Compare commits

...

159 Commits

Author SHA1 Message Date
icarus
00fd20d828 refactor: remove unused import comment in TranslatePage 2025-10-15 01:53:50 +08:00
icarus
d94f73b5ca feat(translate): add target languages preference and refactor language handling
- Introduce TargetLangs type to manage target and alter languages
- Replace local state with preference-based language management
- Simplify language selection logic in ActionTranslate component
- Remove deprecated database storage for language pairs
2025-10-15 01:42:16 +08:00
icarus
7f34d084cc feat(migration): add auto-copy translation mapping for preferences 2025-10-15 01:05:42 +08:00
icarus
821f233728 refactor(translate): store language preferences in cache instead of db
Move source and target language state management from database to cache for better performance and consistency
2025-10-15 00:41:52 +08:00
icarus
0cb60fb2d6 refactor(translate): remove redundant model persistence in handleModelChange 2025-10-15 00:30:39 +08:00
icarus
19d1ce4b2a refactor(translate): migrate scroll sync setting to preferences
Remove local state management for scroll sync and use preference system instead
Clean up unused imports and props in translate components
2025-10-15 00:26:44 +08:00
icarus
c2ee3fff33 refactor(translate): add markdown toggle preference and refactor state management
Move markdown toggle state to preferences system and remove direct database operations
2025-10-15 00:22:43 +08:00
icarus
9b7094ea4a feat(translate): add bidirectional translation configuration in cache
Refactor bidirectional translation logic to use cache for state management
Simplify language pair handling by using language codes directly
2025-10-15 00:16:04 +08:00
icarus
6cda7f891d refactor(translate): centralize language label handling with getLanguageLabel
Move language label generation from individual TranslateLanguage objects to a centralized getLanguageLabel function in useTranslate hook. This improves maintainability by removing duplicate label logic and makes it easier to update language labels globally.

- Remove label() method from TranslateLanguage type and all language objects
- Add getLanguageLabel function in useTranslate that handles label generation
- Update all components to use getLanguageLabel instead of label()
- Add labelMap for common language codes to avoid unnecessary lookups
2025-10-15 00:15:48 +08:00
icarus
dbfece3590 refactor(translate): move auto detection method to preferences
Move auto detection method configuration from local state to preference store
Remove unused auto detection types from renderer types
Add zod schema for auto detection method validation
2025-10-14 22:03:38 +08:00
icarus
9a67ac9018 refactor(translate): remove deprecated redux actions and types
The translate slice actions and types have been migrated elsewhere, so they are removed from this file. The file is marked as deprecated.
2025-10-14 21:51:08 +08:00
icarus
2bd5f39740 refactor(translate): migrate auto copy preference setting to usePreference
Move auto copy setting from redux store to preference system for better consistency
2025-10-14 21:47:31 +08:00
icarus
9ebe4801f4 feat(translate): migrate translate state to cache system
- Replace Redux state management with cache system for translate functionality
- Add new CacheTranslating type to track translation state
- Update TranslatePage to use cache hooks for input, output and state
- Simplify translate function and improve error handling
2025-10-14 21:42:48 +08:00
MyPrototypeWhat
c258035f6a chore: enhance type checking and update UI package configuration
- Added a new typecheck command for the UI package in package.json to ensure type safety.
- Updated tsconfig.web.json to include UI paths for better module resolution.
- Modified the type-check command in the UI package to specify the tsconfig.json file.
- Adjusted the include paths in the UI tsconfig.json to focus on specific component directories.
2025-10-14 14:43:49 +08:00
MyPrototypeWhat
569572bfdc style: standardize import syntax in globals.css
- Updated import statements in globals.css to use single quotes for consistency across the codebase.
2025-10-14 14:20:21 +08:00
MyPrototypeWhat
b821ac5390 fix: update import path for RequireSome type in Toast component
- Changed the import path for RequireSome type from '@types' to '@/types' to align with the project's directory structure.
2025-10-14 14:12:55 +08:00
MyPrototypeWhat
534c2ce485 feat: update UI components and styles with Radix and Tailwind integration
- Added new UI components including Button, Command, Dialog, Popover, and Dropzone using Radix UI.
- Introduced global styles with Tailwind CSS for consistent theming and design.
- Updated existing components to utilize new utility functions for class name management.
- Enhanced Tooltip component with inline-block display for better layout.
- Updated package dependencies in package.json and yarn.lock to include new Radix and Tailwind packages.
2025-10-14 14:12:48 +08:00
Phantom
bab1a5445c ci: allow v2 branch to run PR CI workflow (#10698) 2025-10-13 23:31:46 +08:00
fullex
742f901052 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-10-13 23:18:32 +08:00
Pleasure1234
cb12bb5137 fix: v2 merge error (#10658)
* fix: v2 merge error

* fix: review improve

* fix: ci error

* fix: review

* Update index.tsx

* Update index.tsx
2025-10-13 09:24:32 +08:00
fullex
06b6f2b9d8 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-10-11 09:56:42 +08:00
fullex
2c102ed3b4 refactor: update imports to use 'type' for type-only imports across multiple files
- Changed imports to use 'type' for type-only imports in various files, improving clarity and potentially optimizing the build process.
- Adjusted imports in files related to agents, models, and types to ensure consistency in type usage.
2025-10-09 12:45:17 +08:00
fullex
767e22c58d Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-10-09 12:10:37 +08:00
fullex
dee397f6ac Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-10-08 19:10:15 +08:00
Pleasure1234
a00aba23bd refactor: migrate all antd Tooltip components to HeroUI Tooltip (#10295)
* refactor: migrate tooltip components to @cherrystudio/ui

- Replace all antd Tooltip + InfoCircleOutlined patterns with InfoTooltip component
- Replace all antd Tooltip + QuestionCircleOutlined patterns with HelpTooltip component
- Migrate all WarnTooltip imports to @cherrystudio/ui
- Add onClick support to InfoTooltip and HelpTooltip components
- Remove local tooltip components from renderer
- Update eslint config to restrict antd Tooltip imports
- Clean up unused imports and styled components

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: replace tooltip

* fix: yarn format

* fix: type check

* Update QuickModelPopup.tsx

* fix: yarn test

* fix: ci error

* Update TabContainer.tsx

* fix: ci error

* fix: ci error

* fix: issue

* fix: ci

* fix: again

* refactor(ui): replace Tooltip title prop with content for consistency

* refactor(Tooltip): improve Tooltip component by extending props and simplifying implementation

- Extend TooltipProps from HeroUITooltipProps instead of redefining
- Remove redundant props and use spread operator for classNames
- Export TooltipProps type for better type support

* refactor(HelpTooltip): rename title prop to content and simplify component

Update HelpTooltip component to use TooltipProps interface and rename title prop to content for consistency
Update all instances where HelpTooltip is used to reflect the prop name change

* refactor(IconTooltips): consolidate tooltip components into unified module

Move HelpTooltip, InfoTooltip, and WarnTooltip into a single IconTooltips directory with shared types
Update exports in components index to use new module structure

* refactor(tooltip): update InfoTooltip prop from title to content and simplify component

Consolidate tooltip props interface and update all instances to use content prop instead of title for consistency. Remove redundant interface definitions and simplify InfoTooltip component implementation.

* refactor(ui): rename WarnTooltip prop from title to content for consistency

Update all instances of WarnTooltip component to use content prop instead of title for better consistency with Tooltip component interface. Also simplify the component props by extending IconTooltipProps type.

* fix(tooltip): update tooltip usage

- Replace deprecated props like `mouseEnterDelay` and `mouseLeaveDelay` with `delay` and `closeDelay`
- Rename `arrow` prop to `showArrow` for better semantics
- Update styling props to use `classNames` instead of inline styles
- Remove unnecessary props like `fresh` and `destroyOnHidden`

* refactor(components): remove redundant placement="top" from Tooltip components

The placement="top" prop was removed from all Tooltip components since it's the default value and redundant. This change improves code cleanliness without affecting functionality.

* fix(HeaderNavbar): add tooltip placement for sidebar toggle buttons

* fix(ui): add delay to tooltip components for better user experience

* refactor(tooltip): adjust tooltip behavior and styling across components

- Remove default delay values from base Tooltip component
- Add delay and closeDelay props to specific tooltip instances
- Fix tooltip compatibility issue with Antd Dropdown
- Adjust tooltip placement and styling in various components

* fix(ui): set closeDelay to 0 for Tooltip components to improve responsiveness

Prevent tooltip delay from causing poor user experience by making them close immediately when mouse leaves the element

* refactor(ui): remove redundant tooltip placement prop

The 'placement="top"' prop was removed from Tooltip components as it's the default value and doesn't need to be explicitly set.

* fix(ui): adjust tooltip delays for better user experience

- Set consistent default delay of 1000ms for window controls
- Increase delay for sidebar toggle tooltips to 2000ms
- Adjust various message action tooltip delays between 600-1200ms

* fix(SelectModelPopup): add delay props to provider settings tooltip

Add delay and closeDelay props to Tooltip component to improve user experience by preventing accidental triggers

* style(HelpTooltip): add cursor help style to improve UX

* fix(components): add tooltip delay and placement props for better UX

Add delay prop to CustomTag and ModelIdWithTags tooltips to prevent flickering
Set placement prop for LocalBackupManager tooltip to top-start
Add closeDelay prop to HelpTooltip in SaveToKnowledgePopup for immediate closing

* refactor(ModelSelectButton): simplify tooltip props by using TooltipProps type

Replace individual tooltip placement props with TooltipProps type from ui library for better maintainability

* fix(ui): remove tooltip close delay for better user experience

* docs(tooltip): add jsdoc comments explaining tooltip wrapper behavior

* refactor(Tooltip): clarify showArrow prop

* fix(Inputbar): set closeDelay to 0 for pause tooltip to improve UX

Prevent tooltip from staying visible after interaction by removing the close delay

* style(InputbarTools): improve tooltip consistency and css formatting

- Add closeDelay to new topic tooltip for consistency
- Remove redundant line breaks in tooltip props
- Format css transition properties for better readability

* chore: add tailwindCSS class attributes to vscode settings

* fix(tooltips): improve tooltip behavior and styling across components

- Add closeDelay=0 to most tooltips for instant closing
- Add custom styling to CitationTooltip and ChatFlowHistory tooltips
- Adjust delay times for navigation tooltips
- Remove conflicting Tooltip wrappers around Popconfirm actions

* refactor(ui): adjust tooltip delays and placements across components

- Remove redundant isOpen prop from CustomNode tooltip
- Standardize tooltip delays and placements in MessageGroupMenuBar, MessageTokens, ChatNavbar
- Simplify tooltip wrapper structure in HeaderNavbar
- Add consistent tooltip delays in MessageGroupModelList
- Set tooltip placements in MinimalToolbar

* refactor(Tooltip): enhance tooltip structure and props

- Add className prop to Tooltip component for better customization
- Wrap children in a div with relative positioning to improve layout

* refactor(Tooltip): enhance props structure for improved customization

- Update Tooltip component to allow optional classNames with a placeholder property
- Modify child wrapper to utilize classNames for better styling control

* refactor(IconTooltips): consolidate icon props into single iconProps object

Replace individual icon styling props (iconColor, iconSize, iconStyle) with a unified iconProps object using LucideProps type. This simplifies the component API and improves maintainability by using a standardized props structure across all icon tooltip components.

* feat(JoplinSettings): add help button to open Joplin documentation

Add a help button in Joplin settings that opens the official Joplin documentation in a minapp popup when clicked. This provides users with quick access to Joplin's help resources.

* feat(NotionSettings): add help link click handler for notion title

Add click handler to open help documentation when clicking on Notion title in settings

* feat(S3Settings): add help link to S3 settings title

Add click handler to open documentation for S3 settings when title is clicked

* feat(settings): add help button for siyuan integration

Add click handler to open help documentation for siyuan integration settings

* feat(yuque-settings): add help button to open yuque token guide

Add a help button in Yuque settings that opens a minapp popup with Yuque's token guide. This helps users easily access documentation for generating API tokens.

* fix(ui): adjust tooltip delay settings for better user experience

Set closeDelay to 0 for reset button tooltip to prevent lingering
Add delay of 500ms for api key list tooltip to avoid accidental triggers

* fix(ModelList): set closeDelay to 0 for all Tooltip components

Prevent tooltips from staying open longer than necessary by immediately closing them on mouse leave

* fix(ui): improve tooltip placement and delay settings

adjust tooltip placement and delay for better user experience

* refactor(tests): update tooltip mock implementation and snapshots

- Consolidate tooltip mock to handle both title and content props
- Remove deprecated placement attributes from snapshots
- Clean up test tooltip content assertions

* refactor: remove unnecessary whitespace and simplify tooltip components

clean up code by removing redundant whitespace and simplifying tooltip component usage across multiple files

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: icarus <eurfelux@gmail.com>
Co-authored-by: MyPrototypeWhat <daoquqiexing@gmail.com>
2025-10-05 18:33:21 +08:00
one
de5fb03efb feat(CodeEditor): enable readOnly for CodeEditor (v2) (#10517)
* feat(CodeEditor): enable readOnly for CodeEditor (v2)

* docs: update prop comments
2025-10-05 18:32:31 +08:00
MyPrototypeWhat
a6e58776d2 feat(tailwind): add source for UI package to Tailwind CSS configuration
- Included a new source path for the UI package in the Tailwind CSS configuration to enhance styling capabilities.
- This addition allows for better integration of UI components with Tailwind's utility classes, improving overall design consistency.
2025-09-30 15:12:33 +08:00
MyPrototypeWhat
bebe745e69 refactor(ProviderAvatar): update props for clarity and consistency
- Changed the `name` prop to directly use `providerName` for better readability.
- Updated the `getInitials` prop to use `getFirstCharacter` for improved clarity in the component's functionality.

These changes enhance the maintainability and understanding of the ProviderAvatar component.
2025-09-30 15:07:27 +08:00
MyPrototypeWhat
ec8c24a1c2 refactor: update Avatar components for improved styling and functionality
- Refactored ProviderAvatar to use the name prop for better clarity.
- Updated ModelAvatar to apply consistent styling using Tailwind CSS for width and height.
- Adjusted useOcrProvider hook to standardize Avatar component usage with dynamic sizing.

These changes enhance the overall consistency and maintainability of the Avatar components across the application.
2025-09-30 15:03:58 +08:00
MyPrototypeWhat
db4fcac768 feat: enhance Selector component with SearchableSelector and update exports
- Introduced a new SearchableSelector component for improved item selection with search functionality.
- Updated the Selector component to streamline item selection and added type exports for better type safety.
- Refactored the preferenceSchemas to use the new MathEngine type for better clarity.
- Added comprehensive README documentation for the Selector component detailing usage and features.
- Updated various components and stories to utilize the new Selector and SearchableSelector components.
2025-09-30 14:59:33 +08:00
MyPrototypeWhat
6c71b92d1d refactor: remove ProviderAvatar component and related files
- Deleted the ProviderAvatar component and its associated utility functions and stories to streamline the codebase.
- Updated index.ts to remove the export of ProviderAvatar, ensuring a cleaner component structure.
2025-09-29 18:58:46 +08:00
MyPrototypeWhat
d470fd8b88 refactor: remove unused ProviderLogo styled component from multiple pages
- Deleted the ProviderLogo styled component from CodeToolsPage, AihubmixPage, and PreprocessProviderSettings to streamline the codebase and eliminate redundancy.
2025-09-29 17:48:01 +08:00
MyPrototypeWhat
99962b740c feat: add EmojiAvatar component and update component exports
- Introduced a new EmojiAvatar component for enhanced avatar functionality.
- Updated index.ts to export the new EmojiAvatar alongside existing components.
- Removed the old display/EmojiAvatar component to streamline the codebase.
- Adjusted various components to utilize the new Avatar structure and styling.
2025-09-29 17:47:17 +08:00
MyPrototypeWhat
ef4bede062 feat: introduce DescriptionSwitch component and update component exports
- Added a new DescriptionSwitch component to enhance the Switch functionality with a description feature.
- Updated the exports in index.ts to include the new DescriptionSwitch alongside existing components.
- Refactored the SettingsTab to utilize DescriptionSwitch for improved UI consistency.
- Removed the InfoPopover component as part of the cleanup process.
2025-09-29 12:47:36 +08:00
Phantom
e6e1fb0404 refactor(button): migrate button from antd to heroui (#10292)
* fix(eslint): add Button to restricted antd imports

* feat(ui): add Button component with Storybook stories

Implement a reusable Button component wrapping HeroUIButton with proper TypeScript props.
Add comprehensive Storybook stories demonstrating all button variants, colors, sizes and states.

* refactor(components): update ActionIconButton implementation and usage

Replace onClick with onPress prop and move icon into icon prop
Update component to use @cherrystudio/ui Button instead of antd
Simplify props interface and add displayName

* refactor(ui): migrate antd buttons to @cherrystudio/ui components

update button components across multiple files to use @cherrystudio/ui's Button component
replace antd button props with equivalent @cherrystudio/ui props

* refactor(InputEmbeddingDimension): replace antd Button with custom Button component

Update the Button component to use the custom @cherrystudio/ui Button with updated props for better consistency and maintainability

* refactor(components): migrate buttons from antd to @cherrystudio/ui

Update button components in LocalBackupModals and LocalBackupManager to use @cherrystudio/ui instead of antd
Add flex styling to modal footers for better button alignment

* refactor(ProviderSetting): migrate Button components from antd to @cherrystudio/ui

Update Button components to use @cherrystudio/ui implementation with new props like variant, color, and startContent
Replace onClick handlers with onPress and adjust disabled states

* refactor(ui): migrate antd buttons to cherrystudio ui buttons

Update button components across multiple files to use @cherrystudio/ui Button instead of antd Button
Standardize button props and behavior while maintaining existing functionality

* refactor(NutstorePathSelector): update button props to use cherrystudio ui

Replace antd Button with cherrystudio ui Button component and update props

* refactor(S3BackupManager): migrate antd buttons to @cherrystudio/ui

Update button components from antd to @cherrystudio/ui library
Change button props to match new library's API (variant, color, onPress, etc)
Adjust table props for consistency with new component library

* refactor(TranslateButton): replace styled Button with cherrystudio Button component

The custom styled Button was replaced with the cherrystudio Button component to maintain consistency across the UI and reduce custom styling code. The functionality remains the same but uses the library's built-in props for styling.

* refactor(WebdavBackupManager): replace antd buttons with cherrystudio ui buttons

Update button components to use cherrystudio ui library for consistency

* refactor(ui): migrate buttons from antd to @cherrystudio/ui

Update button components across multiple editor components to use @cherrystudio/ui's Button component instead of antd's. This includes updating props like size, variant, and event handlers to match the new component's API.

* refactor(components): migrate buttons from antd to @cherrystudio/ui

Update button components in HtmlArtifactsCard and HtmlArtifactsPopup to use @cherrystudio/ui's Button component instead of antd's Button. This includes updating props like icon to startContent, onClick to onPress, and type to variant/color.

* refactor(ui): migrate button components from antd to hero ui

- replace antd Button with hero ui Button component
- update button props interface to extend hero ui props
- adjust button props in OAuthButton and MinappPopupContainer

* refactor(MultiSelectionPopup): migrate button components to @cherrystudio/ui

Update button props to match new component library requirements

* refactor(ApiKeyItem): migrate antd buttons to cherrystudio ui components

Update button components in ApiKeyItem to use cherrystudio ui library instead of antd

* refactor(ApiKeyListPopup): update button props to use new UI library syntax

Update button components to use the new syntax from @cherrystudio/ui library, replacing antd Button props with the new variant, color, and isDisabled props. Also adjust icon placement and button types to match the new library's API.

* refactor(SelectModelButton): replace antd Button with custom Button component

Simplify button implementation by using custom Button component from ui library instead of antd. Remove unused styled component and event handling.

* refactor(Preview): migrate ImageToolButton to use @cherrystudio/ui

Update ImageToolButton component to use Button from @cherrystudio/ui instead of antd
Change onClick prop to onPress to match new Button component API
Update related usage in ImageToolbar component

* refactor(ui): migrate buttons from antd to cherrystudio ui components

Update button components across multiple files to use cherrystudio's Button component instead of antd's. This includes updating props like onClick to onPress and adjusting button styling props to match the new component's API.

* refactor(ui): migrate antd buttons to @cherrystudio/ui buttons

Update button components from antd to @cherrystudio/ui library
Adjust button props to match new component API

* refactor(components): update prop names and component usage

- Rename onClick to onPress in ImageToolButton test props
- Update isLoading to loading in S3BackupManager table props
- Change ghost to variant in ProviderSetting button props
- Replace antd Button with cherrystudio Button in PreferenceBasicTests

* refactor(ImageToolButton): migrate from antd to @cherrystudio/ui

* refactor(FilesPage): migrate Button components from antd to @cherrystudio/ui

* refactor(SearchMessage): migrate Button components from antd to @cherrystudio/ui

* refactor(TopicMessages): migrate Button components from antd to @cherrystudio/ui

* refactor(TopicsHistory): migrate Button components from antd to @cherrystudio/ui

* refactor(ChatNavigation): migrate Button components from antd to @cherrystudio/ui

* refactor(CitationsList): migrate Button components from antd to @cherrystudio/ui

* refactor(MessageGroupMenuBar): migrate Button components from antd to @cherrystudio/ui

* refactor: reorganize button imports and adjust class order

Consolidate Button imports from @cherrystudio/ui to be grouped with other imports
Standardize className order for consistency across components

* refactor(SelectModelPopup): replace HStack with Flex component for layout

* feat: migrate PrivacyPopup from antd Button to @cherrystudio/ui Button

- Replace antd Button import with @cherrystudio/ui Button
- Update onClick to onPress event handler
- Update type="primary" to variant="solid" color="primary"
- Maintain existing functionality while following Hero UI API

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate NewTopicButton from antd Button to @cherrystudio/ui Button

- Replace antd Button import with @cherrystudio/ui Button
- Update size="small" to size="sm"
- Update icon prop to startContent for Hero UI API
- Update onClick to onPress event handler
- Maintain existing styled-components with StyledButton wrapper

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate MessageMcpTool Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update two Button components with Hero UI API:
  - size="small" to size="sm"
  - onClick to onPress
  - variant="filled" to variant="solid"
  - Move icons to startContent prop
- Maintain Dropdown.Button as antd component (not migrated)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate SettingsTab Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update settings icon button with Hero UI API:
  - type="text" to variant="light"
  - size="small" to size="sm"
  - icon prop to isIconOnly with child content
  - onClick to onPress event handler

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate AssistantTagsPopup Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update delete tag button with Hero UI API:
  - type="text" to variant="light"
  - danger prop to color="danger"
  - icon prop to isIconOnly with child content
  - onClick to onPress event handler

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate UpdateAppButton from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update styled Button component with Hero UI API:
  - onClick to onPress event handler
  - icon prop to startContent
  - color="orange" to color="warning" (closest equivalent)
  - variant="outlined" to variant="bordered"
  - size="small" to size="sm"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(NewTopicButton): replace styled-components with cn utility

Simplify component styling by removing styled-components in favor of the cn utility

* refactor: organize imports and remove unused event handlers

remove duplicate Button imports and clean up stopPropagation handlers

* feat: migrate KnowledgeContent Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update settings icon Button with Hero UI API:
  - type="text" to variant="light"
  - size="small" to size="sm"
  - icon prop to isIconOnly with child content
  - onClick to onPress event handler
- Update ResponsiveButton styled component selector:
  - .ant-btn-icon + span to [data-slot="icon"] + [data-slot="label"]

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate KnowledgeDirectories Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update three Button components with Hero UI API:
  - Refresh button: type="text" to variant="light", icon to isIconOnly, onClick to onPress
  - Delete button: type="text" danger to variant="light" color="danger", icon to isIconOnly, onClick to onPress
  - Add directory button: type="primary" to variant="solid" color="primary", icon to startContent, disabled to isDisabled
- Remove stopPropagation from add directory button as not needed with onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate KnowledgeFiles Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update three Button components with Hero UI API:
  - Add file button: type="primary" to variant="solid" color="primary", icon to startContent, disabled to isDisabled
  - Refresh button: type="text" to variant="light", icon to isIconOnly, onClick to onPress
  - Delete button: type="text" danger to variant="light" color="danger", icon to isIconOnly, onClick to onPress
- Remove stopPropagation from add file button as not needed with onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate KnowledgeNotes Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update three Button components with Hero UI API:
  - Add note button: type="primary" to variant="solid" color="primary", icon to startContent, disabled to isDisabled
  - Edit button: type="text" to variant="light", icon to isIconOnly, onClick to onPress
  - Delete button: type="text" danger to variant="light" color="danger", icon to isIconOnly, onClick to onPress
- Remove stopPropagation from add note button as not needed with onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate KnowledgeSitemaps Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update three Button components with Hero UI API:
  - Add sitemap button: type="primary" to variant="solid" color="primary", icon to startContent, disabled to isDisabled
  - Refresh button: type="text" to variant="light", icon to isIconOnly, onClick to onPress
  - Delete button: type="text" danger to variant="light" color="danger", icon to isIconOnly, onClick to onPress
- Remove stopPropagation from add sitemap button as not needed with onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate KnowledgeUrls Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update three Button components with Hero UI API:
  - Add URL button: type="primary" to variant="solid" color="primary", icon to startContent, disabled to isDisabled
  - Refresh button: type="text" to variant="light", icon to isIconOnly, onClick to onPress
  - Delete button: type="text" danger to variant="light" color="danger", icon to isIconOnly, onClick to onPress
- Remove stopPropagation from add URL button as not needed with onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate KnowledgeVideos Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update three Button components with Hero UI API:
  - Add video button: type="primary" to variant="solid" color="primary", icon to startContent, disabled to isDisabled
  - Refresh button: type="text" to variant="light", icon to isIconOnly, onClick to onPress
  - Delete button: type="text" danger to variant="light" color="danger", icon to isIconOnly, onClick to onPress
- Remove stopPropagation from add video button as not needed with onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate MinAppsPage Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update two settings Button components with Hero UI API:
  - type="text" to variant="light"
  - icon prop to isIconOnly with child content
  - onClick to onPress event handler
  - Maintain className="nodrag" for draggable interface

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate MiniAppSettings Buttons from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update two Button components with Hero UI API:
  - Swap button: onClick to onPress event handler
  - Reset button: onClick to onPress event handler
- Buttons use default Hero UI styling without additional props

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate NewAppButton from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update two Button components with Hero UI API:
  - Upload button: icon to startContent
  - Save button: type="primary" htmlType="submit" to variant="solid" color="primary" type="submit"
- Maintain form submission functionality with type="submit"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: standardize button imports from @cherrystudio/ui

* refactor(KnowledgeContent): replace icon prop with startContent in Button

Improve consistency with component library by using startContent prop instead of children for icons

* refactor(KnowledgeVideos): update button components to use startContent prop

Use startContent prop for icons in buttons to improve consistency with the design system

* refactor(MinAppsPage): improve button component structure by using startContent prop

* feat: migrate AihubmixPage Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - size="small" to size="sm"
  - icon to startContent
  - onClick to onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate DmxapiPage Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - size="small" to size="sm"
  - icon to startContent
  - onClick to onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate NewApiPage Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - size="small" to size="sm"
  - icon to startContent
  - onClick to onPress
  - type="primary" to variant="solid" color="primary"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate SiliconPage Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - size="small" to size="sm"
  - icon to startContent
  - onClick to onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate TokenFluxPage Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - size="small" to size="sm"
  - icon to startContent
  - onClick to onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate ZhipuPage Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - type="text" to variant="light"
  - icon to startContent
  - onClick to onPress
  - disabled to isDisabled

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate Artboard Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - onClick to onPress for NavigationButton and CancelButton
  - type="link" to variant="light"
- Maintain styled-components usage for NavigationButton and CancelButton

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate DynamicFormRender Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - icon to startContent
  - onClick to onPress
  - size="small" to size="sm"
  - danger to color="danger"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: convert Button inline styles to Tailwind CSS

- Replace style={{borderTopLeftRadius: 0, borderBottomLeftRadius: 0, height: '32px'}} with className="rounded-l-none h-8"
- Replace style={{flexShrink: 0, minWidth: 'auto', padding: '0 8px'}} with className="shrink-0 min-w-0 px-2"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate ImageUploader Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - size="small" to size="sm"
  - onClick to onPress

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(Artboard): replace inline styles with tailwind classes

Use tailwind classes for consistent styling of navigation buttons instead of inline styles

* feat: migrate AboutSettings Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - onClick to onPress for all Button components
  - loading to isLoading for CheckUpdateButton
  - disabled to isDisabled for CheckUpdateButton
- Maintain CheckUpdateButton styled component

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate AssistantMemorySettings Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - type="text" to variant="light" + isIconOnly
  - icon to startContent
  - onClick to onPress
  - size="small" to size="sm"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate AssistantModelSettings Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - icon to startContent
  - onClick to onPress
  - variant="filled" to variant="solid"
  - danger + type="primary" to color="danger" variant="solid"
  - Add isIconOnly for icon-only buttons
- Maintain ModelSelectButton styled component

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate AssistantPromptSettings Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - type="primary" to variant="solid" color="primary"
  - icon to startContent
  - onClick to onPress
- Convert inline styles to Tailwind CSS:
  - style={{fontSize: 18, padding: '4px', minWidth: '28px', height: '28px'}} to className="text-lg p-1 min-w-7 h-7"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: consolidate Button imports from @cherrystudio/ui

Move all Button imports from @cherrystudio/ui to be grouped with other imports from the same package for better consistency and maintainability

* feat: migrate AssistantRegularPromptsSettings Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - type="text" to variant="light"
  - icon to startContent
  - onClick to onPress
  - Add isIconOnly for icon-only buttons
  - danger to color="danger"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: migrate DataSettings Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Update Button props with Hero UI API:
  - onClick to onPress for all buttons
  - icon to startContent for backup/restore buttons
  - danger to color="danger" for reset button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(NutstoreSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Update type/danger props to variant/color system
- Convert loading to isLoading prop
- Convert disabled to isDisabled prop
- Update ghost prop to variant="ghost"
- Add isIconOnly for folder icon button
- Migrate startContent pattern for icons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(S3Settings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Convert icon props to startContent pattern
- Convert loading to isLoading prop
- Convert disabled to isDisabled prop

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(SiyuanSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(WebDavSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Convert icon props to startContent pattern
- Convert loading to isLoading prop
- Convert disabled to isDisabled prop

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(YuqueSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(DisplaySettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Convert icon props to startContent pattern
- Convert variant="text" to variant="light"
- Add isIconOnly for icon-only buttons
- Replace inline styles with Tailwind CSS classes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(PreprocessProviderSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Convert type="text" to variant="light"
- Convert size="small" to size="sm"
- Convert icon to startContent pattern
- Add isIconOnly for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(NotionSettings): replace antd Button with cherrystudio Button and update prop

Update the Button import to use cherrystudio's component instead of antd's

* refactor(settings): migrate Button props to use startContent and isDisabled

Update Button components in LocalBackupSettings to use startContent instead of icon and isDisabled instead of disabled for consistency with the updated UI library

* refactor(JoplinSettings): replace Button import and update onPress prop

Use Button component from @cherrystudio/ui instead of antd
Update onClick to onPress for consistency with component API

* refactor(MarkdownExportSettings): replace antd Button with cherrystudio Button in markdown export

Update the Button component import and props to use the cherrystudio UI library version instead of antd for consistency

* refactor: organize imports in settings components

Move Button import from cherrystudio/ui to be grouped with other imports from the same package for better consistency and readability

* refactor(AddMcpServerModal): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert icon prop to startContent pattern

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(BuiltinMCPServerList): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Convert type="text" to variant="light"
- Convert size="small" to size="sm"
- Convert icon to startContent pattern
- Convert disabled to isDisabled prop
- Add isIconOnly for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(InstallNpxUv): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Convert type="primary" to variant="solid" color="primary"
- Convert type="link" to variant="light"
- Convert shape="circle" to radius="full"
- Convert size="small" to size="sm"
- Convert loading/disabled to isLoading/isDisabled
- Convert icon to startContent pattern
- Add isIconOnly for icon-only button
- Convert green color to success color

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(McpServerCard): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers (removing e.stopPropagation)
- Convert type="text" to variant="light"
- Convert size="small" to size="sm"
- Convert shape="circle" to radius="full"
- Convert danger to color="danger"
- Convert icon to startContent pattern
- Add isIconOnly for icon-only buttons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(MCPSettings): reorder Button imports for consistency

Move Button imports to be grouped with other UI component imports for better readability and maintainability

* refactor(McpServersList): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Convert type="default" to variant="solid"
- Convert shape="round" to radius="full"
- Convert icon to startContent pattern

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(McpServerCard): remove unused event parameter from click handlers

The event parameter was not being used in handleOpenUrl and onClickDetails handlers, so it was removed to simplify the code.

* refactor(McpServerCard): remove data-no-dnd attribute from Button

* refactor(McpSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Convert danger to color="danger"
- Convert type="text" to variant="light"
- Convert type="primary" to variant="solid" color="primary"
- Convert shape="round" to radius="full"
- Convert loading/disabled to isLoading/isDisabled
- Convert icon to startContent pattern
- Add isIconOnly for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(McpSettingsNavbar): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Convert type="text" to variant="light"
- Convert size="small" to size="sm"
- Convert icon to startContent pattern
- Replace inline styles with Tailwind CSS classes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(NpxSearch): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Convert type="text" to variant="light"
- Convert size="small" to size="sm"
- Convert icon to startContent pattern
- Add isIconOnly for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(SyncServersPopup): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Convert type="default" to variant="solid"
- Convert type="primary" to variant="solid" color="primary"
- Convert loading/disabled to isLoading/isDisabled

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(MCPSettings/index): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert type="default" to variant="solid"
- Convert shape="circle" to radius="full"
- Convert icon to startContent pattern
- Add isIconOnly for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(MemorySettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Convert type="text" to variant="light"
- Convert type="primary" to variant="solid" color="primary"
- Convert size="large" to size="lg"
- Convert size="small" to size="sm"
- Convert loading/disabled to isLoading/isDisabled
- Convert danger to color="danger"
- Convert icon to startContent pattern
- Add isIconOnly for icon-only buttons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(UserSelector): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Convert type="default" to variant="solid"
- Convert icon to startContent pattern
- Add isIconOnly for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(DefaultAssistantSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Convert type="text" to variant="light"
- Convert icon to startContent pattern
- Add isIconOnly for icon-only button
- Replace inline styles with Tailwind CSS classes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(QuickModelPopup): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Change icon prop to startContent
- Update type="text" to variant="light"
- Add isIconOnly prop for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(NotesSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for all buttons
- Change type="default" to variant="solid"
- Change type="primary" to color="primary"
- Update loading to isLoading prop
- Update disabled to isDisabled prop
- Change icon prop to startContent
- Replace inline style with Tailwind CSS class (ml-2)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(AnthropicSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Change type="primary" to color="primary"
- Update loading to isLoading prop

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ModelEditContent): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for all buttons
- Change size="small" to size="sm"
- Update icon prop to startContent for save and reset buttons
- Change iconPosition="end" to endContent for more settings toggle
- Update type="text" to variant="light" and add isIconOnly for reset button
- Change type="primary" to color="primary"
- Replace htmlType="submit" with type="submit"
- Update variant="filled" to variant="solid"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ModelTypeSelector): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Change size="small" to size="sm"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(GithubCopilotSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for all buttons
- Change type="primary" to color="primary"
- Change type="primary" danger to color="danger"
- Update size="small" to size="sm"
- Update loading to isLoading prop
- Update disabled to isDisabled prop
- Change icon prop to startContent for copy button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(AddModelPopup): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Change type="primary" to color="primary"
- Replace htmlType="submit" with type="submit"
- Change size="middle" to size="md"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ModelList): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for all buttons
- Change type="text" to variant="light" and add isIconOnly for icon button
- Change type="primary" to color="primary"
- Change type="default" to variant="solid"
- Update disabled to isDisabled prop
- Change icon prop to startContent for all buttons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ModelListGroup): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Change type="text" to variant="light"
- Update disabled to isDisabled prop
- Change icon prop to startContent
- Remove e.stopPropagation() as no longer needed
- Add isIconOnly prop for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ModelListItem): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for both buttons
- Change type="text" to variant="light"
- Update disabled to isDisabled prop
- Change icon prop to startContent for both buttons
- Add isIconOnly prop for icon-only buttons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(NewApiAddModelPopup): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Change type="primary" to color="primary"
- Replace htmlType="submit" with type="submit"
- Change size="middle" to size="md"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(NewApiBatchAddModelPopup): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Change type="primary" to color="primary"
- Replace htmlType="submit" with type="submit"
- Change size="middle" to size="md"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ProviderList): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Update disabled to isDisabled prop
- Change icon prop to startContent
- Keep existing style attributes for custom styling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ProviderOAuth): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for both buttons
- Change shape="round" to radius="full"
- Change icon prop to startContent for both buttons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(UrlSchemaInfoPopup): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Change type="link" to variant="light"
- Change size="small" to size="sm"
- Change icon prop to startContent
- Add isIconOnly prop for icon-only button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(QuickAssistantSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for both styled buttons
- Change type="primary" to color="primary"
- Change type="default" to color="default"
- Update styled component to use new Button from @cherrystudio/ui

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(QuickPhraseSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for all buttons
- Change type="text" to variant="light"
- Change icon prop to startContent for all buttons
- Change danger prop to color="danger"
- Add isIconOnly prop for all icon-only buttons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(SelectionAssistantSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for both buttons
- Change type="link" to variant="light"
- Change icon prop to startContent
- Keep existing style attributes for custom styling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ActionsListItem): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for all buttons
- Change type="link" to variant="light"
- Change size="small" to size="sm"
- Change danger prop to color="danger"
- Add isIconOnly prop for all icon-only buttons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(MacProcessTrustHintModal): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for both buttons
- Change type="link" to variant="light"
- Change type="primary" to color="primary"
- Keep existing style attributes for custom styling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(SelectionActionSearchModal): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler
- Change type="link" to variant="light"
- Change size="small" to size="sm"
- Keep existing style attributes for custom styling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(SelectionFilterListModal): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handler for both modal buttons
- Change type="primary" to color="primary"
- Keep existing key attributes for modal footer

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(SettingsActionsListHeader): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers
- Update icon prop to startContent with Plus icon
- Change disabled to isDisabled
- Add color="primary" for primary button style
- Update styled ResetButton to use variant="light"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ShortcutSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers for all buttons
- Update icon prop to startContent for icon buttons
- Change disabled to isDisabled
- Convert size="small" to size="sm"
- Replace shape="circle" with isIconOnly for circular buttons
- Migrate reset undo button, clear button, and reset all button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(ApiServerSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers for all buttons
- Update icon prop to startContent for documentation and copy buttons
- Change type="primary" to color="primary"
- Convert type="link" to variant="light" for regenerate button
- Change disabled to isDisabled for input button and regenerate button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(CustomLanguageModal): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers for modal footer buttons
- Change type="primary" to color="primary" for save button
- Convert icon prop to startContent with isIconOnly for emoji button
- Migrate cancel, save, and emoji picker buttons to Hero UI API

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(CustomLanguageSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers for all buttons
- Update icon prop to startContent for edit, delete, and add buttons
- Change type="primary" to color="primary" for add button
- Convert danger prop to color="danger" for delete button
- Migrate table action buttons and primary add button to Hero UI API

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(AddSubscribePopup): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert type="primary" to color="primary" for submit button
- Change htmlType="submit" to type="submit" following Hero UI API
- Migrate form submit button from antd to Hero UI

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(BlacklistSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers for all buttons
- Change type="primary" to color="primary" for subscribe buttons
- Convert ghost prop to variant="ghost"
- Change disabled to isDisabled for all button states
- Migrate save, add subscribe, update subscribe, and delete buttons

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(WebSearchProviderSetting): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers for API key list and check buttons
- Change type="text" to variant="light" for API key list button
- Convert icon prop to startContent with isIconOnly for list button
- Update size="small" to size="sm"
- Change ghost prop to variant="ghost" and type to color for check button
- Convert disabled to isDisabled for API checking state

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(TranslateSettings): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress for more settings button
- Simple migration for modal footer button

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(MigrateApp): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers for all migration buttons
- Change type="primary" to color="primary" for primary buttons
- Convert disabled to isDisabled for migration in progress button
- Change size="small" to size="sm" for debug button
- Convert type="dashed" to variant="bordered" for styled buttons
- Migrate all buttons in migration workflow stages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(SelectionActionApp): migrate Button from antd to @cherrystudio/ui

- Replace antd Button import with @cherrystudio/ui Button
- Convert onClick to onPress handlers for all window control buttons
- Change type="text" to variant="light" for all title bar buttons
- Update icon prop to startContent for pin, opacity, minimize, and close buttons
- Add isIconOnly prop for all icon-only buttons in the title bar
- Migrate styled WinButton component to use Hero UI Button as base

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* style(ActionIconButton): remove fixed dimensions and add size prop

Simplify button styling by removing fixed height/width and using size="sm" prop instead

* refactor(AssistantPromptSettings): migrate from antd Popover to hero-ui components

Replace antd Popover with hero-ui Popover and Tooltip components for better consistency
Rename EmojiButtonWrapper to EmojiDeleteButtonWrapper for clarity

* style(AssistantModelSettings): add size prop to delete button in model settings

* style(settings): standardize button sizes and replace Space.Compact with Flex

Consistently apply 'sm' size to buttons across settings components and replace deprecated Space.Compact with Flex component for better layout consistency

* refactor(ApiServerSettings): replace custom buttons with standard Button component

remove custom styled InputButton and RegenerateButton components in favor of using the standard Button component with appropriate props

* style(ProviderSetting): make settings button icon-only for consistency

* style(ui): update icon styling and button props

remove global lucide icon color override
update button components to use consistent props

* style(ProviderList): adjust button size to match design

* feat(theme): add foreground color calculation for primary theme

Calculate and set foreground color based on primary theme color to ensure proper contrast

* style(KnowledgeFiles): make button size consistent with other buttons

* test: update test snapshots for button components

Update test snapshots to reflect changes in button styling and accessibility attributes. The changes include updated class names, ripple effects, and focus states.

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Co-authored-by: MyPrototypeWhat <daoquqiexing@gmail.com>
2025-09-29 12:04:03 +08:00
fullex
e6696def10 chore: update TypeScript configuration and refactor AppUpdater tests
- Added tests mock path to tsconfig.node.json for improved test coverage.
- Refactored AppUpdater to use preferenceService for language retrieval instead of configManager.
- Updated AppUpdater tests to mock preferenceService and ensure correct language handling in release notes.
- Changed import statements to use type imports for better clarity in MessageMcpTool component.
2025-09-29 10:11:40 +08:00
fullex
e5a3363021 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-29 10:01:04 +08:00
fullex
f6ff436294 refactor: replace keyv with cacheService 2025-09-25 11:38:05 +08:00
fullex
8a9b633af2 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-24 22:30:56 +08:00
Phantom
0a37146ba8 refactor(SelectModelPopup): replace HStack with Flex component (#10337)
refactor(SelectModelPopup): replace HStack with Flex component for layout
2025-09-24 20:10:12 +08:00
fullex
ac3dfcbfbe Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-24 13:13:58 +08:00
Phantom
5ac09d5311 refactor: migrate to toast from antd message (#10233)
* style(eslint): reorganize eslint config comments and rules

Move comments to consistent positions above their corresponding rules
Update antd import restriction to include 'message' component

* fix(eslint): reorganize eslint config to enable custom rules

* fix(eslint): update antd import restriction to include message

Prevent direct imports of both Flex and message from antd, enforcing usage of custom components

* feat(migration): add toast utilities to migrate and test apps

Initialize toast utilities on window object for both migration and test applications to enable toast notifications

* build(ui): add path aliases for types and utils modules

* refactor(toast): move toast utilities to ui package for better reusability

Centralize toast utilities in the @cherrystudio/ui package to improve code organization and reuse across multiple components. This change includes:
- Moving toast implementation to ui package
- Updating all imports to use the new location
- Adding proper type definitions

* refactor: replace antd message with window.toast for consistency

Replace all instances of antd's message component with window.toast throughout the application to maintain consistent notification behavior. Also add an ignore rule for dataRefactorTest files in eslint config.
2025-09-20 16:58:41 +08:00
MyPrototypeWhat
d4fd8ffdcc refactor(SettingsTab): update Selector component usage for consistency
- Simplified Selector component usage in SettingsTab by removing deprecated props and updating to the new API.
- Added size and label props to enhance accessibility and user experience.
- Ensured consistent handling of selected keys and selection change events across multiple instances of Selector.
2025-09-19 12:10:33 +08:00
fullex
84274d9d85 Merge branches 'v2' and 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-19 11:19:29 +08:00
Phantom
a72feebead refactor: migrate Switch from antd to heroui (#10237)
* refactor(eslint): reorganize eslint config for better maintainability

Move ignores section and oxlint configs to be grouped with other configurations

* fix(eslint): update antd import restriction to include Switch

Add Switch to restricted imports from antd to enforce using custom components

* feat(ui): add Switch component wrapper and update imports

Add a wrapper for the Switch component from @heroui/react and export it through @cherrystudio/ui. Update eslint rules to prevent direct imports from @heroui/react and update imports in TranslateSettings to use the new wrapper

* refactor(ui): replace antd Switch with custom Switch component

Migrate all instances of antd Switch component to the custom Switch component from @cherrystudio/ui. This includes updating props from `checked` to `isSelected` and `onChange` to `onValueChange` to match the new component's API. Also updates size prop from `small` to `sm` where applicable.

The change ensures consistency across the UI and reduces dependency on antd components. All affected files have been updated to use the new Switch component with proper prop mappings.

* feat(ui): enhance Switch component with loading state

Add loading state support to Switch component by showing a spinner when isLoading is true and disabling interaction during loading. Update all Switch component usages to use the new isLoading prop instead of loading.

* fix(Switch): prevent thumbIcon override when isLoading is true

Implement type constraints to disallow thumbIcon when isLoading is true
Add ref forwarding support and export enhanced props type

* fix(settings): update Switch component props to use consistent naming

Change deprecated 'defaultChecked' and 'disabled' props to 'defaultSelected' and 'isDisabled' respectively to match component library updates

* refactor(Switch): simplify type definition by removing redundant ref prop

* refactor(Switch): simplify props type definition for loading state

Remove complex union type in favor of simpler interface extending SwitchProps

* docs(ui): add jsdoc for CustomizedSwitch component

Add documentation for the CustomizedSwitch component to clarify its purpose and the isLoading prop usage

* fix(eslint): comment out heroui import restriction rule

Temporarily disable the heroui import restriction to allow direct imports while wrapped components are being updated

* style: fix formatting and spacing in settings components
2025-09-18 19:16:53 +08:00
MyPrototypeWhat
e930d3de43 refactor: update imports to use type-only imports for WebSearchPluginConfig and CherryWebSearchConfig
- Changed imports of WebSearchPluginConfig and CherryWebSearchConfig to type-only imports for better clarity and to optimize TypeScript compilation.
2025-09-17 18:40:38 +08:00
MyPrototypeWhat
ecc9923050 Merge remote-tracking branch 'origin/main' into v2 2025-09-17 18:37:22 +08:00
MyPrototypeWhat
e469016775 style(Selector.stories): simplify Selector component stories by condensing JSX structure
- Refactored the Selector component stories to use a more concise JSX format, improving readability.
- Ensured consistent formatting across size variations for better maintainability.
2025-09-17 18:33:14 +08:00
MyPrototypeWhat
15569387c7 feat(ui): implement new Selector component with enhanced functionality
- Replaced the existing Selector component with a new implementation using HeroUI's Select and SelectItem.
- Updated the props structure to support items and selection change handling.
- Added a new story file for the Selector component, showcasing various use cases including single and multiple selection modes, size variations, and disabled states.
- Improved type definitions for better clarity and usability.
2025-09-17 18:31:11 +08:00
Phantom
4f746842a5 refactor: migrate Flex from antd to custom Flex component (#10083)
* refactor(components): rename HStack and VStack to RowFlex and ColFlex for clarity

rename HStack to RowFlex and VStack to ColFlex across all components to better reflect their purpose as flex containers with row and column directions. This improves code readability and maintainability while keeping the same functionality. All references to these components have been updated accordingly.

* refactor(layout): migrate layout components from .ts to .tsx

The layout components have been moved from TypeScript (.ts) to TypeScript with JSX (.tsx) to better support JSX syntax and improve type safety. The functionality remains unchanged.

* refactor(Layout): convert styled Box component to functional component

Improve maintainability by converting styled-component to a functional component with explicit style props. This provides better type safety through CSSProperties interface and makes the component easier to debug.

* refactor(Layout): restructure Box component and convert styled components to functional

- Replace styled-components with functional components for Stack and Center
- Rename style variable to _style in Box component to avoid naming conflict
- Add style prop to Box component to allow external style overrides

* refactor(components): rename HSpaceBetweenStack to SpaceBetweenRowFlex for clarity

* refactor(Layout): pass through props in Stack components

Allow additional props to be passed to Stack and its variants for better flexibility. Convert RowFlex from styled component to regular component for consistency.

* refactor(Layout): convert SpaceBetweenRowFlex from styled to component

Improve maintainability by converting styled component to a regular component that explicitly passes justifyContent prop

* refactor(Layout): convert ColFlex to component and type RowFlex props

Improve type safety by explicitly omitting flexDirection from StackProps and convert ColFlex from styled component to regular component for consistency

* refactor(Layout): convert BaseTypography from styled to component

Improve type safety and maintainability by converting styled component to regular React component with TypeScript interface

* refactor(Layout): remove unused BaseTypography component

* refactor(Layout): remove unused Container component and interface

* refactor(layout): rename Stack to Flex and use CSSProperties types

The Stack component was renamed to Flex to better reflect its purpose and align with common naming conventions. The interface properties were also updated to use CSSProperties types for better type safety and consistency with CSS standards.

* refactor(Layout): move FlexProps interface and comment out unused ButtonProps

Clean up component interfaces by moving FlexProps closer to its usage and commenting out unused ButtonProps interface to reduce clutter

* refactor(layout): standardize flex props from alignItems/justifyContent to align/justify

The changes standardize the flex-related props in the Layout component and across multiple files from using alignItems/justifyContent to the shorter align/justify. This improves consistency and reduces verbosity in the codebase while maintaining the same functionality.

All instances of alignItems have been replaced with align and justifyContent with justify in Flex, RowFlex, ColFlex and related components. The changes are purely syntactic and do not affect the actual layout behavior.

This refactoring makes the code more maintainable by using a consistent naming convention for flex properties throughout the application.

* refactor(Layout): extend BoxProps with React div props

* feat(Layout): add flexWrap prop to Flex component interface

Add flexWrap property to FlexProps interface to support CSS flex-wrap functionality. Also replace antd Flex with custom Flex component in TagFilterSection.

* refactor(components): replace antd Flex with custom Layout components

Consolidate Flex component usage across multiple files by replacing antd's Flex with custom Layout components (Flex, ColFlex, RowFlex) for better maintainability and consistency

* refactor(components):  migrate antd Flex tu custom Flex

* refactor(components): update layout component usage for consistency

replace RowFlex with ColFlex where appropriate and align prop names

* refactor(tests): rename HStack to RowFlex in test components

Update test snapshots and mock components to reflect the component name change from HStack to RowFlex
Remove unused data-vertical attribute from preview container

* refactor(Layout): pass through props and merge styles in Box and Flex components

Improve component flexibility by allowing additional props to pass through and properly merging style objects in both Box and Flex components

* refactor(Layout): make Flex component props optional with undefined defaults

* test: update TagFilterSection snapshot to include wrap style

* perf(Layout): optimize Box component style calculation with useMemo

* docs: fix typo in Layout component comment

* refactor(Layout): update BoxProps to use CSSProperties types

Standardize prop types by using CSSProperties for style-related props to improve type safety and consistency with React's style system

* feat(Layout): add wrap prop to Flex component

* style(TagFilterSection): update snapshot styling to use flex-wrap property

* refactor(Layout): simplify layout components by using Tailwind CSS classes

Remove custom style calculations and props in favor of Tailwind utility classes

* refactor: replace inline styles with Tailwind CSS classes for consistent styling

style: update spacing and alignment utilities across components

* refactor(tests): update test snapshots to use tailwind classes

Replace inline styles with tailwind classes in test snapshots and update test assertions to match. This improves consistency with the codebase's styling approach.

* style: adjust spacing and gaps in UI components for consistency

* style: replace inline styles with tailwind classes for consistency

Refactor various components to use tailwind classes instead of inline styles to maintain consistency and improve readability. Changes include:
- Replacing style attributes with tailwind classes for spacing, margins, and padding
- Standardizing gap sizes across components
- Using tailwind for width, height, and other layout properties
- Updating test files to match new class names

* style(settings): replace inline styles with tailwind classes for consistency

Refactor settings components to use tailwind gap utility instead of inline styles for better maintainability and consistency across the codebase

* refactor(styles): replace inline styles with tailwind classes for consistency

* feat(eslint): add rule to restrict antd Flex imports

Enforce using custom Layout components instead of antd's Flex by adding a restricted import rule

* refactor: migrate flex layout from antd props to tailwind classes

- Replace antd Flex component props with tailwind classes for consistency
- Update gap and alignment values to use tailwind's spacing scale
- Remove unused antd Flex imports to clean up dependencies

* style(settings): adjust spacing and layout in various settings components

- Add gap spacing between elements in multiple settings components
- Remove redundant flex class in some components
- Standardize gap sizes across related components

* refactor(ui): replace inline styles with tailwind classes for consistency

Replace various inline style attributes with equivalent tailwind classes across multiple components to maintain consistent styling approach. Changes include margin, padding, width, and flex properties.

- Convert style attributes to tailwind classes
- Standardize spacing values using tailwind's spacing scale
- Improve maintainability by using utility classes

* style(ui): adjust spacing in model list group header

* style(css): wrap base styles in @layer for better organization

* style(css): fix indentation and nesting in global styles

* style(settings): adjust spacing in model list and convert subtitle to cn

Refactor SettingSubtitle to use cn utility for better className handling
Add gap spacing between model list items for improved layout

* style(css): move some styles from base layer to outer in index.css

* refactor(components): replace HStack with RowFlex for consistency

Update layout components to use RowFlex instead of HStack to maintain consistent naming

* style: reorder imports in useAppInit and BaseApiClient files

* fix(MinAppTabsPool): wrong import path

* refactor: update style file extensions from scss to css

Update file extensions and comments to reflect the change from SCSS to CSS stylesheets

* feat(layout): add Flex component and its variants

Introduce new Flex component with Box, RowFlex, SpaceBetweenRowFlex, ColFlex and Center variants to provide reusable layout components

* refactor: migrate layout components to @cherrystudio/ui package

This commit updates all imports of layout components (Box, Flex, RowFlex, ColFlex, etc.) from '@renderer/components/Layout' to '@cherrystudio/ui' across the codebase. The change also includes updating related test files and eslint configuration to reflect this migration. This refactoring aims to centralize layout components in a shared package for better maintainability and consistency.

* docs(eslint): update comment and restricted imports rule

Update comment to clarify the purpose of the rule and add a TODO note for future migration

* docs(ui): update migration status for layout components

Mark Layout/* components as migrated and refactored in both Chinese and English documentation

* docs: update migration status for Layout components
2025-09-17 18:17:17 +08:00
one
aab941d89c refactor: migrate sortable (#10204)
* refactor: rename sortable dir

* refactor: migrate Sortable to the ui package

* feat: add stories for Sortable

* refactor: add scroller to the vertical story

* refactor: improve hints and width

* refactor: simplify item style

* fix: lint errors

* chore: dependencies

* refactor: move hooks

* fix: import errors

* style: format

* style: format
2025-09-17 17:26:40 +08:00
MyPrototypeWhat
1b04fd065d refactor(ui): enhance CustomCollapse and ToolsCallingIcon components
- Refactored CustomCollapse to utilize Accordion and AccordionItem from HeroUI, simplifying props and improving functionality.
- Updated ToolsCallingIcon to accept TooltipProps for better customization.
- Revised stories for CustomCollapse to reflect new prop structure and added examples for various use cases.
- Cleaned up unnecessary props and improved documentation in story files.
2025-09-17 15:45:22 +08:00
MyPrototypeWhat
76b3ba5d7e feat(ui): integrate @storybook/addon-themes and enhance CustomCollapse component
- Added @storybook/addon-themes to package.json and yarn.lock for theme support in Storybook.
- Updated CustomCollapse component to utilize HeroUI's Accordion and AccordionItem for improved functionality and styling.
- Removed the ReasoningIcon component as it was deemed unnecessary.
- Enhanced ProviderAvatar component to ensure consistent className handling.
- Added new stories for FileIcons, SvgSpinners180Ring, and ToolsCallingIcon to showcase their usage and variations.
2025-09-17 14:53:34 +08:00
fullex
355e5b269d Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-17 14:28:36 +08:00
Phantom
d4b0272fe7 refactor: prefer import type (#10190)
* style(linter): enable consistent-type-imports rule in typescript

* chore: add biome to lint script for improved code formatting

* chore: add oxlint-specific lint script for faster linting

* refactor: use type-only imports for better type safety and clarity
2025-09-17 12:32:53 +08:00
MyPrototypeWhat
59bf94b118 refactor(ui): update migration status and enhance component implementations
- Increased the refactored component count to 18 and reduced pending migrations to 184 in the migration status files.
- Improved the Ellipsis, ListItem, MaxContextCount, and ThinkingEffect components by simplifying their structure and enhancing styling.
- Updated the tsconfig.json to adjust the root directory for better project organization.
- Removed unnecessary alias configurations in tsdown.config.ts for cleaner setup.
- Added new stories for Ellipsis and ListItem components to improve documentation and showcase their usage.
2025-09-16 19:20:04 +08:00
fullex
bd7cd22220 refactor: update data management documentation and structure
- Renamed "State Management" to "Data Management" in CLAUDE.md for clarity.
- Enhanced data management section with detailed descriptions of Cache System, Preference System, and User Data API.
- Updated README.md in shared/data to reflect new directory structure and provide clearer organization of type definitions and schemas.
- Added guidelines for selecting appropriate data access patterns based on data characteristics.
2025-09-16 17:30:02 +08:00
MyPrototypeWhat
f48674b2c7 refactor(ui): clean up component code and improve styling
- Refactored EmojiIcon, ExpandableText, and ProviderAvatar components for better readability and consistency.
- Simplified JSX structure and improved styling in ExpandableText and EmojiAvatar stories.
- Enhanced code formatting in various files for improved maintainability.
2025-09-16 17:21:01 +08:00
MyPrototypeWhat
56af6f43c0 refactor(ui): update button elements to include type attribute
- Added type="button" to button elements in DividerWithText and Icon stories for better accessibility and to prevent unintended form submissions.
- Improved code consistency across button components in the UI stories.
2025-09-16 17:15:40 +08:00
MyPrototypeWhat
f83c3e171e chore(ui): update migration status and component files
- Updated migration status to reflect the migration of additional components, reducing the total migrated count to 34 and increasing the refactored count to 14.
- Enhanced component files by refactoring several components to improve structure and styling, including CopyButton, CustomTag, and IndicatorLight.
- Added new stories for components such as CopyButton, CustomCollapse, and DividerWithText to improve documentation and showcase usage.
- Adjusted TypeScript configuration to include story files for better type checking.
2025-09-16 17:12:10 +08:00
fullex
d397a43806 fix: typecheck/test:lint/format:check
feat: add data related test
2025-09-16 15:26:36 +08:00
fullex
8353f331f1 test: update tests to use usePreference hook and improve snapshot consistency
- Refactored tests in MainTextBlock and ThinkingBlock to utilize the usePreference hook for managing user settings.
- Updated snapshots in DraggableVirtualList test to reflect changes in class names.
- Enhanced export tests to ensure proper handling of markdown formatting and citation footnotes.
- Mocked additional dependencies globally for improved test reliability.
2025-09-16 14:07:54 +08:00
MyPrototypeWhat
8cc6b08831 chore(ui): update package.json and migration status files
- Reformatted keywords and files array in package.json for better readability.
- Updated migration status to reflect the migration of additional components, increasing the total migrated count to 46 and reducing pending migrations to 190.
- Added new components to the migration status table, including ErrorBoundary and ProviderAvatar, while removing deprecated components like ErrorTag, SuccessTag, and WarnTag.
2025-09-16 13:32:25 +08:00
fullex
ffe897d58c chore: update yarn.lock and refactor SettingsTab component
- Added "@typescript-eslint/visitor-keys@npm:8.43.0" to yarn.lock.
- Refactored getVirtualIndexes in DraggableVirtualList to use item.index.
- Replaced useSettings with usePreference for codeFancyBlock in SettingsTab.
- Updated Switch component to use setCodeFancyBlock directly.
2025-09-16 11:56:10 +08:00
fullex
182ac3bc98 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-16 11:35:18 +08:00
fullex
c0cca4ae44 chore: update configuration and improve cache management
- Added "packages/ui/scripts/**" to .oxlintrc.json for linting.
- Excluded ".claude/**" from biome.jsonc.
- Refactored API path types in apiPaths.ts for better clarity.
- Updated error handling in errorCodes.ts to ensure stack trace is always available.
- Modified preferenceSchemas.ts to include new features and updated generated timestamp.
- Cleaned up tsconfig.json for better organization.
- Adjusted CustomTag component to improve rendering logic.
- Enhanced CodeEditor utility functions for better type safety.
- Improved Scrollbar story for better readability.
- Refactored CacheService to streamline comments and improve documentation.
- Updated useCache and useSharedCache hooks for better clarity and functionality.
- Cleaned up selectionStore and settings.ts by commenting out deprecated actions.
- Updated DataApiHookTests for better optimistic update handling.
2025-09-16 11:27:18 +08:00
one
8981d0a09d refactor(CodeEditor): decouple CodeEditor and global settings (#10163)
* refactor(CodeEditor): decouple CodeEditor and global settings

* refactor: improve language extension fallbacks

* refactor: make a copy of CodeEditor in the ui package

* refactor: update ui CodeEditor and language list

* refactor: use CodeEditor from the ui package

* feat: add a story for CodeEditor
2025-09-16 10:11:36 +08:00
Phantom
de44938d9b fix: ui package env (#10191)
* ci: add ui package to oxlint configuration

* chore: update vscode settings for oxlintrc.json association
2025-09-16 10:08:52 +08:00
fullex
75d5dcf275 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-16 00:46:42 +08:00
fullex
d8f4825e5e Merge branch 'v2' of github.com:CherryHQ/cherry-studio into v2 2025-09-16 00:40:48 +08:00
fullex
c242abd81a feat: refactor cache management and update component dependencies
- Updated package.json to version 2.0.0-alpha, reflecting significant changes.
- Refactored cache management by integrating useCache hooks across various components, enhancing state management and performance.
- Replaced useRuntime references with useMinapps in multiple components to streamline minapp state handling.
- Improved type safety in cache schemas and updated related components to utilize new types.
- Removed deprecated runtime actions and streamlined the codebase for better maintainability.
2025-09-16 00:40:36 +08:00
MyPrototypeWhat
79c9ed963f feat: update UI package with Storybook integration and Tailwind CSS v4 configuration
- Added Storybook scripts for development and building the UI components.
- Updated package.json to include new dependencies for Storybook and styled-components.
- Revised README to reflect changes in Tailwind CSS configuration, transitioning to v4 and removing the tailwind.config.js file.
- Enhanced the tsdown configuration to mark additional peer dependencies as external.
- Removed outdated Tailwind CSS configuration file to streamline the setup.
2025-09-15 19:26:23 +08:00
fullex
6079961f44 feat: enhance testing framework for CacheService and PreferenceService
- Updated README.md to reflect the expanded testing framework for CacheService, including detailed test modules and scenarios.
- Added CacheService tests for direct API, hooks, advanced features, and stress testing.
- Refactored TestApp to incorporate CacheService tests alongside existing PreferenceService tests, improving organization and accessibility.
- Adjusted component styling to support dark mode and ensure consistent UI across test components.
2025-09-15 17:36:14 +08:00
MyPrototypeWhat
04ef5edea2 feat: update migration status and add new UI components
- Updated migration status documentation to reflect the migration of 43 components, with 193 pending.
- Enhanced the component status table with new entries for MaxContextCount, CollapsibleSearchBar, ImageToolButton, and InfoPopover.
- Added implementations for the new components, improving the UI library's functionality.
- Updated index.ts to export the newly added components for better accessibility.
2025-09-15 16:08:35 +08:00
MyPrototypeWhat
046ed3edef feat: update migration status and add ListItem and EditableNumber components
- Updated migration status documentation to reflect the migration of 38 components, with 198 pending.
- Enhanced the component status table with new entries for ListItem and EditableNumber.
- Added ListItem and EditableNumber components with their respective implementations and styles.
- Updated index.ts to export the newly added components for improved accessibility.
2025-09-15 15:23:03 +08:00
MyPrototypeWhat
6eb9ab30b0 feat: update migration status and add new UI components
- Updated migration status documentation to reflect the migration of 36 components, with 200 pending.
- Enhanced the component status table with new entries for CustomCollapse, EmojiAvatar, ResetIcon, OcrIcon, ToolIcon, WrapIcon, UnWrapIcon, HelpTooltip, Selector, and WarnTooltip.
- Updated index.ts to export the newly added components for improved accessibility.
2025-09-15 15:12:28 +08:00
MyPrototypeWhat
1c27481813 feat: update migration status and add new UI components
- Updated migration status documentation to reflect the migration of 26 components, with 210 pending.
- Enhanced the component status table with detailed descriptions and categorized components.
- Introduced new components: CustomTag, ErrorTag, SuccessTag, WarnTag, CopyIcon, DeleteIcon, EditIcon, and RefreshIcon.
- Updated index.ts to export the newly added components for improved accessibility.
2025-09-15 14:59:52 +08:00
fullex
a6e19f7757 refactor: consolidate CacheService implementation and update references
- Moved CacheService functionality to a new implementation in @data/CacheService, enhancing modularity.
- Updated all references across the codebase to utilize the new cacheService instance.
- Removed the old CacheService files from both main and renderer directories to streamline the codebase.
2025-09-15 14:47:30 +08:00
fullex
6d89f94335 feat: CacheService & useCache Hooks 2025-09-15 14:12:41 +08:00
MyPrototypeWhat
2e07b4ea58 feat: add migration status documentation and new UI components
- Introduced migration status documentation in both English and Chinese to track the progress of the UI component library migration.
- Added new UI components including CopyButton, DividerWithText, EmojiIcon, IndicatorLight, Spinner, TextBadge, and various display and icon components.
- Updated the index.ts file to export the newly added components for easier access.
- Enhanced the directory structure and component classification guidelines for better organization and clarity.
2025-09-15 14:10:49 +08:00
MyPrototypeWhat
bf2f6ddd7f chore: update CODEOWNERS to include new UI package ownership
- Added ownership for the /packages/ui/ directory to @MyPrototypeWhat.
- Ensured consistent ownership assignment across relevant directories.
2025-09-15 12:34:56 +08:00
MyPrototypeWhat
c936bddfe7 feat: add index.ts type definitions for UI components
- Introduced a new TypeScript definition file (index.ts) to support the newly added UI component library.
- This file will facilitate better type checking and autocompletion for developers using the library.
2025-09-15 12:33:47 +08:00
MyPrototypeWhat
d3028f1dd1 feat: add @cherrystudio/ui component library
- Introduced a new UI component library for Cherry Studio, including various components such as buttons, inputs, and layout elements.
- Updated configuration files to include the new library and its dependencies.
- Enhanced the project structure to support modular imports and TypeScript definitions for better development experience.
2025-09-15 12:03:39 +08:00
MyPrototypeWhat
0038280fba refactor: update import paths for styles and navbar position
- Changed the import of navbar position hook from useSettings to useNavbarPosition for better clarity.
- Updated style imports from index.scss to index.css for consistency across components.
2025-09-15 11:45:12 +08:00
fullex
0a94609f78 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-15 00:06:06 +08:00
fullex
f9f8390540 Merge branch 'v2' of github.com:CherryHQ/cherry-studio into v2 2025-09-14 21:01:07 +08:00
fullex
91dd6482ce chore: add CODEOWNERS file to define ownership for specific directories
- Created a CODEOWNERS file to specify ownership for migrations and data directories.
- Assigned ownership to @0xfullex for the specified paths to streamline code review and management.
2025-09-14 21:00:57 +08:00
fullex
016bbff79f Update pr-ci.yml 2025-09-14 18:52:58 +08:00
fullex
32f41391c4 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2025-09-14 17:39:42 +08:00
fullex
78a8ebc777 feat(preferences): update user theme settings and add new preferences
- Updated preferences configuration with new user theme options including font family and code font family.
- Added new preferences for chat and export menus.
- Adjusted default preferences to include new settings for user theme.
- Enhanced useUserTheme hook to manage new font family preferences.
2025-09-14 17:05:31 +08:00
fullex
57fd73e51a Merge branch 'main' of github.com:CherryHQ/cherry-studio into wip/data-refactor 2025-09-14 17:05:14 +08:00
fullex
bd448b5108 refactor: remove AbortSignal support from DataApiService and related components
- Eliminated AbortSignal handling from ApiClient interface and DataApiService to streamline request processing.
- Updated IpcAdapter to remove event sender logic for responses, aligning with the new direct IPC approach.
- Adjusted tests to reflect the removal of cancellation capabilities, emphasizing that direct IPC requests cannot be cancelled.
- Cleaned up related code and comments to enhance clarity and maintainability.
2025-09-13 13:50:59 +08:00
fullex
a7d12abd1f feat: add Data API channels and integrate swr for data fetching
- Introduced new IPC channels for Data API requests and responses in IpcChannel.
- Added swr library to package.json for improved data fetching capabilities.
- Updated preload API to include Data API related methods for handling requests and subscriptions.
- Removed deprecated pending_default_values.ts file as part of data refactor.
2025-09-13 00:55:15 +08:00
fullex
9e3618bc17 refactor: update selection preferences and enums for improved consistency
- Removed deprecated selection IPC channels from IpcChannel.
- Replaced string literals with enums for SelectionTriggerMode and SelectionFilterMode in preference management.
- Updated the SelectionService and selectionStore to utilize the new enum types for better type safety and clarity.
- Marked selectionStore as deprecated for future removal after data refactoring.
2025-09-09 12:14:29 +08:00
fullex
8cb270ca86 fix: restore LANG_DETECT_PROMPT import in translate utility and reorder imports in MiniWindowApp 2025-09-06 18:44:26 +08:00
fullex
d321cd23ef chore: format 2025-09-06 18:32:33 +08:00
fullex
9da3e82c47 refactor: update preference management in AI components
- Replaced instances of useSettings with usePreference for better preference handling across various components.
- Updated function signatures to support async operations where necessary.
- Adjusted imports to utilize shared configuration for prompts, enhancing consistency in prompt management.
- Improved error handling and logging in AI-related functionalities.
2025-09-06 18:21:11 +08:00
fullex
2931e558b3 Merge branch 'main' of github.com:CherryHQ/cherry-studio into wip/data-refactor 2025-09-06 18:20:53 +08:00
fullex
9a847dc5a3 refactor: update Minapp components to use preference management
- Replaced useSettings with usePreference in PinnedMinapps and useMinappPopup components for better preference handling.
- Added external dependency for Electron in electron.vite.config.ts and set output format to CommonJS.
2025-09-06 17:23:19 +08:00
fullex
c2a1178dff refactor: update preferences management and enhance PreferenceService documentation
- Updated preferences types in preferences.ts to use PreferenceTypes for better type safety.
- Added new preference keys related to notes features in preferences.ts.
- Enhanced documentation in PreferenceService.ts and usePreference.ts to clarify usage and update strategies.
- Improved caching and subscription mechanisms in PreferenceService for better performance and reliability.
2025-09-04 12:47:22 +08:00
fullex
7f114ade4d Merge branch 'main' of github.com:CherryHQ/cherry-studio into wip/data-refactor 2025-09-03 21:21:38 +08:00
fullex
7b633641d1 Merge branch 'main' of github.com:CherryHQ/cherry-studio into wip/data-refactor 2025-09-03 16:58:15 +08:00
fullex
1dacdc3178 refactor: expand settings state with comprehensive user preferences
- Introduced a detailed SettingsState interface, incorporating various user preferences such as showAssistants, language settings, proxy configurations, and more.
- Updated initialState to reflect the new comprehensive settings structure, ensuring all preferences are initialized correctly.
- Cleaned up commented-out code and organized settings for improved clarity and maintainability.
- Enhanced type safety by integrating new types for various settings, aligning with recent refactoring efforts in preference management.
2025-09-03 16:53:29 +08:00
fullex
566dd14fed refactor: enhance preference management and streamline component integrations
- Updated various components to utilize the usePreference hook, replacing previous useSettings references for improved consistency and maintainability.
- Introduced new preference types for ChatMessageStyle, ChatMessageNavigationMode, and MultiModelMessageStyle to enhance type safety.
- Refactored preference handling in multiple files, ensuring a more streamlined approach to managing user preferences.
- Cleaned up unused code and comments related to previous settings for better clarity and maintainability.
- Updated auto-generated preference mappings to reflect recent changes in preference structure.
2025-09-03 16:48:04 +08:00
fullex
68cd87e069 refactor: update UpgradeChannel handling and improve preference integration
- Commented out the UpgradeChannel enum in constant.ts and moved it to preferenceTypes.ts for better organization.
- Updated various components to utilize the new UpgradeChannel type from preferenceTypes, enhancing type safety and consistency.
- Refactored preference handling across multiple files to streamline the use of the usePreference hook, replacing previous settings references.
- Cleaned up unused code and comments related to previous settings for improved maintainability.
- Updated auto-generated preference mappings to reflect recent changes in preference structure.
2025-09-03 14:31:15 +08:00
fullex
1b57ffeb56 refactor: enhance preference management and update component integrations
- Updated preference handling to utilize the usePreference hook across various components, improving consistency and maintainability.
- Introduced new preference types for ProxyMode and MultiModelFoldDisplayMode to enhance type safety.
- Refactored components to replace useSettings with usePreference, streamlining preference management.
- Cleaned up unused code and comments related to previous settings for better clarity.
- Updated auto-generated preference mappings to reflect recent changes in preference structure.
2025-09-02 22:11:15 +08:00
fullex
5d789ef394 refactor: enhance preference management and update sidebar icon handling
- Updated preferences to include new confirmation settings for message actions, allowing users to customize action confirmations.
- Refactored components to utilize the usePreference hook for improved preference handling, replacing previous useSettings references.
- Introduced new types for AssistantIconType and SidebarIcon to enhance type safety.
- Cleaned up unused code and comments related to previous settings for better maintainability.
- Updated auto-generated preference mappings to reflect recent changes in preference structure.
2025-09-02 17:24:38 +08:00
fullex
820d6a6e96 refactor: update preference keys and enhance preference management
- Updated preference keys from 'app.theme.*' to 'ui.*' for better organization and clarity.
- Introduced new preferences for assistant tab sorting and visibility.
- Refactored components to utilize the updated preference keys, improving consistency across the codebase.
- Cleaned up unused code and comments related to previous settings for maintainability.
- Updated auto-generated preference mappings to reflect the new structure.
2025-09-02 15:37:30 +08:00
fullex
0a67ab4103 refactor: enhance preference management and update mappings
- Updated preferences to utilize the new SendMessageShortcut type for better type safety.
- Refactored components to use the usePreference hook instead of useSettings for improved preference handling.
- Added new preferences for target language and send message shortcut in various components.
- Cleaned up unused code and comments related to settings for better maintainability.
- Updated auto-generated preference mappings to reflect recent changes in preference structure.
2025-09-02 13:24:41 +08:00
fullex
5cc7390bb6 Merge branch 'main' of github.com:CherryHQ/cherry-studio into wip/data-refactor 2025-09-02 11:50:00 +08:00
fullex
2ce4fabc7d refactor: update preference handling and remove unused settings
- Commented out the App_SetDisableHardwareAcceleration IPC channel and related code for hardware acceleration settings.
- Updated preferences to utilize the new WindowStyle type for window style settings.
- Refactored components to use the usePreference hook instead of useSettings for better preference management.
- Cleaned up unused code and comments related to hardware acceleration and window style for improved maintainability.
2025-09-02 11:45:33 +08:00
fullex
7b2570974e refactor: update language handling and remove unused locales
- Commented out the App_SetLanguage IPC channel and related language management code.
- Updated preferences to use LanguageVarious type for language settings.
- Removed the locales utility file and adjusted imports to utilize preferenceService for language management.
- Cleaned up unused code and comments related to language handling for improved maintainability.
2025-09-02 01:39:04 +08:00
fullex
0ef3852029 refactor: update theme handling and preference types
- Removed the App_SetTheme IPC channel and related theme management code.
- Updated imports to use preferenceTypes for theme and selection action items.
- Refactored preference service to preload preferences and adjusted related components.
- Cleaned up unused code and comments related to theme management.
- Enhanced the organization of preference-related types and actions for better maintainability.
2025-09-01 23:49:17 +08:00
fullex
0dce1c57fc Merge branch 'main' of github.com:CherryHQ/cherry-studio into wip/data-refactor 2025-09-01 09:44:12 +08:00
fullex
190ee76cf1 refactor(preload): update action item type to SelectionActionItem
Replaced the ActionItem type with SelectionActionItem in the processAction method for better type safety. Removed unused imports related to ActionItem in ActionTranslate component.
2025-08-28 10:54:12 +08:00
fullex
83fea49ed2 Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/data-refactor 2025-08-28 10:52:05 +08:00
fullex
ccc50dbf2b Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/data-refactor 2025-08-19 23:04:35 +08:00
fullex
6b503c4080 Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/data-refactor 2025-08-16 21:52:19 +08:00
fullex
40fe381aa5 refactor(preferences): replace empty action items with default values and remove unused hook
- Updated the preferences configuration to use `defaultActionItems` instead of an empty array for `feature.selection.action_items`, enhancing default behavior.
- Removed the `useSelectionAssistant` hook as it was no longer needed, streamlining the codebase.
2025-08-16 21:51:58 +08:00
fullex
65c24a2f4b fix(selection): disable sandbox mode in SelectionService and clean up imports in ActionTranslate component
- Changed sandbox mode from true to false in SelectionService to improve security and functionality.
- Removed unnecessary blank line in entryPoint.tsx for cleaner code.
- Updated ActionTranslate component to use the new SelectionActionItem type for better type safety.
2025-08-16 18:52:46 +08:00
fullex
b15778b16b feat(preferences): enhance selection management with type safety and refactor preferences structure
- Introduced new types for selection management: `SelectionActionItem`, `SelectionFilterMode`, and `SelectionTriggerMode` to improve type safety across the application.
- Updated `PreferencesType` to utilize these new types, ensuring better consistency and clarity in preference definitions.
- Refactored `SelectionService` and related components to adopt the new types, enhancing the handling of selection actions and preferences.
- Cleaned up deprecated types and improved the overall structure of preference management, aligning with recent updates in the preference system.
2025-08-16 08:57:48 +08:00
fullex
087e825086 feat(preferences): implement custom notifier for preference change management
- Introduced `PreferenceNotifier` class to replace `EventEmitter`, enhancing performance and memory efficiency for preference change notifications.
- Refactored `PreferenceService` to utilize the new notifier for managing subscriptions and notifications.
- Updated `SelectionService` to adopt the new subscription model, improving the handling of preference changes and ensuring proper cleanup of listeners.
- Enhanced subscription statistics and debugging capabilities within the notifier.
2025-08-15 19:45:13 +08:00
fullex
3dd2bc1a40 feat(preferences): enhance preference subscription and notification system
- Updated `PreferenceService` to notify change listeners immediately upon fetching uncached values.
- Refactored subscription logic to simplify auto-subscribing to preference keys.
- Modified `usePreference` and `useMultiplePreferences` hooks to improve handling of default values and subscription behavior.
- Enhanced `SelectionAssistantSettings` to include detailed logging of preference states for better debugging.
2025-08-15 18:27:36 +08:00
fullex
9bde833419 feat(preferences): implement optimistic and pessimistic update strategies in PreferenceService
- Introduced `PreferenceUpdateOptions` interface to configure update behavior.
- Enhanced `set` and `setMultiple` methods in `PreferenceService` to support both optimistic and pessimistic update strategies, allowing for immediate UI feedback or database-first updates.
- Updated `usePreference` and `useMultiplePreferences` hooks to accept options for flexible update strategies.
- Improved handling of concurrent updates with request queues and rollback mechanisms for optimistic updates.
- Enhanced documentation in hooks to clarify usage of update strategies.
2025-08-15 16:48:22 +08:00
fullex
e15005d1cf feat(preferences): update preferences structure and enhance shortcut management
- Updated the preferences configuration with new shortcut definitions and types for better management.
- Introduced a method to get and subscribe to preference changes in the PreferenceService, improving reactivity.
- Refactored SelectionService to utilize the new preference management system, enhancing code clarity and maintainability.
- Updated SelectionAssistantSettings to use the new preference hooks for managing selection settings.
- Adjusted the generated preferences file to reflect the latest configuration changes.
2025-08-15 12:54:24 +08:00
fullex
30e6883333 refactor(preferences): consolidate IPC handlers into PreferenceService
- Moved IPC handler logic for preference operations from ipc.ts to PreferenceService.
- Introduced a unified method for registering IPC handlers, improving code organization and maintainability.
- Enhanced preference change notification system with optimized performance and added support for main process listeners.
2025-08-14 18:01:22 +08:00
fullex
99be38c325 Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/refactor/databases 2025-08-13 13:24:26 +08:00
fullex
df876651b9 feat(preferences): enhance testing framework with real-time UI synchronization and slider controls
This commit updates the dataRefactorTest README to include new features such as real-time UI linkage for theme, language, and zoom preferences, as well as interactive slider controls for various settings. The TestApp component is modified to support dynamic window identification and theme monitoring. Additionally, the PreferenceBasicTests, PreferenceMultipleTests, and PreferenceServiceTests components are enhanced with slider functionality for numerical preferences, improving the testing capabilities for cross-window synchronization and user experience.
2025-08-12 23:42:10 +08:00
fullex
85bdcdc206 refactor(preferences): improve PreferenceService and related hooks with enhanced type safety and listener management
This commit refactors the PreferenceService to improve type safety for preference handling and updates the listener management system. It renames methods for clarity, ensuring that preference changes are properly notified to all relevant listeners. Additionally, the usePreference hook is updated to align with these changes, enhancing the overall consistency and reliability of preference management in the application.
2025-08-12 21:23:02 +08:00
fullex
2860935e5b refactor(preferences): enhance PreferenceService with public access modifiers and improve caching logic
This commit updates the PreferenceService by adding public access modifiers to several methods, improving code clarity and consistency. It also refines the caching logic to eliminate unnecessary type assertions and streamline the handling of preference values. Additionally, minor formatting adjustments are made for better readability across the service and related hooks.
2025-08-12 18:14:39 +08:00
fullex
b219e96544 feat(preferences): integrate PreferenceService and enhance testing capabilities
This commit refactors the PreferenceService to use named exports for better consistency and updates the DbService import accordingly. It introduces a testing mechanism for the PreferenceService by creating test windows to facilitate cross-window preference synchronization testing. Additionally, improvements are made to the usePreference hook for better performance and stability, ensuring efficient preference management in the application.
2025-08-12 13:44:41 +08:00
fullex
c02f93e6b9 feat(preferences): add data path alias and update TypeScript configuration
This commit introduces a new alias '@data' in the Electron Vite configuration for easier access to the data directory. Additionally, the TypeScript configuration is updated to include path mapping for '@data/*', enhancing module resolution. Several test files related to the PreferenceService have been removed, streamlining the test suite and focusing on essential functionality.
2025-08-12 11:35:09 +08:00
fullex
72f32e4b8f feat(preferences): add getAll method and IPC handler for retrieving all preferences
This commit introduces a new IPC channel and handler for fetching all user preferences at once, enhancing the efficiency of preference management. The PreferenceService is updated with a getAll method to retrieve all preferences from the memory cache, and the renderer-side PreferenceService is adjusted to support this new functionality. Additionally, type safety improvements are made across the preference handling code, ensuring better consistency and reducing potential errors.
2025-08-12 01:01:22 +08:00
fullex
a81f13848c refactor(preferences): enhance preference handling with type safety and improved IPC methods
This commit refines the preference management system by introducing type safety for preference keys and values, ensuring better consistency across the application. It updates IPC handlers for getting and setting preferences to utilize the new types, improving code clarity and reducing potential errors. Additionally, the PreferenceService is adjusted to align with these changes, enhancing the overall robustness of preference operations.
2025-08-11 22:58:30 +08:00
fullex
81538d5709 feat(preferences): add IPC channels and handlers for preference management
This commit introduces new IPC channels for getting, setting, and subscribing to preferences, enhancing the application's ability to manage user preferences. It also updates the preferences interface to use a consistent naming convention and refactors the preference seeding and migration processes to align with these changes. Additionally, the PrefService has been removed as it is no longer needed.
2025-08-11 20:40:50 +08:00
fullex
54449e7130 feat(migration): implement transaction handling and batch migration for preferences
This commit introduces a new transaction method in DbService to manage database operations with automatic rollback on error and commit on success. It enhances the PreferencesMigrator to support batch migration operations, improving the efficiency of migrating preferences from multiple sources. Additionally, the migration UI is updated to reflect progress during backup and migration stages, providing clearer feedback to users.
2025-08-10 23:25:28 +08:00
fullex
c217a0bf02 feat(migration): add Redux data handling to migration process
This commit introduces new IPC channels for sending and retrieving Redux persist data during the migration process. It enhances the DataRefactorMigrateService with methods to cache and manage Redux data, ensuring a smoother migration experience. Additionally, the MigrateApp component is updated to extract Redux data from localStorage and send it to the main process, improving the overall migration flow and user experience.
2025-08-10 20:58:43 +08:00
fullex
39257f64b1 feat(migration): enhance migration UI and refactor layout
This commit updates the migration window dimensions for improved usability, sets explicit entry points for preload scripts, and enhances the overall layout of the migration interface. It introduces new styles for buttons and alerts, improves the structure of the migration steps, and refines the user experience with clearer feedback and options during the migration process.
2025-08-10 13:51:08 +08:00
fullex
06dab978f7 feat(migration): update migration UI and enhance user experience
This commit modifies the migration window dimensions and properties for improved usability, allowing for resizing and maximizing. It also introduces new icons for different migration stages, updates localized messages for clarity, and enhances the overall layout of the migration interface, including adjustments to the alert messages and step indicators for better user guidance during the migration process.
2025-08-10 02:09:52 +08:00
fullex
c3f61533f7 feat(migration): enhance migration flow with new stages and error handling
This commit introduces additional stages to the migration process, including 'backup_required', 'backup_progress', and 'backup_confirmed', improving user guidance during data migration. It also adds new IPC channels for proceeding to backup and retrying migration, along with enhanced error handling and logging throughout the migration flow. The user interface has been updated to reflect these changes, providing clearer feedback and options during the migration process.
2025-08-10 01:40:03 +08:00
fullex
8715eb1f41 feat(migration): add new IPC channels and enhance migration flow
This commit introduces new IPC channels for starting the migration flow, restarting the application, and closing the migration window. It also updates the migration logic to improve user interaction and error handling during the migration process. Additionally, the migration interface has been enhanced with a step indicator and localized messages for better user experience.
2025-08-10 00:19:09 +08:00
fullex
92eb5aed7f refactor(migration): rename data migration files and update migration logic
This commit renames the data migration files for clarity, changing `dataMigrate.html` to `dataRefactorMigrate.html` and updating the corresponding service imports. It also enhances the migration logic by implementing a new `app_state` table structure and removing deprecated migration files, streamlining the overall migration process.
2025-08-09 22:37:20 +08:00
fullex
ff965402cd refactor(migration): streamline migration process and enhance IPC handling
This commit refines the data migration process by ensuring that migration checks occur before window creation and improves the logging of migration events. It also consolidates IPC handlers specific to migration within the MigrateService, allowing for better management of migration-related tasks. Additionally, the HTML for the data migration interface has been updated to enhance security policies.
2025-08-09 20:56:21 +08:00
fullex
973f26f9dd feat(migration): implement data migration service and update database architecture
This commit introduces a new data migration service with various IPC channels for migration tasks, including checking if migration is needed, starting the migration, and tracking progress. Additionally, the database architecture section has been added to the documentation, detailing the use of SQLite with Drizzle ORM, migration standards, and JSON field handling. Legacy migration files for ElectronStore and Redux have been removed as they are now deprecated.
2025-08-09 20:19:41 +08:00
fullex
4e3f8a8f76 feat(preferences): auto-generate preferences configuration from classification.json
This commit introduces an auto-generated preferences configuration file, replacing the previous manual definitions. The new structure is based on the latest classification.json and includes comprehensive settings for various application features. The auto-generation process ensures that the preferences are up-to-date and consistent with the defined classifications.
2025-08-09 16:44:35 +08:00
fullex
21e40db086 mv dir to data 2025-08-09 14:30:24 +08:00
fullex
92cd012037 Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/refactor/databases 2025-08-09 09:44:28 +08:00
fullex
7cd937888e Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/refactor/databases 2025-08-06 19:53:07 +08:00
fullex
ec491f5f24 更新 Preferences 接口以使用排序的对象键,并调整默认偏好设置的结构。同时,在 preference.ts 文件中添加了关于 scope 字段的注释,说明其未来用途。此更改旨在提高代码的可读性和一致性。 2025-08-02 00:22:22 +08:00
fullex
c0efb46c2b format 2025-07-28 22:40:19 +08:00
fullex
aa47fc3ed7 更新 yarn.lock 文件,添加了多个新依赖项,包括 @drizzle-team/brocli、@esbuild-kit/core-utils、@esbuild-kit/esm-loader 及其相关版本,同时更新了 esbuild 和 esbuild-register 的版本,确保依赖项的兼容性和稳定性。 2025-07-26 21:46:44 +08:00
fullex
c3c9f9b3f2 Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/refactor/databases 2025-07-26 21:46:02 +08:00
fullex
d486b56595 chore: update dependencies in package.json and yarn.lock 2025-07-03 12:21:31 +08:00
fullex
4bb5ff8086 Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/refactor/databases 2025-07-03 12:13:49 +08:00
fullex
a748162e67 chore: update yarn.lock and refactor database schema
- Added `get-tsconfig` dependency version 4.10.1 to yarn.lock.
- Updated schema path in sqlite-drizzle.config.ts from './src/main/db/schema/*' to './src/main/db/schemas/*'.
- Removed unused files: columnHelpers.ts, preference.ts, seed/index.ts, and seed/preferenceSeed.ts to clean up the codebase.
2025-05-27 12:09:08 +08:00
fullex
610e7481b3 Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/refactor/databases 2025-05-26 22:52:23 +08:00
fullex
9105e0f5c1 db init 2025-05-26 08:30:22 +08:00
fullex
a248517520 Merge branch 'main' of https://github.com/CherryHQ/cherry-studio into wip/refactor/databases 2025-05-23 11:01:19 +08:00
fullex
d31f35b16d feat: update dependencies in package.json and yarn.lock
- Added better-sqlite3, drizzle-orm, drizzle-kit, and their respective type definitions.
- Updated various esbuild-related packages to their latest versions.
- Enhanced package management for improved compatibility and performance.
2025-05-20 12:40:17 +08:00
1142 changed files with 45530 additions and 9133 deletions

9
.github/CODEOWNERS vendored
View File

@@ -1,4 +1,11 @@
/src/renderer/src/store/ @0xfullex
/src/main/services/ConfigManager.ts @0xfullex
/packages/shared/IpcChannel.ts @0xfullex
/src/main/ipc.ts @0xfullex
/src/main/ipc.ts @0xfullex
/migrations/ @0xfullex
/packages/shared/data/ @0xfullex
/src/main/data/ @0xfullex
/src/renderer/src/data/ @0xfullex
/packages/ui/ @MyPrototypeWhat

View File

@@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
env:
PRCI: true
if: github.event.pull_request.draft == false
if: github.event.pull_request.draft == false || github.head_ref == 'v2'
steps:
- name: Check out Git repository

View File

@@ -27,7 +27,7 @@
"env": {
"node": true
},
"files": ["src/main/**", "resources/scripts/**", "scripts/**", "playwright.config.ts", "electron.vite.config.ts"]
"files": ["src/main/**", "resources/scripts/**", "scripts/**", "playwright.config.ts", "electron.vite.config.ts", "packages/ui/scripts/**"]
},
{
"env": {
@@ -37,6 +37,7 @@
"src/renderer/**/*.{ts,tsx}",
"packages/aiCore/**",
"packages/extension-table-plus/**",
"packages/ui/**",
"resources/js/**"
]
},
@@ -140,7 +141,7 @@
"typescript/await-thenable": "warn",
// "typescript/ban-ts-comment": "error",
"typescript/no-array-constructor": "error",
// "typescript/consistent-type-imports": "error",
"typescript/consistent-type-imports": "error",
"typescript/no-array-delete": "warn",
"typescript/no-base-to-string": "warn",
"typescript/no-duplicate-enum-values": "error",

View File

@@ -31,7 +31,8 @@
},
"editor.formatOnSave": true,
"files.associations": {
"*.css": "tailwindcss"
"*.css": "tailwindcss",
".oxlintrc.json": "jsonc"
},
"files.eol": "\n",
// "i18n-ally.displayLanguage": "zh-cn", // 界面显示语言

113
CLAUDE.md
View File

@@ -35,14 +35,113 @@ This file provides guidance to AI coding assistants when working with code in th
- **Renderer Process** (`src/renderer/`): React UI with Redux state management
- **Preload Scripts** (`src/preload/`): Secure IPC bridge
### Key Components
- **AI Core** (`src/renderer/src/aiCore/`): Middleware pipeline for multiple AI providers.
- **Services** (`src/main/services/`): MCPService, KnowledgeService, WindowService, etc.
- **Build System**: Electron-Vite with experimental rolldown-vite, yarn workspaces.
- **State Management**: Redux Toolkit (`src/renderer/src/store/`) for predictable state.
- **UI Components**: HeroUI (`@heroui/*`) for all new UI elements.
### Key Architectural Components
#### Main Process Services (`src/main/services/`)
- **MCPService**: Model Context Protocol server management
- **KnowledgeService**: Document processing and knowledge base management
- **FileStorage/S3Storage/WebDav**: Multiple storage backends
- **WindowService**: Multi-window management (main, mini, selection windows)
- **ProxyManager**: Network proxy handling
- **SearchService**: Full-text search capabilities
#### AI Core (`src/renderer/src/aiCore/`)
- **Middleware System**: Composable pipeline for AI request processing
- **Client Factory**: Supports multiple AI providers (OpenAI, Anthropic, Gemini, etc.)
- **Stream Processing**: Real-time response handling
#### Data Management
- **Cache System**: Three-layer caching (memory/shared/persist) with React hooks integration
- **Preferences**: Type-safe configuration management with multi-window synchronization
- **User Data**: SQLite-based storage with Drizzle ORM for business data
#### Knowledge Management
- **Embeddings**: Vector search with multiple providers (OpenAI, Voyage, etc.)
- **OCR**: Document text extraction (system OCR, Doc2x, Mineru)
- **Preprocessing**: Document preparation pipeline
- **Loaders**: Support for various file formats (PDF, DOCX, EPUB, etc.)
### Build System
- **Electron-Vite**: Development and build tooling (v4.0.0)
- **Rolldown-Vite**: Using experimental rolldown-vite instead of standard vite
- **Workspaces**: Monorepo structure with `packages/` directory
- **Multiple Entry Points**: Main app, mini window, selection toolbar
- **Styled Components**: CSS-in-JS styling with SWC optimization
### Testing Strategy
- **Vitest**: Unit and integration testing
- **Playwright**: End-to-end testing
- **Component Testing**: React Testing Library
- **Coverage**: Available via `yarn test:coverage`
### Key Patterns
- **IPC Communication**: Secure main-renderer communication via preload scripts
- **Service Layer**: Clear separation between UI and business logic
- **Plugin Architecture**: Extensible via MCP servers and middleware
- **Multi-language Support**: i18n with dynamic loading
- **Theme System**: Light/dark themes with custom CSS variables
### UI Design
The project is in the process of migrating from antd & styled-components to HeroUI. Please use HeroUI to build UI components. The use of antd and styled-components is prohibited.
HeroUI Docs: https://www.heroui.com/docs/guide/introduction
### Database Architecture
- **Database**: SQLite (`cherrystudio.sqlite`) + libsql driver
- **ORM**: Drizzle ORM with comprehensive migration system
- **Schemas**: Located in `src/main/data/db/schemas/` directory
#### Database Standards
- **Table Naming**: Use singular form with snake_case (e.g., `topic`, `message`, `app_state`)
- **Schema Exports**: Export using `xxxTable` pattern (e.g., `topicTable`, `appStateTable`)
- **Field Definition**: Drizzle auto-infers field names, no need to add default field names
- **JSON Fields**: For JSON support, add `{ mode: 'json' }`, refer to `preference.ts` table definition
- **JSON Serialization**: For JSON fields, no need to manually serialize/deserialize when reading/writing to database, Drizzle handles this automatically
- **Timestamps**: Use existing `crudTimestamps` utility
- **Migrations**: Generate via `yarn run migrations:generate`
## Data Access Patterns
The application uses three distinct data management systems. Choose the appropriate system based on data characteristics:
### Cache System
- **Purpose**: Temporary data that can be regenerated
- **Lifecycle**: Component-level (memory), window-level (shared), or persistent (survives restart)
- **Use Cases**: API response caching, computed results, temporary UI state
- **APIs**: `useCache`, `useSharedCache`, `usePersistCache` hooks, or `cacheService`
### Preference System
- **Purpose**: User configuration and application settings
- **Lifecycle**: Permanent until user changes
- **Use Cases**: Theme, language, editor settings, user preferences
- **APIs**: `usePreference`, `usePreferences` hooks, or `preferenceService`
### User Data API
- **Purpose**: Core business data (conversations, files, notes, etc.)
- **Lifecycle**: Permanent business records
- **Use Cases**: Topics, messages, files, knowledge base, user-generated content
- **APIs**: `useDataApi` hook or `dataApiService` for direct calls
### Selection Guidelines
- **Use Cache** for data that can be lost without impact (computed values, API responses)
- **Use Preferences** for user settings that affect app behavior (UI configuration, feature flags)
- **Use User Data API** for irreplaceable business data (conversations, documents, user content)
## Logging Standards
### Usage
### Logging
```typescript
import { loggerService } from '@logger'
const logger = loggerService.withContext('moduleName')

View File

@@ -38,6 +38,7 @@
"!.github/**",
"!.husky/**",
"!.vscode/**",
"!.claude/**",
"!*.yaml",
"!*.yml",
"!*.mjs",

View File

@@ -63,6 +63,9 @@ asarUnpack:
- resources/**
- "**/*.{metal,exp,lib}"
- "node_modules/@img/sharp-libvips-*/**"
extraResources:
- from: "migrations/sqlite-drizzle"
to: "migrations/sqlite-drizzle"
win:
executableName: Cherry Studio
artifactName: ${productName}-${version}-${arch}-setup.${ext}

View File

@@ -22,6 +22,7 @@ export default defineConfig({
alias: {
'@main': resolve('src/main'),
'@types': resolve('src/renderer/src/types'),
'@data': resolve('src/main/data'),
'@shared': resolve('packages/shared'),
'@logger': resolve('src/main/services/LoggerService'),
'@mcp-trace/trace-core': resolve('packages/mcp-trace/trace-core'),
@@ -61,7 +62,20 @@ export default defineConfig({
}
},
build: {
sourcemap: isDev
sourcemap: isDev,
rollupOptions: {
// Unlike renderer which auto-discovers entries from HTML files,
// preload requires explicit entry point configuration for multiple scripts
input: {
index: resolve(__dirname, 'src/preload/index.ts'),
simplest: resolve(__dirname, 'src/preload/simplest.ts') // Minimal preload
},
external: ['electron'],
output: {
entryFileNames: '[name].js',
format: 'cjs'
}
}
}
},
renderer: {
@@ -90,12 +104,14 @@ export default defineConfig({
'@shared': resolve('packages/shared'),
'@types': resolve('src/renderer/src/types'),
'@logger': resolve('src/renderer/src/services/LoggerService'),
'@data': resolve('src/renderer/src/data'),
'@mcp-trace/trace-core': resolve('packages/mcp-trace/trace-core'),
'@mcp-trace/trace-web': resolve('packages/mcp-trace/trace-web'),
'@cherrystudio/ai-core/provider': resolve('packages/aiCore/src/core/providers'),
'@cherrystudio/ai-core/built-in/plugins': resolve('packages/aiCore/src/core/plugins/built-in'),
'@cherrystudio/ai-core': resolve('packages/aiCore/src'),
'@cherrystudio/extension-table-plus': resolve('packages/extension-table-plus/src')
'@cherrystudio/extension-table-plus': resolve('packages/extension-table-plus/src'),
'@cherrystudio/ui': resolve('packages/ui/src')
}
},
optimizeDeps: {
@@ -115,7 +131,8 @@ export default defineConfig({
miniWindow: resolve(__dirname, 'src/renderer/miniWindow.html'),
selectionToolbar: resolve(__dirname, 'src/renderer/selectionToolbar.html'),
selectionAction: resolve(__dirname, 'src/renderer/selectionAction.html'),
traceWindow: resolve(__dirname, 'src/renderer/traceWindow.html')
traceWindow: resolve(__dirname, 'src/renderer/traceWindow.html'),
dataRefactorMigrate: resolve(__dirname, 'src/renderer/dataRefactorMigrate.html')
},
onwarn(warning, warn) {
if (warning.code === 'COMMONJS_VARIABLE_IN_ESM') return

View File

@@ -72,8 +72,9 @@ export default defineConfig([
...oxlint.configs['flat/eslint'],
...oxlint.configs['flat/typescript'],
...oxlint.configs['flat/unicorn'],
// Custom rules should be after oxlint to overwrite
// LoggerService Custom Rules - only apply to src directory
{
// LoggerService Custom Rules - only apply to src directory
files: ['src/**/*.{ts,tsx,js,jsx}'],
ignores: ['src/**/__tests__/**', 'src/**/__mocks__/**', 'src/**/*.test.*', 'src/preload/**'],
rules: {
@@ -87,6 +88,7 @@ export default defineConfig([
]
}
},
// i18n
{
files: ['**/*.{ts,tsx,js,jsx}'],
languageOptions: {
@@ -134,4 +136,30 @@ export default defineConfig([
'i18n/no-template-in-t': 'warn'
}
},
// ui migration
{
// Component Rules - prevent importing antd components when migration completed
files: ['**/*.{ts,tsx,js,jsx}'],
ignores: ['src/renderer/src/windows/dataRefactorTest/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'antd',
importNames: ['Flex', 'Switch', 'message', 'Button', 'Tooltip'],
message:
'❌ Do not import this component from antd. Use our custom components instead: import { ... } from "@cherrystudio/ui"'
},
// {
// name: '@heroui/react',
// message:
// '❌ Do not import components from heroui directly. Use our wrapped components instead: import { ... } from "@cherrystudio/ui"'
// }
]
}
]
}
},
])

6
migrations/README.md Normal file
View File

@@ -0,0 +1,6 @@
**THIS DIRECTORY IS NOT FOR RUNTIME USE**
- Using `libsql` as the `sqlite3` driver, and `drizzle` as the ORM and database migration tool
- `migrations/sqlite-drizzle` contains auto-generated migration data. Please **DO NOT** modify it.
- If table structure changes, we should run migrations.
- To generate migrations, use the command `yarn run migrations:generate`

View File

@@ -0,0 +1,7 @@
import { defineConfig } from 'drizzle-kit'
export default defineConfig({
out: './migrations/sqlite-drizzle',
schema: './src/main/data/db/schemas/*',
dialect: 'sqlite',
casing: 'snake_case'
})

View File

@@ -0,0 +1,17 @@
CREATE TABLE `app_state` (
`key` text PRIMARY KEY NOT NULL,
`value` text NOT NULL,
`description` text,
`created_at` integer,
`updated_at` integer
);
--> statement-breakpoint
CREATE TABLE `preference` (
`scope` text NOT NULL,
`key` text NOT NULL,
`value` text,
`created_at` integer,
`updated_at` integer
);
--> statement-breakpoint
CREATE INDEX `scope_name_idx` ON `preference` (`scope`,`key`);

View File

@@ -0,0 +1,114 @@
{
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
},
"dialect": "sqlite",
"enums": {},
"id": "de8009d7-95b9-4f99-99fa-4b8795708f21",
"internal": {
"indexes": {}
},
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"app_state": {
"checkConstraints": {},
"columns": {
"created_at": {
"autoincrement": false,
"name": "created_at",
"notNull": false,
"primaryKey": false,
"type": "integer"
},
"description": {
"autoincrement": false,
"name": "description",
"notNull": false,
"primaryKey": false,
"type": "text"
},
"key": {
"autoincrement": false,
"name": "key",
"notNull": true,
"primaryKey": true,
"type": "text"
},
"updated_at": {
"autoincrement": false,
"name": "updated_at",
"notNull": false,
"primaryKey": false,
"type": "integer"
},
"value": {
"autoincrement": false,
"name": "value",
"notNull": true,
"primaryKey": false,
"type": "text"
}
},
"compositePrimaryKeys": {},
"foreignKeys": {},
"indexes": {},
"name": "app_state",
"uniqueConstraints": {}
},
"preference": {
"checkConstraints": {},
"columns": {
"created_at": {
"autoincrement": false,
"name": "created_at",
"notNull": false,
"primaryKey": false,
"type": "integer"
},
"key": {
"autoincrement": false,
"name": "key",
"notNull": true,
"primaryKey": false,
"type": "text"
},
"scope": {
"autoincrement": false,
"name": "scope",
"notNull": true,
"primaryKey": false,
"type": "text"
},
"updated_at": {
"autoincrement": false,
"name": "updated_at",
"notNull": false,
"primaryKey": false,
"type": "integer"
},
"value": {
"autoincrement": false,
"name": "value",
"notNull": false,
"primaryKey": false,
"type": "text"
}
},
"compositePrimaryKeys": {},
"foreignKeys": {},
"indexes": {
"scope_name_idx": {
"columns": ["scope", "key"],
"isUnique": false,
"name": "scope_name_idx"
}
},
"name": "preference",
"uniqueConstraints": {}
}
},
"version": "6",
"views": {}
}

View File

@@ -0,0 +1,13 @@
{
"dialect": "sqlite",
"entries": [
{
"breakpoints": true,
"idx": 0,
"tag": "0000_solid_lord_hawal",
"version": "6",
"when": 1754745234572
}
],
"version": "7"
}

View File

@@ -1,6 +1,6 @@
{
"name": "CherryStudio",
"version": "1.7.0-alpha.5",
"version": "2.0.0-alpha",
"private": true,
"description": "A powerful AI assistant for producer.",
"main": "./out/main/index.js",
@@ -50,9 +50,10 @@
"generate:icons": "electron-icon-builder --input=./build/logo.png --output=build",
"analyze:renderer": "VISUALIZER_RENDERER=true yarn build",
"analyze:main": "VISUALIZER_MAIN=true yarn build",
"typecheck": "concurrently -n \"node,web\" -c \"cyan,magenta\" \"npm run typecheck:node\" \"npm run typecheck:web\"",
"typecheck": "concurrently -n \"node,web,ui\" -c \"cyan,magenta,green\" \"npm run typecheck:node\" \"npm run typecheck:web\" \"npm run typecheck:ui\"",
"typecheck:node": "tsgo --noEmit -p tsconfig.node.json --composite false",
"typecheck:web": "tsgo --noEmit -p tsconfig.web.json --composite false",
"typecheck:ui": "cd packages/ui && npm run type-check",
"check:i18n": "dotenv -e .env -- tsx scripts/check-i18n.ts",
"sync:i18n": "dotenv -e .env -- tsx scripts/sync-i18n.ts",
"update:i18n": "dotenv -e .env -- tsx scripts/update-i18n.ts",
@@ -68,11 +69,13 @@
"test:e2e": "yarn playwright test",
"test:lint": "oxlint --deny-warnings && eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --cache",
"test:scripts": "vitest scripts",
"lint": "oxlint --fix && eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --cache && yarn typecheck && yarn check:i18n && yarn format:check",
"lint": "oxlint --fix && eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --cache && biome lint --write && biome format --write && yarn typecheck && yarn check:i18n && yarn format:check",
"lint:ox": "oxlint --fix && biome lint --write && biome format --write",
"format": "biome format --write && biome lint --write",
"format:check": "biome format && biome lint",
"prepare": "git config blame.ignoreRevsFile .git-blame-ignore-revs && husky",
"claude": "dotenv -e .env -- claude",
"migrations:generate": "drizzle-kit generate --config ./migrations/sqlite-drizzle.config.ts",
"release:aicore:alpha": "yarn workspace @cherrystudio/ai-core version prerelease --immediate && yarn workspace @cherrystudio/ai-core npm publish --tag alpha --access public",
"release:aicore:beta": "yarn workspace @cherrystudio/ai-core version prerelease --immediate && yarn workspace @cherrystudio/ai-core npm publish --tag beta --access public",
"release:aicore": "yarn workspace @cherrystudio/ai-core version patch --immediate && yarn workspace @cherrystudio/ai-core npm publish --access public"
@@ -124,6 +127,7 @@
"@cherrystudio/embedjs-ollama": "^0.1.31",
"@cherrystudio/embedjs-openai": "^0.1.31",
"@cherrystudio/extension-table-plus": "workspace:^",
"@cherrystudio/ui": "workspace:*",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/modifiers": "^9.0.0",
"@dnd-kit/sortable": "^10.0.0",
@@ -139,7 +143,6 @@
"@google/genai": "patch:@google/genai@npm%3A1.0.1#~/.yarn/patches/@google-genai-npm-1.0.1-e26f0f9af7.patch",
"@hello-pangea/dnd": "^18.0.1",
"@heroui/react": "^2.8.3",
"@kangfenmao/keyv-storage": "^0.1.0",
"@langchain/community": "^0.3.50",
"@mistralai/mistralai": "^1.7.5",
"@modelcontextprotocol/sdk": "^1.17.5",

View File

@@ -2,7 +2,7 @@
* 中间件管理器
* 专注于 AI SDK 中间件的管理,与插件系统分离
*/
import { LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { LanguageModelV2Middleware } from '@ai-sdk/provider'
/**
* 创建中间件列表

View File

@@ -1,7 +1,7 @@
/**
* 中间件系统类型定义
*/
import { LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { LanguageModelV2Middleware } from '@ai-sdk/provider'
/**
* 具名中间件接口

View File

@@ -2,7 +2,7 @@
* 模型包装工具函数
* 用于将中间件应用到LanguageModel上
*/
import { LanguageModelV2, LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { LanguageModelV2, LanguageModelV2Middleware } from '@ai-sdk/provider'
import { wrapLanguageModel } from 'ai'
/**

View File

@@ -5,7 +5,7 @@
* 集成了来自 ModelCreator 的特殊处理逻辑
*/
import { EmbeddingModelV2, ImageModelV2, LanguageModelV2, LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { EmbeddingModelV2, ImageModelV2, LanguageModelV2, LanguageModelV2Middleware } from '@ai-sdk/provider'
import { wrapModelWithMiddlewares } from '../middleware/wrapper'
import { DEFAULT_SEPARATOR, globalRegistryManagement } from '../providers/RegistryManagement'

View File

@@ -1,7 +1,7 @@
/**
* Creation 模块类型定义
*/
import { LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { ProviderId, ProviderSettingsMap } from '../providers/types'

View File

@@ -1,4 +1,4 @@
import { ExtractProviderOptions, ProviderOptionsMap, TypedProviderOptions } from './types'
import type { ExtractProviderOptions, ProviderOptionsMap, TypedProviderOptions } from './types'
/**
* 创建特定供应商的选项

View File

@@ -10,7 +10,7 @@ import type { AiRequestContext } from '../../types'
import { StreamEventManager } from './StreamEventManager'
import { type TagConfig, TagExtractor } from './tagExtraction'
import { ToolExecutor } from './ToolExecutor'
import { PromptToolUseConfig, ToolUseResult } from './type'
import type { PromptToolUseConfig, ToolUseResult } from './type'
/**
* 工具使用标签配置

View File

@@ -1,6 +1,6 @@
import { ToolSet } from 'ai'
import type { ToolSet } from 'ai'
import { AiRequestContext } from '../..'
import type { AiRequestContext } from '../..'
/**
* 解析结果类型

View File

@@ -1,10 +1,10 @@
import { anthropic } from '@ai-sdk/anthropic'
import { google } from '@ai-sdk/google'
import { openai } from '@ai-sdk/openai'
import { InferToolInput, InferToolOutput, type Tool } from 'ai'
import type { anthropic } from '@ai-sdk/anthropic'
import type { google } from '@ai-sdk/google'
import type { openai } from '@ai-sdk/openai'
import type { InferToolInput, InferToolOutput, Tool } from 'ai'
import { ProviderOptionsMap } from '../../../options/types'
import { OpenRouterSearchConfig } from './openrouter'
import type { ProviderOptionsMap } from '../../../options/types'
import type { OpenRouterSearchConfig } from './openrouter'
/**
* 从 AI SDK 的工具函数中提取参数类型,以确保类型安全。

View File

@@ -9,7 +9,8 @@ import { openai } from '@ai-sdk/openai'
import { createOpenRouterOptions, createXaiOptions, mergeProviderOptions } from '../../../options'
import { definePlugin } from '../../'
import type { AiRequestContext } from '../../types'
import { DEFAULT_WEB_SEARCH_CONFIG, WebSearchPluginConfig } from './helper'
import type { WebSearchPluginConfig } from './helper'
import { DEFAULT_WEB_SEARCH_CONFIG } from './helper'
/**
* 网络搜索插件

View File

@@ -1,4 +1,4 @@
import { AiPlugin, AiRequestContext } from './types'
import type { AiPlugin, AiRequestContext } from './types'
/**
* 插件管理器

View File

@@ -5,7 +5,7 @@
* 例如: aihubmix:anthropic:claude-3.5-sonnet
*/
import { ProviderV2 } from '@ai-sdk/provider'
import type { ProviderV2 } from '@ai-sdk/provider'
import { customProvider } from 'ai'
import { globalRegistryManagement } from './RegistryManagement'

View File

@@ -4,7 +4,7 @@
* 基于 AI SDK 原生的 createProviderRegistry
*/
import { EmbeddingModelV2, ImageModelV2, LanguageModelV2, ProviderV2 } from '@ai-sdk/provider'
import type { EmbeddingModelV2, ImageModelV2, LanguageModelV2, ProviderV2 } from '@ai-sdk/provider'
import { createProviderRegistry, type ProviderRegistryProvider } from 'ai'
type PROVIDERS = Record<string, ProviderV2>

View File

@@ -9,10 +9,11 @@ import { createDeepSeek } from '@ai-sdk/deepseek'
import { createGoogleGenerativeAI } from '@ai-sdk/google'
import { createOpenAI, type OpenAIProviderSettings } from '@ai-sdk/openai'
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { LanguageModelV2 } from '@ai-sdk/provider'
import type { LanguageModelV2 } from '@ai-sdk/provider'
import { createXai } from '@ai-sdk/xai'
import { createOpenRouter } from '@openrouter/ai-sdk-provider'
import { customProvider, Provider } from 'ai'
import type { Provider } from 'ai'
import { customProvider } from 'ai'
import * as z from 'zod'
/**

View File

@@ -4,7 +4,7 @@ import { type DeepSeekProviderSettings } from '@ai-sdk/deepseek'
import { type GoogleGenerativeAIProviderSettings } from '@ai-sdk/google'
import { type OpenAIProviderSettings } from '@ai-sdk/openai'
import { type OpenAICompatibleProviderSettings } from '@ai-sdk/openai-compatible'
import {
import type {
EmbeddingModelV2 as EmbeddingModel,
ImageModelV2 as ImageModel,
LanguageModelV2 as LanguageModel,

View File

@@ -1,4 +1,4 @@
import { ImageModelV2 } from '@ai-sdk/provider'
import type { ImageModelV2 } from '@ai-sdk/provider'
import { experimental_generateImage as aiGenerateImage, NoImageGeneratedError } from 'ai'
import { beforeEach, describe, expect, it, vi } from 'vitest'

View File

@@ -2,12 +2,12 @@
* 运行时执行器
* 专注于插件化的AI调用处理
*/
import { ImageModelV2, LanguageModelV2, LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { ImageModelV2, LanguageModelV2, LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { LanguageModel } from 'ai'
import {
experimental_generateImage as _generateImage,
generateObject as _generateObject,
generateText as _generateText,
LanguageModel,
streamObject as _streamObject,
streamText as _streamText
} from 'ai'

View File

@@ -11,7 +11,7 @@ export type { RuntimeConfig } from './types'
// === 便捷工厂函数 ===
import { LanguageModelV2Middleware } from '@ai-sdk/provider'
import type { LanguageModelV2Middleware } from '@ai-sdk/provider'
import { type AiPlugin } from '../plugins'
import { type ProviderId, type ProviderSettingsMap } from '../providers/types'

View File

@@ -1,6 +1,13 @@
/* eslint-disable @eslint-react/naming-convention/context-name */
import { ImageModelV2 } from '@ai-sdk/provider'
import { experimental_generateImage, generateObject, generateText, LanguageModel, streamObject, streamText } from 'ai'
import type { ImageModelV2 } from '@ai-sdk/provider'
import type {
experimental_generateImage,
generateObject,
generateText,
LanguageModel,
streamObject,
streamText
} from 'ai'
import { type AiPlugin, createContext, PluginManager } from '../plugins'
import { type ProviderId } from '../providers/types'

View File

@@ -1,8 +1,8 @@
/**
* Runtime 层类型定义
*/
import { ImageModelV2 } from '@ai-sdk/provider'
import { experimental_generateImage, generateObject, generateText, streamObject, streamText } from 'ai'
import type { ImageModelV2 } from '@ai-sdk/provider'
import type { experimental_generateImage, generateObject, generateText, streamObject, streamText } from 'ai'
import { type ModelConfig } from '../models/types'
import { type AiPlugin } from '../plugins'

View File

@@ -1,4 +1,5 @@
import { Extension, Node } from '@tiptap/core'
import type { Node } from '@tiptap/core'
import { Extension } from '@tiptap/core'
import type { TableCellOptions } from '../cell/index.js'
import { TableCell } from '../cell/index.js'

View File

@@ -1,7 +1,7 @@
import { SpanKind, SpanStatusCode } from '@opentelemetry/api'
import { ReadableSpan } from '@opentelemetry/sdk-trace-base'
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'
import { SpanEntity } from '../types/config'
import type { SpanEntity } from '../types/config'
/**
* convert ReadableSpan to SpanEntity

View File

@@ -1,4 +1,4 @@
import { ReadableSpan } from '@opentelemetry/sdk-trace-base'
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'
export interface TraceCache {
createSpan: (span: ReadableSpan) => void

View File

@@ -1,5 +1,6 @@
import { ExportResult, ExportResultCode } from '@opentelemetry/core'
import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'
import type { ExportResult } from '@opentelemetry/core'
import { ExportResultCode } from '@opentelemetry/core'
import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'
export type SaveFunction = (spans: ReadableSpan[]) => Promise<void>

View File

@@ -1,7 +1,9 @@
import { Context, trace } from '@opentelemetry/api'
import { BatchSpanProcessor, BufferConfig, ReadableSpan, Span, SpanExporter } from '@opentelemetry/sdk-trace-base'
import type { Context } from '@opentelemetry/api'
import { trace } from '@opentelemetry/api'
import type { BufferConfig, ReadableSpan, Span, SpanExporter } from '@opentelemetry/sdk-trace-base'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'
import { TraceCache } from '../core/traceCache'
import type { TraceCache } from '../core/traceCache'
export class CacheBatchSpanProcessor extends BatchSpanProcessor {
private cache: TraceCache

View File

@@ -1,6 +1,7 @@
import { Context } from '@opentelemetry/api'
import { BatchSpanProcessor, BufferConfig, ReadableSpan, Span, SpanExporter } from '@opentelemetry/sdk-trace-base'
import { EventEmitter } from 'stream'
import type { Context } from '@opentelemetry/api'
import type { BufferConfig, ReadableSpan, Span, SpanExporter } from '@opentelemetry/sdk-trace-base'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'
import type { EventEmitter } from 'stream'
import { convertSpanToSpanEntity } from '../core/spanConvert'

View File

@@ -1,5 +1,7 @@
import { Context, trace } from '@opentelemetry/api'
import { BatchSpanProcessor, BufferConfig, ReadableSpan, Span, SpanExporter } from '@opentelemetry/sdk-trace-base'
import type { Context } from '@opentelemetry/api'
import { trace } from '@opentelemetry/api'
import type { BufferConfig, ReadableSpan, Span, SpanExporter } from '@opentelemetry/sdk-trace-base'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'
export type SpanFunction = (span: ReadableSpan) => void

View File

@@ -1,5 +1,5 @@
import { Link } from '@opentelemetry/api'
import { TimedEvent } from '@opentelemetry/sdk-trace-base'
import type { Link } from '@opentelemetry/api'
import type { TimedEvent } from '@opentelemetry/sdk-trace-base'
export type AttributeValue =
| string

View File

@@ -1,11 +1,14 @@
import { trace, Tracer } from '@opentelemetry/api'
import type { Tracer } from '@opentelemetry/api'
import { trace } from '@opentelemetry/api'
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks'
import { W3CTraceContextPropagator } from '@opentelemetry/core'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import { BatchSpanProcessor, ConsoleSpanExporter, SpanProcessor } from '@opentelemetry/sdk-trace-base'
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base'
import { BatchSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base'
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'
import { defaultConfig, TraceConfig } from '../trace-core/types/config'
import type { TraceConfig } from '../trace-core/types/config'
import { defaultConfig } from '../trace-core/types/config'
export class NodeTracer {
private static provider: NodeTracerProvider

View File

@@ -1,4 +1,5 @@
import { Context, ContextManager, ROOT_CONTEXT } from '@opentelemetry/api'
import type { Context, ContextManager } from '@opentelemetry/api'
import { ROOT_CONTEXT } from '@opentelemetry/api'
export class TopicContextManager implements ContextManager {
private topicContextStack: Map<string, Context[]>

View File

@@ -1,4 +1,5 @@
import { Context, context } from '@opentelemetry/api'
import type { Context } from '@opentelemetry/api'
import { context } from '@opentelemetry/api'
const originalPromise = globalThis.Promise

View File

@@ -1,9 +1,11 @@
import { W3CTraceContextPropagator } from '@opentelemetry/core'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import { BatchSpanProcessor, ConsoleSpanExporter, SpanProcessor } from '@opentelemetry/sdk-trace-base'
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base'
import { BatchSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base'
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'
import { defaultConfig, TraceConfig } from '../trace-core/types/config'
import type { TraceConfig } from '../trace-core/types/config'
import { defaultConfig } from '../trace-core/types/config'
import { TopicContextManager } from './TopicContextManager'
export const contextManager = new TopicContextManager()

View File

@@ -2,7 +2,7 @@ export enum IpcChannel {
App_GetCacheSize = 'app:get-cache-size',
App_ClearCache = 'app:clear-cache',
App_SetLaunchOnBoot = 'app:set-launch-on-boot',
App_SetLanguage = 'app:set-language',
// App_SetLanguage = 'app:set-language',
App_SetEnableSpellCheck = 'app:set-enable-spell-check',
App_SetSpellCheckLanguages = 'app:set-spell-check-languages',
App_CheckForUpdate = 'app:check-for-update',
@@ -14,7 +14,7 @@ export enum IpcChannel {
App_SetLaunchToTray = 'app:set-launch-to-tray',
App_SetTray = 'app:set-tray',
App_SetTrayOnClose = 'app:set-tray-on-close',
App_SetTheme = 'app:set-theme',
// App_SetTheme = 'app:set-theme',
App_SetAutoUpdate = 'app:set-auto-update',
App_SetTestPlan = 'app:set-test-plan',
App_SetTestChannel = 'app:set-test-channel',
@@ -46,7 +46,7 @@ export enum IpcChannel {
App_MacRequestProcessTrust = 'app:mac-request-process-trust',
App_QuoteToMain = 'app:quote-to-main',
App_SetDisableHardwareAcceleration = 'app:set-disable-hardware-acceleration',
// App_SetDisableHardwareAcceleration = 'app:set-disable-hardware-acceleration',
Notification_Send = 'notification:send',
Notification_OnClick = 'notification:on-click',
@@ -220,6 +220,22 @@ export enum IpcChannel {
Backup_DeleteS3File = 'backup:deleteS3File',
Backup_CheckS3Connection = 'backup:checkS3Connection',
// data migration
DataMigrate_CheckNeeded = 'data-migrate:check-needed',
DataMigrate_GetProgress = 'data-migrate:get-progress',
DataMigrate_Cancel = 'data-migrate:cancel',
DataMigrate_RequireBackup = 'data-migrate:require-backup',
DataMigrate_BackupCompleted = 'data-migrate:backup-completed',
DataMigrate_ShowBackupDialog = 'data-migrate:show-backup-dialog',
DataMigrate_StartFlow = 'data-migrate:start-flow',
DataMigrate_ProceedToBackup = 'data-migrate:proceed-to-backup',
DataMigrate_StartMigration = 'data-migrate:start-migration',
DataMigrate_RetryMigration = 'data-migrate:retry-migration',
DataMigrate_RestartApp = 'data-migrate:restart-app',
DataMigrate_CloseWindow = 'data-migrate:close-window',
DataMigrate_SendReduxData = 'data-migrate:send-redux-data',
DataMigrate_GetReduxData = 'data-migrate:get-redux-data',
// zip
Zip_Compress = 'zip:compress',
Zip_Decompress = 'zip:decompress',
@@ -234,7 +250,8 @@ export enum IpcChannel {
// events
BackupProgress = 'backup-progress',
ThemeUpdated = 'theme:updated',
DataMigrateProgress = 'data-migrate-progress',
NativeThemeUpdated = 'native-theme:updated',
RestoreProgress = 'restore-progress',
UpdateError = 'update-error',
UpdateAvailable = 'update-available',
@@ -273,12 +290,6 @@ export enum IpcChannel {
Selection_ToolbarVisibilityChange = 'selection:toolbar-visibility-change',
Selection_ToolbarDetermineSize = 'selection:toolbar-determine-size',
Selection_WriteToClipboard = 'selection:write-to-clipboard',
Selection_SetEnabled = 'selection:set-enabled',
Selection_SetTriggerMode = 'selection:set-trigger-mode',
Selection_SetFilterMode = 'selection:set-filter-mode',
Selection_SetFilterList = 'selection:set-filter-list',
Selection_SetFollowToolbar = 'selection:set-follow-toolbar',
Selection_SetRemeberWinSize = 'selection:set-remeber-win-size',
Selection_ActionWindowClose = 'selection:action-window-close',
Selection_ActionWindowMinimize = 'selection:action-window-minimize',
Selection_ActionWindowPin = 'selection:action-window-pin',
@@ -297,6 +308,27 @@ export enum IpcChannel {
Memory_DeleteAllMemoriesForUser = 'memory:delete-all-memories-for-user',
Memory_GetUsersList = 'memory:get-users-list',
// Data: Preference
Preference_Get = 'preference:get',
Preference_Set = 'preference:set',
Preference_GetMultiple = 'preference:get-multiple',
Preference_SetMultiple = 'preference:set-multiple',
Preference_GetAll = 'preference:get-all',
Preference_Subscribe = 'preference:subscribe',
Preference_Changed = 'preference:changed',
// Data: Cache
Cache_Sync = 'cache:sync',
Cache_SyncBatch = 'cache:sync-batch',
// Data: API Channels
DataApi_Request = 'data-api:request',
DataApi_Batch = 'data-api:batch',
DataApi_Transaction = 'data-api:transaction',
DataApi_Subscribe = 'data-api:subscribe',
DataApi_Unsubscribe = 'data-api:unsubscribe',
DataApi_Stream = 'data-api:stream',
// TRACE
TRACE_SAVE_DATA = 'trace:saveData',
TRACE_GET_DATA = 'trace:getData',

View File

@@ -9,9 +9,9 @@
*/
import Anthropic from '@anthropic-ai/sdk'
import { TextBlockParam } from '@anthropic-ai/sdk/resources'
import type { TextBlockParam } from '@anthropic-ai/sdk/resources'
import { loggerService } from '@logger'
import { Provider } from '@types'
import type { Provider } from '@types'
import type { ModelMessage } from 'ai'
const logger = loggerService.withContext('anthropic-sdk')

View File

@@ -197,11 +197,11 @@ export enum FeedUrl {
GITHUB_LATEST = 'https://github.com/CherryHQ/cherry-studio/releases/latest/download'
}
export enum UpgradeChannel {
LATEST = 'latest', // 最新稳定版本
RC = 'rc', // 公测版本
BETA = 'beta' // 预览版本
}
// export enum UpgradeChannel {
// LATEST = 'latest', // 最新稳定版本
// RC = 'rc', // 公测版本
// BETA = 'beta' // 预览版本
// }
export const defaultTimeout = 10 * 1000 * 60

View File

@@ -1,4 +1,4 @@
import { ProcessingStatus } from '@types'
import type { ProcessingStatus } from '@types'
export type LoaderReturn = {
entriesAdded: number

View File

@@ -0,0 +1,106 @@
# Cherry Studio Shared Data
This directory contains shared type definitions and schemas for the Cherry Studio data management systems. These files provide type safety and consistency across the entire application.
## 📁 Directory Structure
```
packages/shared/data/
├── api/ # Data API type system
│ ├── index.ts # Barrel exports for clean imports
│ ├── apiSchemas.ts # API endpoint definitions and mappings
│ ├── apiTypes.ts # Core request/response infrastructure types
│ ├── apiModels.ts # Business entity types and DTOs
│ ├── apiPaths.ts # API path definitions and utilities
│ └── errorCodes.ts # Standardized error handling
├── cache/ # Cache system type definitions
│ ├── cacheTypes.ts # Core cache infrastructure types
│ ├── cacheSchemas.ts # Cache key schemas and type mappings
│ └── cacheValueTypes.ts # Cache value type definitions
├── preference/ # Preference system type definitions
│ ├── preferenceTypes.ts # Core preference system types
│ └── preferenceSchemas.ts # Preference schemas and default values
└── README.md # This file
```
## 🏗️ System Overview
This directory provides type definitions for three main data management systems:
### API System (`api/`)
- **Purpose**: Type-safe IPC communication between Main and Renderer processes
- **Features**: RESTful patterns, error handling, business entity definitions
- **Usage**: Ensures type safety for all data API operations
### Cache System (`cache/`)
- **Purpose**: Type definitions for three-layer caching architecture
- **Features**: Memory/shared/persist cache schemas, TTL support, hook integration
- **Usage**: Type-safe caching operations across the application
### Preference System (`preference/`)
- **Purpose**: User configuration and settings management
- **Features**: 158 configuration items, default values, nested key support
- **Usage**: Type-safe preference access and synchronization
## 📋 File Categories
**Framework Infrastructure** - These are TypeScript type definitions that:
- ✅ Exist only at compile time
- ✅ Provide type safety and IntelliSense support
- ✅ Define contracts between application layers
- ✅ Enable static analysis and error detection
## 📖 Usage Examples
### API Types
```typescript
// Import API types
import type { DataRequest, DataResponse, ApiSchemas } from '@shared/data/api'
```
### Cache Types
```typescript
// Import cache types
import type { UseCacheKey, UseSharedCacheKey } from '@shared/data/cache'
```
### Preference Types
```typescript
// Import preference types
import type { PreferenceKeyType, PreferenceDefaultScopeType } from '@shared/data/preference'
```
## 🔧 Development Guidelines
### Adding Cache Types
1. Add cache key to `cache/cacheSchemas.ts`
2. Define value type in `cache/cacheValueTypes.ts`
3. Update type mappings for type safety
### Adding Preference Types
1. Add preference key to `preference/preferenceSchemas.ts`
2. Define default value and type
3. Preference system automatically picks up new keys
### Adding API Types
1. Define business entities in `api/apiModels.ts`
2. Add endpoint definitions to `api/apiSchemas.ts`
3. Export types from `api/index.ts`
### Best Practices
- Use `import type` for type-only imports
- Follow existing naming conventions
- Document complex types with JSDoc
- Maintain type safety across all imports
## 🔗 Related Implementation
### Main Process Services
- `src/main/data/CacheService.ts` - Main process cache management
- `src/main/data/PreferenceService.ts` - Preference management service
- `src/main/data/DataApiService.ts` - Data API coordination service
### Renderer Process Services
- `src/renderer/src/data/CacheService.ts` - Renderer cache service
- `src/renderer/src/data/PreferenceService.ts` - Renderer preference service
- `src/renderer/src/data/DataApiService.ts` - Renderer API client

View File

@@ -0,0 +1,107 @@
/**
* Generic test model definitions
* Contains flexible types for comprehensive API testing
*/
/**
* Generic test item entity - flexible structure for testing various scenarios
*/
export interface TestItem {
/** Unique identifier */
id: string
/** Item title */
title: string
/** Optional description */
description?: string
/** Type category */
type: string
/** Current status */
status: string
/** Priority level */
priority: string
/** Associated tags */
tags: string[]
/** Creation timestamp */
createdAt: string
/** Last update timestamp */
updatedAt: string
/** Additional metadata */
metadata: Record<string, any>
}
/**
* Data Transfer Objects (DTOs) for test operations
*/
/**
* DTO for creating a new test item
*/
export interface CreateTestItemDto {
/** Item title */
title: string
/** Optional description */
description?: string
/** Type category */
type?: string
/** Current status */
status?: string
/** Priority level */
priority?: string
/** Associated tags */
tags?: string[]
/** Additional metadata */
metadata?: Record<string, any>
}
/**
* DTO for updating an existing test item
*/
export interface UpdateTestItemDto {
/** Updated title */
title?: string
/** Updated description */
description?: string
/** Updated type */
type?: string
/** Updated status */
status?: string
/** Updated priority */
priority?: string
/** Updated tags */
tags?: string[]
/** Updated metadata */
metadata?: Record<string, any>
}
/**
* Bulk operation types for batch processing
*/
/**
* Request for bulk operations on multiple items
*/
export interface BulkOperationRequest<TData = any> {
/** Type of bulk operation to perform */
operation: 'create' | 'update' | 'delete' | 'archive' | 'restore'
/** Array of data items to process */
data: TData[]
}
/**
* Response from a bulk operation
*/
export interface BulkOperationResponse {
/** Number of successfully processed items */
successful: number
/** Number of items that failed processing */
failed: number
/** Array of errors that occurred during processing */
errors: Array<{
/** Index of the item that failed */
index: number
/** Error message */
error: string
/** Optional additional error data */
data?: any
}>
}

View File

@@ -0,0 +1,60 @@
import type { ApiSchemas } from './apiSchemas'
/**
* Template literal type utilities for converting parameterized paths to concrete paths
* This enables type-safe API calls with actual paths like '/test/items/123' instead of '/test/items/:id'
*/
/**
* Convert parameterized path templates to concrete path types
* @example '/test/items/:id' -> '/test/items/${string}'
* @example '/topics/:id/messages' -> '/topics/${string}/messages'
*/
export type ResolvedPath<T extends string> = T extends `${infer Prefix}/:${string}/${infer Suffix}`
? `${Prefix}/${string}/${ResolvedPath<Suffix>}`
: T extends `${infer Prefix}/:${string}`
? `${Prefix}/${string}`
: T
/**
* Generate all possible concrete paths from ApiSchemas
* This creates a union type of all valid API paths
*/
export type ConcreteApiPaths = {
[K in keyof ApiSchemas]: ResolvedPath<K & string>
}[keyof ApiSchemas]
/**
* Reverse lookup: from concrete path back to original template path
* Used to determine which ApiSchema entry matches a concrete path
*/
export type MatchApiPath<Path extends string> = {
[K in keyof ApiSchemas]: Path extends ResolvedPath<K & string> ? K : never
}[keyof ApiSchemas]
/**
* Extract query parameters type for a given concrete path
*/
export type QueryParamsForPath<Path extends string> = MatchApiPath<Path> extends keyof ApiSchemas
? ApiSchemas[MatchApiPath<Path>] extends { GET: { query?: infer Q } }
? Q
: Record<string, any>
: Record<string, any>
/**
* Extract request body type for a given concrete path and HTTP method
*/
export type BodyForPath<Path extends string, Method extends string> = MatchApiPath<Path> extends keyof ApiSchemas
? ApiSchemas[MatchApiPath<Path>] extends { [M in Method]: { body: infer B } }
? B
: any
: any
/**
* Extract response type for a given concrete path and HTTP method
*/
export type ResponseForPath<Path extends string, Method extends string> = MatchApiPath<Path> extends keyof ApiSchemas
? ApiSchemas[MatchApiPath<Path>] extends { [M in Method]: { response: infer R } }
? R
: any
: any

View File

@@ -0,0 +1,487 @@
// NOTE: Types are defined inline in the schema for simplicity
// If needed, specific types can be imported from './apiModels'
import type { BodyForPath, ConcreteApiPaths, QueryParamsForPath, ResponseForPath } from './apiPaths'
import type { HttpMethod, PaginatedResponse, PaginationParams } from './apiTypes'
// Re-export for external use
export type { ConcreteApiPaths } from './apiPaths'
/**
* Complete API Schema definitions for Test API
*
* Each path defines the supported HTTP methods with their:
* - Request parameters (params, query, body)
* - Response types
* - Type safety guarantees
*
* This schema serves as the contract between renderer and main processes,
* enabling full TypeScript type checking across IPC boundaries.
*/
export interface ApiSchemas {
/**
* Test items collection endpoint
* @example GET /test/items?page=1&limit=10&search=hello
* @example POST /test/items { "title": "New Test Item" }
*/
'/test/items': {
/** List all test items with optional filtering and pagination */
GET: {
query?: PaginationParams & {
/** Search items by title or description */
search?: string
/** Filter by item type */
type?: string
/** Filter by status */
status?: string
}
response: PaginatedResponse<any>
}
/** Create a new test item */
POST: {
body: {
title: string
description?: string
type?: string
status?: string
priority?: string
tags?: string[]
metadata?: Record<string, any>
}
response: any
}
}
/**
* Individual test item endpoint
* @example GET /test/items/123
* @example PUT /test/items/123 { "title": "Updated Title" }
* @example DELETE /test/items/123
*/
'/test/items/:id': {
/** Get a specific test item by ID */
GET: {
params: { id: string }
response: any
}
/** Update a specific test item */
PUT: {
params: { id: string }
body: {
title?: string
description?: string
type?: string
status?: string
priority?: string
tags?: string[]
metadata?: Record<string, any>
}
response: any
}
/** Delete a specific test item */
DELETE: {
params: { id: string }
response: void
}
}
/**
* Test search endpoint
* @example GET /test/search?query=hello&page=1&limit=20
*/
'/test/search': {
/** Search test items */
GET: {
query: {
/** Search query string */
query: string
/** Page number for pagination */
page?: number
/** Number of results per page */
limit?: number
/** Additional filters */
type?: string
status?: string
}
response: PaginatedResponse<any>
}
}
/**
* Test statistics endpoint
* @example GET /test/stats
*/
'/test/stats': {
/** Get comprehensive test statistics */
GET: {
response: {
/** Total number of items */
total: number
/** Item count grouped by type */
byType: Record<string, number>
/** Item count grouped by status */
byStatus: Record<string, number>
/** Item count grouped by priority */
byPriority: Record<string, number>
/** Recent activity timeline */
recentActivity: Array<{
/** Date of activity */
date: string
/** Number of items on that date */
count: number
}>
}
}
}
/**
* Test bulk operations endpoint
* @example POST /test/bulk { "operation": "create", "data": [...] }
*/
'/test/bulk': {
/** Perform bulk operations on test items */
POST: {
body: {
/** Operation type */
operation: 'create' | 'update' | 'delete'
/** Array of data items to process */
data: any[]
}
response: {
successful: number
failed: number
errors: string[]
}
}
}
/**
* Test error simulation endpoint
* @example POST /test/error { "errorType": "timeout" }
*/
'/test/error': {
/** Simulate various error scenarios for testing */
POST: {
body: {
/** Type of error to simulate */
errorType:
| 'timeout'
| 'network'
| 'server'
| 'notfound'
| 'validation'
| 'unauthorized'
| 'ratelimit'
| 'generic'
}
response: never
}
}
/**
* Test slow response endpoint
* @example POST /test/slow { "delay": 2000 }
*/
'/test/slow': {
/** Test slow response for performance testing */
POST: {
body: {
/** Delay in milliseconds */
delay: number
}
response: {
message: string
delay: number
timestamp: string
}
}
}
/**
* Test data reset endpoint
* @example POST /test/reset
*/
'/test/reset': {
/** Reset all test data to initial state */
POST: {
response: {
message: string
timestamp: string
}
}
}
/**
* Test config endpoint
* @example GET /test/config
* @example PUT /test/config { "setting": "value" }
*/
'/test/config': {
/** Get test configuration */
GET: {
response: Record<string, any>
}
/** Update test configuration */
PUT: {
body: Record<string, any>
response: Record<string, any>
}
}
/**
* Test status endpoint
* @example GET /test/status
*/
'/test/status': {
/** Get system test status */
GET: {
response: {
status: string
timestamp: string
version: string
uptime: number
environment: string
}
}
}
/**
* Test performance endpoint
* @example GET /test/performance
*/
'/test/performance': {
/** Get performance metrics */
GET: {
response: {
requestsPerSecond: number
averageLatency: number
memoryUsage: number
cpuUsage: number
uptime: number
}
}
}
/**
* Batch execution of multiple requests
* @example POST /batch { "requests": [...], "parallel": true }
*/
'/batch': {
/** Execute multiple API requests in a single call */
POST: {
body: {
/** Array of requests to execute */
requests: Array<{
/** HTTP method for the request */
method: HttpMethod
/** API path for the request */
path: string
/** URL parameters */
params?: any
/** Request body */
body?: any
}>
/** Execute requests in parallel vs sequential */
parallel?: boolean
}
response: {
/** Results array matching input order */
results: Array<{
/** HTTP status code */
status: number
/** Response data if successful */
data?: any
/** Error information if failed */
error?: any
}>
/** Batch execution metadata */
metadata: {
/** Total execution duration in ms */
duration: number
/** Number of successful requests */
successCount: number
/** Number of failed requests */
errorCount: number
}
}
}
}
/**
* Atomic transaction of multiple operations
* @example POST /transaction { "operations": [...], "options": { "rollbackOnError": true } }
*/
'/transaction': {
/** Execute multiple operations in a database transaction */
POST: {
body: {
/** Array of operations to execute atomically */
operations: Array<{
/** HTTP method for the operation */
method: HttpMethod
/** API path for the operation */
path: string
/** URL parameters */
params?: any
/** Request body */
body?: any
}>
/** Transaction configuration options */
options?: {
/** Database isolation level */
isolation?: 'read-uncommitted' | 'read-committed' | 'repeatable-read' | 'serializable'
/** Rollback all operations on any error */
rollbackOnError?: boolean
/** Transaction timeout in milliseconds */
timeout?: number
}
}
response: Array<{
/** HTTP status code */
status: number
/** Response data if successful */
data?: any
/** Error information if failed */
error?: any
}>
}
}
}
/**
* Simplified type extraction helpers
*/
export type ApiPaths = keyof ApiSchemas
export type ApiMethods<TPath extends ApiPaths> = keyof ApiSchemas[TPath] & HttpMethod
export type ApiResponse<TPath extends ApiPaths, TMethod extends string> = TPath extends keyof ApiSchemas
? TMethod extends keyof ApiSchemas[TPath]
? ApiSchemas[TPath][TMethod] extends { response: infer R }
? R
: never
: never
: never
export type ApiParams<TPath extends ApiPaths, TMethod extends string> = TPath extends keyof ApiSchemas
? TMethod extends keyof ApiSchemas[TPath]
? ApiSchemas[TPath][TMethod] extends { params: infer P }
? P
: never
: never
: never
export type ApiQuery<TPath extends ApiPaths, TMethod extends string> = TPath extends keyof ApiSchemas
? TMethod extends keyof ApiSchemas[TPath]
? ApiSchemas[TPath][TMethod] extends { query: infer Q }
? Q
: never
: never
: never
export type ApiBody<TPath extends ApiPaths, TMethod extends string> = TPath extends keyof ApiSchemas
? TMethod extends keyof ApiSchemas[TPath]
? ApiSchemas[TPath][TMethod] extends { body: infer B }
? B
: never
: never
: never
/**
* Type-safe API client interface using concrete paths
* Accepts actual paths like '/test/items/123' instead of '/test/items/:id'
* Automatically infers query, body, and response types from ApiSchemas
*/
export interface ApiClient {
get<TPath extends ConcreteApiPaths>(
path: TPath,
options?: {
query?: QueryParamsForPath<TPath>
headers?: Record<string, string>
}
): Promise<ResponseForPath<TPath, 'GET'>>
post<TPath extends ConcreteApiPaths>(
path: TPath,
options: {
body?: BodyForPath<TPath, 'POST'>
query?: Record<string, any>
headers?: Record<string, string>
}
): Promise<ResponseForPath<TPath, 'POST'>>
put<TPath extends ConcreteApiPaths>(
path: TPath,
options: {
body: BodyForPath<TPath, 'PUT'>
query?: Record<string, any>
headers?: Record<string, string>
}
): Promise<ResponseForPath<TPath, 'PUT'>>
delete<TPath extends ConcreteApiPaths>(
path: TPath,
options?: {
query?: Record<string, any>
headers?: Record<string, string>
}
): Promise<ResponseForPath<TPath, 'DELETE'>>
patch<TPath extends ConcreteApiPaths>(
path: TPath,
options: {
body?: BodyForPath<TPath, 'PATCH'>
query?: Record<string, any>
headers?: Record<string, string>
}
): Promise<ResponseForPath<TPath, 'PATCH'>>
}
/**
* Helper types to determine if parameters are required based on schema
*/
type HasRequiredQuery<Path extends ApiPaths, Method extends ApiMethods<Path>> = Path extends keyof ApiSchemas
? Method extends keyof ApiSchemas[Path]
? ApiSchemas[Path][Method] extends { query: any }
? true
: false
: false
: false
type HasRequiredBody<Path extends ApiPaths, Method extends ApiMethods<Path>> = Path extends keyof ApiSchemas
? Method extends keyof ApiSchemas[Path]
? ApiSchemas[Path][Method] extends { body: any }
? true
: false
: false
: false
type HasRequiredParams<Path extends ApiPaths, Method extends ApiMethods<Path>> = Path extends keyof ApiSchemas
? Method extends keyof ApiSchemas[Path]
? ApiSchemas[Path][Method] extends { params: any }
? true
: false
: false
: false
/**
* Handler function for a specific API endpoint
* Provides type-safe parameter extraction based on ApiSchemas
* Parameters are required or optional based on the schema definition
*/
export type ApiHandler<Path extends ApiPaths, Method extends ApiMethods<Path>> = (
params: (HasRequiredParams<Path, Method> extends true
? { params: ApiParams<Path, Method> }
: { params?: ApiParams<Path, Method> }) &
(HasRequiredQuery<Path, Method> extends true
? { query: ApiQuery<Path, Method> }
: { query?: ApiQuery<Path, Method> }) &
(HasRequiredBody<Path, Method> extends true ? { body: ApiBody<Path, Method> } : { body?: ApiBody<Path, Method> })
) => Promise<ApiResponse<Path, Method>>
/**
* Complete API implementation that must match ApiSchemas structure
* TypeScript will error if any endpoint is missing - this ensures exhaustive coverage
*/
export type ApiImplementation = {
[Path in ApiPaths]: {
[Method in ApiMethods<Path>]: ApiHandler<Path, Method>
}
}

View File

@@ -0,0 +1,289 @@
/**
* Core types for the Data API system
* Provides type definitions for request/response handling across renderer-main IPC communication
*/
/**
* Standard HTTP methods supported by the Data API
*/
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
/**
* Request object structure for Data API calls
*/
export interface DataRequest<T = any> {
/** Unique request identifier for tracking and correlation */
id: string
/** HTTP method for the request */
method: HttpMethod
/** API path (e.g., '/topics', '/topics/123') */
path: string
/** URL parameters for the request */
params?: Record<string, any>
/** Request body data */
body?: T
/** Request headers */
headers?: Record<string, string>
/** Additional metadata for request processing */
metadata?: {
/** Request timestamp */
timestamp: number
/** OpenTelemetry span context for tracing */
spanContext?: any
/** Cache options for this specific request */
cache?: CacheOptions
}
}
/**
* Response object structure for Data API calls
*/
export interface DataResponse<T = any> {
/** Request ID that this response corresponds to */
id: string
/** HTTP status code */
status: number
/** Response data if successful */
data?: T
/** Error information if request failed */
error?: DataApiError
/** Response metadata */
metadata?: {
/** Request processing duration in milliseconds */
duration: number
/** Whether response was served from cache */
cached?: boolean
/** Cache TTL if applicable */
cacheTtl?: number
/** Response timestamp */
timestamp: number
}
}
/**
* Standardized error structure for Data API
*/
export interface DataApiError {
/** Error code for programmatic handling */
code: string
/** Human-readable error message */
message: string
/** HTTP status code */
status: number
/** Additional error details */
details?: any
/** Error stack trace (development mode only) */
stack?: string
}
/**
* Standard error codes for Data API
*/
export enum ErrorCode {
// Client errors (4xx)
BAD_REQUEST = 'BAD_REQUEST',
UNAUTHORIZED = 'UNAUTHORIZED',
FORBIDDEN = 'FORBIDDEN',
NOT_FOUND = 'NOT_FOUND',
METHOD_NOT_ALLOWED = 'METHOD_NOT_ALLOWED',
VALIDATION_ERROR = 'VALIDATION_ERROR',
RATE_LIMIT_EXCEEDED = 'RATE_LIMIT_EXCEEDED',
// Server errors (5xx)
INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR',
DATABASE_ERROR = 'DATABASE_ERROR',
SERVICE_UNAVAILABLE = 'SERVICE_UNAVAILABLE',
// Custom application errors
MIGRATION_ERROR = 'MIGRATION_ERROR',
PERMISSION_DENIED = 'PERMISSION_DENIED',
RESOURCE_LOCKED = 'RESOURCE_LOCKED',
CONCURRENT_MODIFICATION = 'CONCURRENT_MODIFICATION'
}
/**
* Cache configuration options
*/
export interface CacheOptions {
/** Cache TTL in seconds */
ttl?: number
/** Return stale data while revalidating in background */
staleWhileRevalidate?: boolean
/** Custom cache key override */
cacheKey?: string
/** Operations that should invalidate this cache entry */
invalidateOn?: string[]
/** Whether to bypass cache entirely */
noCache?: boolean
}
/**
* Transaction request wrapper for atomic operations
*/
export interface TransactionRequest {
/** List of operations to execute in transaction */
operations: DataRequest[]
/** Transaction options */
options?: {
/** Database isolation level */
isolation?: 'read-uncommitted' | 'read-committed' | 'repeatable-read' | 'serializable'
/** Whether to rollback entire transaction on any error */
rollbackOnError?: boolean
/** Transaction timeout in milliseconds */
timeout?: number
}
}
/**
* Batch request for multiple operations
*/
export interface BatchRequest {
/** List of requests to execute */
requests: DataRequest[]
/** Whether to execute requests in parallel */
parallel?: boolean
/** Stop on first error */
stopOnError?: boolean
}
/**
* Batch response containing results for all requests
*/
export interface BatchResponse {
/** Individual response for each request */
results: DataResponse[]
/** Overall batch execution metadata */
metadata: {
/** Total execution time */
duration: number
/** Number of successful operations */
successCount: number
/** Number of failed operations */
errorCount: number
}
}
/**
* Pagination parameters for list operations
*/
export interface PaginationParams {
/** Page number (1-based) */
page?: number
/** Items per page */
limit?: number
/** Cursor for cursor-based pagination */
cursor?: string
/** Sort field and direction */
sort?: {
field: string
order: 'asc' | 'desc'
}
}
/**
* Paginated response wrapper
*/
export interface PaginatedResponse<T> {
/** Items for current page */
items: T[]
/** Total number of items */
total: number
/** Current page number */
page: number
/** Total number of pages */
pageCount: number
/** Whether there are more pages */
hasNext: boolean
/** Whether there are previous pages */
hasPrev: boolean
/** Next cursor for cursor-based pagination */
nextCursor?: string
/** Previous cursor for cursor-based pagination */
prevCursor?: string
}
/**
* Subscription options for real-time data updates
*/
export interface SubscriptionOptions {
/** Path pattern to subscribe to */
path: string
/** Filters to apply to subscription */
filters?: Record<string, any>
/** Whether to receive initial data */
includeInitial?: boolean
/** Custom subscription metadata */
metadata?: Record<string, any>
}
/**
* Subscription callback function
*/
export type SubscriptionCallback<T = any> = (data: T, event: SubscriptionEvent) => void
/**
* Subscription event types
*/
export enum SubscriptionEvent {
CREATED = 'created',
UPDATED = 'updated',
DELETED = 'deleted',
INITIAL = 'initial',
ERROR = 'error'
}
/**
* Middleware interface
*/
export interface Middleware {
/** Middleware name */
name: string
/** Execution priority (lower = earlier) */
priority?: number
/** Middleware execution function */
execute(req: DataRequest, res: DataResponse, next: () => Promise<void>): Promise<void>
}
/**
* Request context passed through middleware chain
*/
export interface RequestContext {
/** Original request */
request: DataRequest
/** Response being built */
response: DataResponse
/** Path that matched this request */
path?: string
/** HTTP method */
method?: HttpMethod
/** Authenticated user (if any) */
user?: any
/** Additional context data */
data: Map<string, any>
}
/**
* Base options for service operations
*/
export interface ServiceOptions {
/** Database transaction to use */
transaction?: any
/** User context for authorization */
user?: any
/** Additional service-specific options */
metadata?: Record<string, any>
}
/**
* Standard service response wrapper
*/
export interface ServiceResult<T = any> {
/** Whether operation was successful */
success: boolean
/** Result data if successful */
data?: T
/** Error information if failed */
error?: DataApiError
/** Additional metadata */
metadata?: Record<string, any>
}

View File

@@ -0,0 +1,194 @@
/**
* Centralized error code definitions for the Data API system
* Provides consistent error handling across renderer and main processes
*/
import type { DataApiError } from './apiTypes'
import { ErrorCode } from './apiTypes'
// Re-export ErrorCode for convenience
export { ErrorCode } from './apiTypes'
/**
* Error code to HTTP status mapping
*/
export const ERROR_STATUS_MAP: Record<ErrorCode, number> = {
// Client errors (4xx)
[ErrorCode.BAD_REQUEST]: 400,
[ErrorCode.UNAUTHORIZED]: 401,
[ErrorCode.FORBIDDEN]: 403,
[ErrorCode.NOT_FOUND]: 404,
[ErrorCode.METHOD_NOT_ALLOWED]: 405,
[ErrorCode.VALIDATION_ERROR]: 422,
[ErrorCode.RATE_LIMIT_EXCEEDED]: 429,
// Server errors (5xx)
[ErrorCode.INTERNAL_SERVER_ERROR]: 500,
[ErrorCode.DATABASE_ERROR]: 500,
[ErrorCode.SERVICE_UNAVAILABLE]: 503,
// Custom application errors (5xx)
[ErrorCode.MIGRATION_ERROR]: 500,
[ErrorCode.PERMISSION_DENIED]: 403,
[ErrorCode.RESOURCE_LOCKED]: 423,
[ErrorCode.CONCURRENT_MODIFICATION]: 409
}
/**
* Default error messages for each error code
*/
export const ERROR_MESSAGES: Record<ErrorCode, string> = {
[ErrorCode.BAD_REQUEST]: 'Bad request: Invalid request format or parameters',
[ErrorCode.UNAUTHORIZED]: 'Unauthorized: Authentication required',
[ErrorCode.FORBIDDEN]: 'Forbidden: Insufficient permissions',
[ErrorCode.NOT_FOUND]: 'Not found: Requested resource does not exist',
[ErrorCode.METHOD_NOT_ALLOWED]: 'Method not allowed: HTTP method not supported for this endpoint',
[ErrorCode.VALIDATION_ERROR]: 'Validation error: Request data does not meet requirements',
[ErrorCode.RATE_LIMIT_EXCEEDED]: 'Rate limit exceeded: Too many requests',
[ErrorCode.INTERNAL_SERVER_ERROR]: 'Internal server error: An unexpected error occurred',
[ErrorCode.DATABASE_ERROR]: 'Database error: Failed to access or modify data',
[ErrorCode.SERVICE_UNAVAILABLE]: 'Service unavailable: The service is temporarily unavailable',
[ErrorCode.MIGRATION_ERROR]: 'Migration error: Failed to migrate data',
[ErrorCode.PERMISSION_DENIED]: 'Permission denied: Operation not allowed for current user',
[ErrorCode.RESOURCE_LOCKED]: 'Resource locked: Resource is currently locked by another operation',
[ErrorCode.CONCURRENT_MODIFICATION]: 'Concurrent modification: Resource was modified by another user'
}
/**
* Utility class for creating standardized Data API errors
*/
export class DataApiErrorFactory {
/**
* Create a DataApiError with standard properties
*/
static create(code: ErrorCode, customMessage?: string, details?: any, stack?: string): DataApiError {
return {
code,
message: customMessage || ERROR_MESSAGES[code],
status: ERROR_STATUS_MAP[code],
details,
stack: stack || undefined
}
}
/**
* Create a validation error with field-specific details
*/
static validation(fieldErrors: Record<string, string[]>, message?: string): DataApiError {
return this.create(ErrorCode.VALIDATION_ERROR, message || 'Request validation failed', { fieldErrors })
}
/**
* Create a not found error for specific resource
*/
static notFound(resource: string, id?: string): DataApiError {
const message = id ? `${resource} with id '${id}' not found` : `${resource} not found`
return this.create(ErrorCode.NOT_FOUND, message, { resource, id })
}
/**
* Create a database error with query details
*/
static database(originalError: Error, operation?: string): DataApiError {
return this.create(
ErrorCode.DATABASE_ERROR,
`Database operation failed${operation ? `: ${operation}` : ''}`,
{
originalError: originalError.message,
operation
},
originalError.stack
)
}
/**
* Create a permission denied error
*/
static permissionDenied(action: string, resource?: string): DataApiError {
const message = resource ? `Permission denied: Cannot ${action} ${resource}` : `Permission denied: Cannot ${action}`
return this.create(ErrorCode.PERMISSION_DENIED, message, { action, resource })
}
/**
* Create an internal server error from an unexpected error
*/
static internal(originalError: Error, context?: string): DataApiError {
const message = context
? `Internal error in ${context}: ${originalError.message}`
: `Internal error: ${originalError.message}`
return this.create(
ErrorCode.INTERNAL_SERVER_ERROR,
message,
{ originalError: originalError.message, context },
originalError.stack
)
}
/**
* Create a rate limit exceeded error
*/
static rateLimit(limit: number, windowMs: number): DataApiError {
return this.create(ErrorCode.RATE_LIMIT_EXCEEDED, `Rate limit exceeded: ${limit} requests per ${windowMs}ms`, {
limit,
windowMs
})
}
/**
* Create a resource locked error
*/
static resourceLocked(resource: string, id: string, lockedBy?: string): DataApiError {
const message = lockedBy
? `${resource} '${id}' is locked by ${lockedBy}`
: `${resource} '${id}' is currently locked`
return this.create(ErrorCode.RESOURCE_LOCKED, message, { resource, id, lockedBy })
}
/**
* Create a concurrent modification error
*/
static concurrentModification(resource: string, id: string): DataApiError {
return this.create(ErrorCode.CONCURRENT_MODIFICATION, `${resource} '${id}' was modified by another user`, {
resource,
id
})
}
}
/**
* Check if an error is a Data API error
*/
export function isDataApiError(error: any): error is DataApiError {
return (
error &&
typeof error === 'object' &&
typeof error.code === 'string' &&
typeof error.message === 'string' &&
typeof error.status === 'number'
)
}
/**
* Convert a generic error to a DataApiError
*/
export function toDataApiError(error: unknown, context?: string): DataApiError {
if (isDataApiError(error)) {
return error
}
if (error instanceof Error) {
return DataApiErrorFactory.internal(error, context)
}
return DataApiErrorFactory.create(
ErrorCode.INTERNAL_SERVER_ERROR,
`Unknown error${context ? ` in ${context}` : ''}: ${String(error)}`,
{ originalError: error, context }
)
}

View File

@@ -0,0 +1,121 @@
/**
* Cherry Studio Data API - Barrel Exports
*
* This file provides a centralized entry point for all data API types,
* schemas, and utilities. Import everything you need from this single location.
*
* @example
* ```typescript
* import { Topic, CreateTopicDto, ApiSchemas, DataRequest, ErrorCode } from '@/shared/data'
* ```
*/
// Core data API types and infrastructure
export type {
BatchRequest,
BatchResponse,
CacheOptions,
DataApiError,
DataRequest,
DataResponse,
HttpMethod,
Middleware,
PaginatedResponse,
PaginationParams,
RequestContext,
ServiceOptions,
ServiceResult,
SubscriptionCallback,
SubscriptionOptions,
TransactionRequest
} from './apiTypes'
export { ErrorCode, SubscriptionEvent } from './apiTypes'
// Domain models and DTOs
export type {
BulkOperationRequest,
BulkOperationResponse,
CreateTestItemDto,
TestItem,
UpdateTestItemDto
} from './apiModels'
// API schema definitions and type helpers
export type {
ApiBody,
ApiClient,
ApiMethods,
ApiParams,
ApiPaths,
ApiQuery,
ApiResponse,
ApiSchemas
} from './apiSchemas'
// Path type utilities for template literal types
export type {
BodyForPath,
ConcreteApiPaths,
MatchApiPath,
QueryParamsForPath,
ResolvedPath,
ResponseForPath
} from './apiPaths'
// Error handling utilities
export {
ErrorCode as DataApiErrorCode,
DataApiErrorFactory,
ERROR_MESSAGES,
ERROR_STATUS_MAP,
isDataApiError,
toDataApiError
} from './errorCodes'
/**
* Re-export commonly used type combinations for convenience
*/
// Import types for re-export convenience types
import type { CreateTestItemDto, TestItem, UpdateTestItemDto } from './apiModels'
import type {
BatchRequest,
BatchResponse,
DataApiError,
DataRequest,
DataResponse,
ErrorCode,
PaginatedResponse,
PaginationParams,
TransactionRequest
} from './apiTypes'
import type { DataApiErrorFactory } from './errorCodes'
/** All test item-related types */
export type TestItemTypes = {
TestItem: TestItem
CreateTestItemDto: CreateTestItemDto
UpdateTestItemDto: UpdateTestItemDto
}
/** All error-related types and utilities */
export type ErrorTypes = {
DataApiError: DataApiError
ErrorCode: ErrorCode
ErrorFactory: typeof DataApiErrorFactory
}
/** All request/response types */
export type RequestTypes = {
DataRequest: DataRequest
DataResponse: DataResponse
BatchRequest: BatchRequest
BatchResponse: BatchResponse
TransactionRequest: TransactionRequest
}
/** All pagination-related types */
export type PaginationTypes = {
PaginationParams: PaginationParams
PaginatedResponse: PaginatedResponse<any>
}

View File

@@ -0,0 +1,168 @@
import type { TranslateLanguageCode } from '@types'
import type * as CacheValueTypes from './cacheValueTypes'
/**
* Use cache schema for renderer hook
*/
export type UseCacheSchema = {
// App state
'app.dist.update_state': CacheValueTypes.CacheAppUpdateState
'app.user.avatar': string
// Chat context
'chat.multi_select_mode': boolean
'chat.selected_message_ids': string[]
'chat.generating': boolean
'chat.websearch.searching': boolean
'chat.websearch.active_searches': CacheValueTypes.CacheActiveSearches
// Minapp management
'minapp.opened_keep_alive': CacheValueTypes.CacheMinAppType[]
'minapp.current_id': string
'minapp.show': boolean
'minapp.opened_oneoff': CacheValueTypes.CacheMinAppType | null
// Topic management
'topic.active': CacheValueTypes.CacheTopic | null
'topic.renaming': string[]
'topic.newly_renamed': string[]
// Translate state
'translate.lang.source': TranslateLanguageCode | 'auto'
'translate.lang.target': TranslateLanguageCode
'translate.input': string
'translate.output': string
'translate.detecting': boolean
'translate.translating': CacheValueTypes.CacheTranslating
'translate.bidirectional': CacheValueTypes.CacheTranslateBidirectional
// Test keys (for dataRefactorTest window)
// TODO: remove after testing
'test-hook-memory-1': string
'test-ttl-cache': string
'test-protected-cache': string
'test-deep-equal': { nested: { count: number }; tags: string[] }
'test-performance': number
'test-multi-hook': string
'concurrent-test-1': number
'concurrent-test-2': number
'large-data-test': Record<string, any>
'test-number-cache': number
'test-object-cache': { name: string; count: number; active: boolean }
}
export const DefaultUseCache: UseCacheSchema = {
// App state
'app.dist.update_state': {
info: null,
checking: false,
downloading: false,
downloaded: false,
downloadProgress: 0,
available: false
},
'app.user.avatar': '',
// Chat context
'chat.multi_select_mode': false,
'chat.selected_message_ids': [],
'chat.generating': false,
'chat.websearch.searching': false,
'chat.websearch.active_searches': {},
// Minapp management
'minapp.opened_keep_alive': [],
'minapp.current_id': '',
'minapp.show': false,
'minapp.opened_oneoff': null,
// Topic management
'topic.active': null,
'topic.renaming': [],
'topic.newly_renamed': [],
// Translate state
'translate.lang.source': 'auto',
'translate.lang.target': 'zh-cn',
'translate.input': '',
'translate.output': '',
'translate.detecting': false,
'translate.translating': { isTranslating: false, abortKey: null },
'translate.bidirectional': {
enabled: false,
origin: 'en-us',
target: 'zh-cn'
},
// Test keys (for dataRefactorTest window)
// TODO: remove after testing
'test-hook-memory-1': 'default-memory-value',
'test-ttl-cache': 'test-ttl-cache',
'test-protected-cache': 'protected-value',
'test-deep-equal': { nested: { count: 0 }, tags: ['initial'] },
'test-performance': 0,
'test-multi-hook': 'hook-1-default',
'concurrent-test-1': 0,
'concurrent-test-2': 0,
'large-data-test': {},
'test-number-cache': 42,
'test-object-cache': { name: 'test', count: 0, active: true }
}
/**
* Use shared cache schema for renderer hook
*/
export type UseSharedCacheSchema = {
'example-key': string
// Test keys (for dataRefactorTest window)
// TODO: remove after testing
'test-hook-shared-1': string
'test-multi-hook': string
'concurrent-shared': number
}
export const DefaultUseSharedCache: UseSharedCacheSchema = {
'example-key': 'example default value',
// Test keys (for dataRefactorTest window)
// TODO: remove after testing
'concurrent-shared': 0,
'test-hook-shared-1': 'default-shared-value',
'test-multi-hook': 'hook-3-shared'
}
/**
* Persist cache schema defining allowed keys and their value types
* This ensures type safety and prevents key conflicts
*/
export type RendererPersistCacheSchema = {
'example-key': string
// Test keys (for dataRefactorTest window)
// TODO: remove after testing
'example-1': string
'example-2': string
'example-3': string
'example-4': string
}
export const DefaultRendererPersistCache: RendererPersistCacheSchema = {
'example-key': 'example default value',
// Test keys (for dataRefactorTest window)
// TODO: remove after testing
'example-1': 'example default value',
'example-2': 'example default value',
'example-3': 'example default value',
'example-4': 'example default value'
}
/**
* Type-safe cache key
*/
export type RendererPersistCacheKey = keyof RendererPersistCacheSchema
export type UseCacheKey = keyof UseCacheSchema
export type UseSharedCacheKey = keyof UseSharedCacheSchema

View File

@@ -0,0 +1,43 @@
/**
* Cache types and interfaces for CacheService
*
* Supports three-layer caching architecture:
* 1. Memory cache (cross-component within renderer)
* 2. Shared cache (cross-window via IPC)
* 3. Persist cache (cross-window with localStorage persistence)
*/
/**
* Cache entry with optional TTL support
*/
export interface CacheEntry<T = any> {
value: T
expireAt?: number // Unix timestamp
}
/**
* Cache synchronization message for IPC communication
*/
export interface CacheSyncMessage {
type: 'shared' | 'persist'
key: string
value: any
ttl?: number
}
/**
* Batch cache synchronization message
*/
export interface CacheSyncBatchMessage {
type: 'shared' | 'persist'
entries: Array<{
key: string
value: any
ttl?: number
}>
}
/**
* Cache subscription callback
*/
export type CacheSubscriber = () => void

View File

@@ -0,0 +1,32 @@
import type { MinAppType, Topic, TranslateLanguageCode, WebSearchStatus } from '@types'
import type { UpdateInfo } from 'builder-util-runtime'
export type CacheAppUpdateState = {
info: UpdateInfo | null
checking: boolean
downloading: boolean
downloaded: boolean
downloadProgress: number
available: boolean
}
export type CacheActiveSearches = Record<string, WebSearchStatus>
// For cache schema, we use any for complex types to avoid circular dependencies
// The actual type checking will be done at runtime by the cache system
export type CacheMinAppType = MinAppType
export type CacheTopic = Topic
export type CacheTranslating =
| {
isTranslating: true
abortKey: string
}
| {
isTranslating: false
abortKey: null
}
export type CacheTranslateBidirectional = {
enabled: boolean
origin: TranslateLanguageCode
target: TranslateLanguageCode
}

View File

@@ -0,0 +1,703 @@
/**
* Auto-generated preferences configuration
* Generated at: 2025-09-16T03:17:03.354Z
*
* This file is automatically generated from classification.json
* To update this file, modify classification.json and run:
* node .claude/data-classify/scripts/generate-preferences.js
*
* === AUTO-GENERATED CONTENT START ===
*/
import { TRANSLATE_PROMPT } from '@shared/config/prompts'
import * as PreferenceTypes from '@shared/data/preference/preferenceTypes'
/* eslint @typescript-eslint/member-ordering: ["error", {
"interfaces": { "order": "alphabetically" },
"typeLiterals": { "order": "alphabetically" }
}] */
export interface PreferenceSchemas {
default: {
// redux/settings/enableDeveloperMode
'app.developer_mode.enabled': boolean
// redux/settings/disableHardwareAcceleration
'app.disable_hardware_acceleration': boolean
// redux/settings/autoCheckUpdate
'app.dist.auto_update.enabled': boolean
// redux/settings/testChannel
'app.dist.test_plan.channel': PreferenceTypes.UpgradeChannel
// redux/settings/testPlan
'app.dist.test_plan.enabled': boolean
// redux/settings/language
'app.language': PreferenceTypes.LanguageVarious | null
// redux/settings/launchOnBoot
'app.launch_on_boot': boolean
// redux/settings/notification.assistant
'app.notification.assistant.enabled': boolean
// redux/settings/notification.backup
'app.notification.backup.enabled': boolean
// redux/settings/notification.knowledge
'app.notification.knowledge.enabled': boolean
// redux/settings/enableDataCollection
'app.privacy.data_collection.enabled': boolean
// redux/settings/proxyBypassRules
'app.proxy.bypass_rules': string
// redux/settings/proxyMode
'app.proxy.mode': PreferenceTypes.ProxyMode
// redux/settings/proxyUrl
'app.proxy.url': string
// redux/settings/enableSpellCheck
'app.spell_check.enabled': boolean
// redux/settings/spellCheckLanguages
'app.spell_check.languages': string[]
// redux/settings/tray
'app.tray.enabled': boolean
// redux/settings/trayOnClose
'app.tray.on_close': boolean
// redux/settings/launchToTray
'app.tray.on_launch': boolean
// redux/settings/userId
'app.user.id': string
// redux/settings/userName
'app.user.name': string
// electronStore/ZoomFactor/ZoomFactor
'app.zoom_factor': number
// redux/settings/clickAssistantToShowTopic
'assistant.click_to_show_topic': boolean
// redux/settings/assistantIconType
'assistant.icon_type': PreferenceTypes.AssistantIconType
// redux/settings/showAssistants
'assistant.tab.show': boolean
// redux/settings/assistantsTabSortType
'assistant.tab.sort_type': PreferenceTypes.AssistantTabSortType
// redux/settings/codeCollapsible
'chat.code.collapsible': boolean
// redux/settings/codeEditor.autocompletion
'chat.code.editor.autocompletion': boolean
// redux/settings/codeEditor.enabled
'chat.code.editor.enabled': boolean
// redux/settings/codeEditor.foldGutter
'chat.code.editor.fold_gutter': boolean
// redux/settings/codeEditor.highlightActiveLine
'chat.code.editor.highlight_active_line': boolean
// redux/settings/codeEditor.keymap
'chat.code.editor.keymap': boolean
// redux/settings/codeEditor.themeDark
'chat.code.editor.theme_dark': string
// redux/settings/codeEditor.themeLight
'chat.code.editor.theme_light': string
// redux/settings/codeExecution.enabled
'chat.code.execution.enabled': boolean
// redux/settings/codeExecution.timeoutMinutes
'chat.code.execution.timeout_minutes': number
// redux/settings/codeFancyBlock
'chat.code.fancy_block': boolean
// redux/settings/codeImageTools
'chat.code.image_tools': boolean
// redux/settings/codePreview.themeDark
'chat.code.preview.theme_dark': string
// redux/settings/codePreview.themeLight
'chat.code.preview.theme_light': string
// redux/settings/codeShowLineNumbers
'chat.code.show_line_numbers': boolean
// redux/settings/codeViewer.themeDark
'chat.code.viewer.theme_dark': string
// redux/settings/codeViewer.themeLight
'chat.code.viewer.theme_light': string
// redux/settings/codeWrappable
'chat.code.wrappable': boolean
// redux/settings/pasteLongTextAsFile
'chat.input.paste_long_text_as_file': boolean
// redux/settings/pasteLongTextThreshold
'chat.input.paste_long_text_threshold': number
// redux/settings/enableQuickPanelTriggers
'chat.input.quick_panel.triggers_enabled': boolean
// redux/settings/sendMessageShortcut
'chat.input.send_message_shortcut': PreferenceTypes.SendMessageShortcut
// redux/settings/showInputEstimatedTokens
'chat.input.show_estimated_tokens': boolean
// redux/settings/autoTranslateWithSpace
'chat.input.translate.auto_translate_with_space': boolean
// redux/settings/showTranslateConfirm
'chat.input.translate.show_confirm': boolean
// redux/settings/confirmDeleteMessage
'chat.message.confirm_delete': boolean
// redux/settings/confirmRegenerateMessage
'chat.message.confirm_regenerate': boolean
// redux/settings/messageFont
'chat.message.font': string
// redux/settings/fontSize
'chat.message.font_size': number
// redux/settings/mathEngine
'chat.message.math.engine': PreferenceTypes.MathEngine
// redux/settings/mathEnableSingleDollar
'chat.message.math.single_dollar': boolean
// redux/settings/foldDisplayMode
'chat.message.multi_model.fold_display_mode': PreferenceTypes.MultiModelFoldDisplayMode
// redux/settings/gridColumns
'chat.message.multi_model.grid_columns': number
// redux/settings/gridPopoverTrigger
'chat.message.multi_model.grid_popover_trigger': PreferenceTypes.MultiModelGridPopoverTrigger
// redux/settings/multiModelMessageStyle
'chat.message.multi_model.style': PreferenceTypes.MultiModelMessageStyle
// redux/settings/messageNavigation
'chat.message.navigation_mode': PreferenceTypes.ChatMessageNavigationMode
// redux/settings/renderInputMessageAsMarkdown
'chat.message.render_as_markdown': boolean
// redux/settings/showMessageDivider
'chat.message.show_divider': boolean
// redux/settings/showMessageOutline
'chat.message.show_outline': boolean
// redux/settings/showPrompt
'chat.message.show_prompt': boolean
// redux/settings/messageStyle
'chat.message.style': PreferenceTypes.ChatMessageStyle
// redux/settings/thoughtAutoCollapse
'chat.message.thought.auto_collapse': boolean
// redux/settings/narrowMode
'chat.narrow_mode': boolean
// redux/settings/skipBackupFile
'data.backup.general.skip_backup_file': boolean
// redux/settings/localBackupAutoSync
'data.backup.local.auto_sync': boolean
// redux/settings/localBackupDir
'data.backup.local.dir': string
// redux/settings/localBackupMaxBackups
'data.backup.local.max_backups': number
// redux/settings/localBackupSkipBackupFile
'data.backup.local.skip_backup_file': boolean
// redux/settings/localBackupSyncInterval
'data.backup.local.sync_interval': number
// redux/nutstore/nutstoreAutoSync
'data.backup.nutstore.auto_sync': boolean
// redux/nutstore/nutstoreMaxBackups
'data.backup.nutstore.max_backups': number
// redux/nutstore/nutstorePath
'data.backup.nutstore.path': string
// redux/nutstore/nutstoreSkipBackupFile
'data.backup.nutstore.skip_backup_file': boolean
// redux/nutstore/nutstoreSyncInterval
'data.backup.nutstore.sync_interval': number
// redux/nutstore/nutstoreToken
'data.backup.nutstore.token': string
// redux/settings/s3.accessKeyId
'data.backup.s3.access_key_id': string
// redux/settings/s3.autoSync
'data.backup.s3.auto_sync': boolean
// redux/settings/s3.bucket
'data.backup.s3.bucket': string
// redux/settings/s3.endpoint
'data.backup.s3.endpoint': string
// redux/settings/s3.maxBackups
'data.backup.s3.max_backups': number
// redux/settings/s3.region
'data.backup.s3.region': string
// redux/settings/s3.root
'data.backup.s3.root': string
// redux/settings/s3.secretAccessKey
'data.backup.s3.secret_access_key': string
// redux/settings/s3.skipBackupFile
'data.backup.s3.skip_backup_file': boolean
// redux/settings/s3.syncInterval
'data.backup.s3.sync_interval': number
// redux/settings/webdavAutoSync
'data.backup.webdav.auto_sync': boolean
// redux/settings/webdavDisableStream
'data.backup.webdav.disable_stream': boolean
// redux/settings/webdavHost
'data.backup.webdav.host': string
// redux/settings/webdavMaxBackups
'data.backup.webdav.max_backups': number
// redux/settings/webdavPass
'data.backup.webdav.pass': string
// redux/settings/webdavPath
'data.backup.webdav.path': string
// redux/settings/webdavSkipBackupFile
'data.backup.webdav.skip_backup_file': boolean
// redux/settings/webdavSyncInterval
'data.backup.webdav.sync_interval': number
// redux/settings/webdavUser
'data.backup.webdav.user': string
// redux/settings/excludeCitationsInExport
'data.export.markdown.exclude_citations': boolean
// redux/settings/forceDollarMathInMarkdown
'data.export.markdown.force_dollar_math': boolean
// redux/settings/markdownExportPath
'data.export.markdown.path': string | null
// redux/settings/showModelNameInMarkdown
'data.export.markdown.show_model_name': boolean
// redux/settings/showModelProviderInMarkdown
'data.export.markdown.show_model_provider': boolean
// redux/settings/standardizeCitationsInExport
'data.export.markdown.standardize_citations': boolean
// redux/settings/useTopicNamingForMessageTitle
'data.export.markdown.use_topic_naming_for_message_title': boolean
// redux/settings/exportMenuOptions.docx
'data.export.menus.docx': boolean
// redux/settings/exportMenuOptions.image
'data.export.menus.image': boolean
// redux/settings/exportMenuOptions.joplin
'data.export.menus.joplin': boolean
// redux/settings/exportMenuOptions.markdown
'data.export.menus.markdown': boolean
// redux/settings/exportMenuOptions.markdown_reason
'data.export.menus.markdown_reason': boolean
// redux/settings/exportMenuOptions.notes
'data.export.menus.notes': boolean
// redux/settings/exportMenuOptions.notion
'data.export.menus.notion': boolean
// redux/settings/exportMenuOptions.obsidian
'data.export.menus.obsidian': boolean
// redux/settings/exportMenuOptions.plain_text
'data.export.menus.plain_text': boolean
// redux/settings/exportMenuOptions.siyuan
'data.export.menus.siyuan': boolean
// redux/settings/exportMenuOptions.yuque
'data.export.menus.yuque': boolean
// redux/settings/joplinExportReasoning
'data.integration.joplin.export_reasoning': boolean
// redux/settings/joplinToken
'data.integration.joplin.token': string
// redux/settings/joplinUrl
'data.integration.joplin.url': string
// redux/settings/notionApiKey
'data.integration.notion.api_key': string
// redux/settings/notionDatabaseID
'data.integration.notion.database_id': string
// redux/settings/notionExportReasoning
'data.integration.notion.export_reasoning': boolean
// redux/settings/notionPageNameKey
'data.integration.notion.page_name_key': string
// redux/settings/defaultObsidianVault
'data.integration.obsidian.default_vault': string
// redux/settings/siyuanApiUrl
'data.integration.siyuan.api_url': string | null
// redux/settings/siyuanBoxId
'data.integration.siyuan.box_id': string | null
// redux/settings/siyuanRootPath
'data.integration.siyuan.root_path': string | null
// redux/settings/siyuanToken
'data.integration.siyuan.token': string | null
// redux/settings/yuqueRepoId
'data.integration.yuque.repo_id': string
// redux/settings/yuqueToken
'data.integration.yuque.token': string
// redux/settings/yuqueUrl
'data.integration.yuque.url': string
// redux/settings/apiServer.apiKey
'feature.csaas.api_key': string
// redux/settings/apiServer.enabled
'feature.csaas.enabled': boolean
// redux/settings/apiServer.host
'feature.csaas.host': string
// redux/settings/apiServer.port
'feature.csaas.port': number
// redux/settings/maxKeepAliveMinapps
'feature.minapp.max_keep_alive': number
// redux/settings/minappsOpenLinkExternal
'feature.minapp.open_link_external': boolean
// redux/settings/showOpenedMinappsInSidebar
'feature.minapp.show_opened_in_sidebar': boolean
// redux/note/settings.defaultEditMode
'feature.notes.default_edit_mode': string
// redux/note/settings.defaultViewMode
'feature.notes.default_view_mode': string
// redux/note/settings.fontFamily
'feature.notes.font_family': string
// redux/note/settings.fontSize
'feature.notes.font_size': number
// redux/note/settings.isFullWidth
'feature.notes.full_width': boolean
// redux/note/notesPath
'feature.notes.path': string
// redux/note/settings.showTabStatus
'feature.notes.show_tab_status': boolean
// redux/note/settings.showTableOfContents
'feature.notes.show_table_of_contents': boolean
// redux/note/settings.showWorkspace
'feature.notes.show_workspace': boolean
// redux/note/sortType
'feature.notes.sort_type': string
// redux/settings/clickTrayToShowQuickAssistant
'feature.quick_assistant.click_tray_to_show': boolean
// redux/settings/enableQuickAssistant
'feature.quick_assistant.enabled': boolean
// redux/settings/readClipboardAtStartup
'feature.quick_assistant.read_clipboard_at_startup': boolean
// redux/selectionStore/actionItems
'feature.selection.action_items': PreferenceTypes.SelectionActionItem[]
// redux/selectionStore/actionWindowOpacity
'feature.selection.action_window_opacity': number
// redux/selectionStore/isAutoClose
'feature.selection.auto_close': boolean
// redux/selectionStore/isAutoPin
'feature.selection.auto_pin': boolean
// redux/selectionStore/isCompact
'feature.selection.compact': boolean
// redux/selectionStore/selectionEnabled
'feature.selection.enabled': boolean
// redux/selectionStore/filterList
'feature.selection.filter_list': string[]
// redux/selectionStore/filterMode
'feature.selection.filter_mode': PreferenceTypes.SelectionFilterMode
// redux/selectionStore/isFollowToolbar
'feature.selection.follow_toolbar': boolean
// redux/selectionStore/isRemeberWinSize
'feature.selection.remember_win_size': boolean
// redux/selectionStore/triggerMode
'feature.selection.trigger_mode': PreferenceTypes.SelectionTriggerMode
// redux/settings/translateModelPrompt
'feature.translate.model_prompt': string
// redux/settings/targetLanguage
'feature.translate.target_language': string
// redux/shortcuts/shortcuts.exit_fullscreen
'shortcut.app.exit_fullscreen': Record<string, unknown>
// redux/shortcuts/shortcuts.search_message
'shortcut.app.search_message': Record<string, unknown>
// redux/shortcuts/shortcuts.show_app
'shortcut.app.show_main_window': Record<string, unknown>
// redux/shortcuts/shortcuts.mini_window
'shortcut.app.show_mini_window': Record<string, unknown>
// redux/shortcuts/shortcuts.show_settings
'shortcut.app.show_settings': Record<string, unknown>
// redux/shortcuts/shortcuts.toggle_show_assistants
'shortcut.app.toggle_show_assistants': Record<string, unknown>
// redux/shortcuts/shortcuts.zoom_in
'shortcut.app.zoom_in': Record<string, unknown>
// redux/shortcuts/shortcuts.zoom_out
'shortcut.app.zoom_out': Record<string, unknown>
// redux/shortcuts/shortcuts.zoom_reset
'shortcut.app.zoom_reset': Record<string, unknown>
// redux/shortcuts/shortcuts.clear_topic
'shortcut.chat.clear': Record<string, unknown>
// redux/shortcuts/shortcuts.copy_last_message
'shortcut.chat.copy_last_message': Record<string, unknown>
// redux/shortcuts/shortcuts.search_message_in_chat
'shortcut.chat.search_message': Record<string, unknown>
// redux/shortcuts/shortcuts.toggle_new_context
'shortcut.chat.toggle_new_context': Record<string, unknown>
// redux/shortcuts/shortcuts.selection_assistant_select_text
'shortcut.selection.get_text': Record<string, unknown>
// redux/shortcuts/shortcuts.selection_assistant_toggle
'shortcut.selection.toggle_enabled': Record<string, unknown>
// redux/shortcuts/shortcuts.new_topic
'shortcut.topic.new': Record<string, unknown>
// redux/settings/enableTopicNaming
'topic.naming.enabled': boolean
// redux/settings/topicNamingPrompt
'topic.naming_prompt': string
// redux/settings/topicPosition
'topic.position': string
// redux/settings/pinTopicsToTop
'topic.tab.pin_to_top': boolean
// redux/settings/showTopics
'topic.tab.show': boolean
// redux/settings/showTopicTime
'topic.tab.show_time': boolean
// redux/translate/settings
'translate.settings.auto_copy': boolean
// indexedDB/translate
'translate.settings.auto_detection_method': PreferenceTypes.AutoDetectionMethod
'translate.settings.enable_markdown': boolean
'translate.settings.scroll_sync': boolean
// new preference
'translate.settings.target_langs': PreferenceTypes.TargetLangs
// redux/settings/customCss
'ui.custom_css': string
// redux/settings/navbarPosition
'ui.navbar.position': 'left' | 'top'
// redux/settings/sidebarIcons.disabled
'ui.sidebar.icons.invisible': PreferenceTypes.SidebarIcon[]
// redux/settings/sidebarIcons.visible
'ui.sidebar.icons.visible': PreferenceTypes.SidebarIcon[]
// redux/settings/theme
'ui.theme_mode': PreferenceTypes.ThemeMode
// redux/settings/userTheme.userCodeFontFamily
'ui.theme_user.code_font_family': string
// redux/settings/userTheme.colorPrimary
'ui.theme_user.color_primary': string
// redux/settings/userTheme.userFontFamily
'ui.theme_user.font_family': string
// redux/settings/windowStyle
'ui.window_style': PreferenceTypes.WindowStyle
}
}
/* eslint sort-keys: ["error", "asc", {"caseSensitive": true, "natural": false}] */
export const DefaultPreferences: PreferenceSchemas = {
default: {
'app.developer_mode.enabled': false,
'app.disable_hardware_acceleration': false,
'app.dist.auto_update.enabled': true,
'app.dist.test_plan.channel': PreferenceTypes.UpgradeChannel.LATEST,
'app.dist.test_plan.enabled': false,
'app.language': null,
'app.launch_on_boot': false,
'app.notification.assistant.enabled': false,
'app.notification.backup.enabled': false,
'app.notification.knowledge.enabled': false,
'app.privacy.data_collection.enabled': false,
'app.proxy.bypass_rules': '',
'app.proxy.mode': 'system',
'app.proxy.url': '',
'app.spell_check.enabled': false,
'app.spell_check.languages': [],
'app.tray.enabled': true,
'app.tray.on_close': true,
'app.tray.on_launch': false,
'app.user.id': 'uuid()',
'app.user.name': '',
'app.zoom_factor': 1,
'assistant.click_to_show_topic': true,
'assistant.icon_type': 'emoji',
'assistant.tab.show': true,
'assistant.tab.sort_type': 'list',
'chat.code.collapsible': false,
'chat.code.editor.autocompletion': true,
'chat.code.editor.enabled': false,
'chat.code.editor.fold_gutter': false,
'chat.code.editor.highlight_active_line': false,
'chat.code.editor.keymap': false,
'chat.code.editor.theme_dark': 'auto',
'chat.code.editor.theme_light': 'auto',
'chat.code.execution.enabled': false,
'chat.code.execution.timeout_minutes': 1,
'chat.code.fancy_block': true,
'chat.code.image_tools': false,
'chat.code.preview.theme_dark': 'auto',
'chat.code.preview.theme_light': 'auto',
'chat.code.show_line_numbers': false,
'chat.code.viewer.theme_dark': 'auto',
'chat.code.viewer.theme_light': 'auto',
'chat.code.wrappable': false,
'chat.input.paste_long_text_as_file': false,
'chat.input.paste_long_text_threshold': 1500,
'chat.input.quick_panel.triggers_enabled': false,
'chat.input.send_message_shortcut': 'Enter',
'chat.input.show_estimated_tokens': false,
'chat.input.translate.auto_translate_with_space': false,
'chat.input.translate.show_confirm': true,
'chat.message.confirm_delete': true,
'chat.message.confirm_regenerate': true,
'chat.message.font': 'system',
'chat.message.font_size': 14,
'chat.message.math.engine': 'KaTeX',
'chat.message.math.single_dollar': true,
'chat.message.multi_model.fold_display_mode': 'expanded',
'chat.message.multi_model.grid_columns': 2,
'chat.message.multi_model.grid_popover_trigger': 'click',
'chat.message.multi_model.style': 'horizontal',
'chat.message.navigation_mode': 'none',
'chat.message.render_as_markdown': false,
'chat.message.show_divider': true,
'chat.message.show_outline': false,
'chat.message.show_prompt': true,
'chat.message.style': 'plain',
'chat.message.thought.auto_collapse': true,
'chat.narrow_mode': false,
'data.backup.general.skip_backup_file': false,
'data.backup.local.auto_sync': false,
'data.backup.local.dir': '',
'data.backup.local.max_backups': 0,
'data.backup.local.skip_backup_file': false,
'data.backup.local.sync_interval': 0,
'data.backup.nutstore.auto_sync': false,
'data.backup.nutstore.max_backups': 0,
'data.backup.nutstore.path': '/cherry-studio',
'data.backup.nutstore.skip_backup_file': false,
'data.backup.nutstore.sync_interval': 0,
'data.backup.nutstore.token': '',
'data.backup.s3.access_key_id': '',
'data.backup.s3.auto_sync': false,
'data.backup.s3.bucket': '',
'data.backup.s3.endpoint': '',
'data.backup.s3.max_backups': 0,
'data.backup.s3.region': '',
'data.backup.s3.root': '',
'data.backup.s3.secret_access_key': '',
'data.backup.s3.skip_backup_file': false,
'data.backup.s3.sync_interval': 0,
'data.backup.webdav.auto_sync': false,
'data.backup.webdav.disable_stream': false,
'data.backup.webdav.host': '',
'data.backup.webdav.max_backups': 0,
'data.backup.webdav.pass': '',
'data.backup.webdav.path': '/cherry-studio',
'data.backup.webdav.skip_backup_file': false,
'data.backup.webdav.sync_interval': 0,
'data.backup.webdav.user': '',
'data.export.markdown.exclude_citations': false,
'data.export.markdown.force_dollar_math': false,
'data.export.markdown.path': null,
'data.export.markdown.show_model_name': false,
'data.export.markdown.show_model_provider': false,
'data.export.markdown.standardize_citations': false,
'data.export.markdown.use_topic_naming_for_message_title': false,
'data.export.menus.docx': true,
'data.export.menus.image': true,
'data.export.menus.joplin': true,
'data.export.menus.markdown': true,
'data.export.menus.markdown_reason': true,
'data.export.menus.notes': true,
'data.export.menus.notion': true,
'data.export.menus.obsidian': true,
'data.export.menus.plain_text': true,
'data.export.menus.siyuan': true,
'data.export.menus.yuque': true,
'data.integration.joplin.export_reasoning': false,
'data.integration.joplin.token': '',
'data.integration.joplin.url': '',
'data.integration.notion.api_key': '',
'data.integration.notion.database_id': '',
'data.integration.notion.export_reasoning': false,
'data.integration.notion.page_name_key': 'Name',
'data.integration.obsidian.default_vault': '',
'data.integration.siyuan.api_url': null,
'data.integration.siyuan.box_id': null,
'data.integration.siyuan.root_path': null,
'data.integration.siyuan.token': null,
'data.integration.yuque.repo_id': '',
'data.integration.yuque.token': '',
'data.integration.yuque.url': '',
'feature.csaas.api_key': '`cs-sk-${uuid()}`',
'feature.csaas.enabled': false,
'feature.csaas.host': 'localhost',
'feature.csaas.port': 23333,
'feature.minapp.max_keep_alive': 3,
'feature.minapp.open_link_external': false,
'feature.minapp.show_opened_in_sidebar': true,
'feature.notes.default_edit_mode': 'preview',
'feature.notes.default_view_mode': 'edit',
'feature.notes.font_family': 'default',
'feature.notes.font_size': 16,
'feature.notes.full_width': true,
'feature.notes.path': '',
'feature.notes.show_tab_status': true,
'feature.notes.show_table_of_contents': true,
'feature.notes.show_workspace': true,
'feature.notes.sort_type': 'sort_a2z',
'feature.quick_assistant.click_tray_to_show': false,
'feature.quick_assistant.enabled': false,
'feature.quick_assistant.read_clipboard_at_startup': true,
'feature.selection.action_items': [
{
enabled: true,
icon: 'languages',
id: 'translate',
isBuiltIn: true,
name: 'selection.action.builtin.translate'
},
{
enabled: true,
icon: 'file-question',
id: 'explain',
isBuiltIn: true,
name: 'selection.action.builtin.explain'
},
{ enabled: true, icon: 'scan-text', id: 'summary', isBuiltIn: true, name: 'selection.action.builtin.summary' },
{
enabled: true,
icon: 'search',
id: 'search',
isBuiltIn: true,
name: 'selection.action.builtin.search',
searchEngine: 'Google|https://www.google.com/search?q={{queryString}}'
},
{ enabled: true, icon: 'clipboard-copy', id: 'copy', isBuiltIn: true, name: 'selection.action.builtin.copy' },
{ enabled: false, icon: 'wand-sparkles', id: 'refine', isBuiltIn: true, name: 'selection.action.builtin.refine' },
{ enabled: false, icon: 'quote', id: 'quote', isBuiltIn: true, name: 'selection.action.builtin.quote' }
],
'feature.selection.action_window_opacity': 100,
'feature.selection.auto_close': false,
'feature.selection.auto_pin': false,
'feature.selection.compact': false,
'feature.selection.enabled': false,
'feature.selection.filter_list': [],
'feature.selection.filter_mode': PreferenceTypes.SelectionFilterMode.Default,
'feature.selection.follow_toolbar': true,
'feature.selection.remember_win_size': false,
'feature.selection.trigger_mode': PreferenceTypes.SelectionTriggerMode.Selected,
'feature.translate.model_prompt': TRANSLATE_PROMPT,
'feature.translate.target_language': 'en-us',
'shortcut.app.exit_fullscreen': { editable: false, enabled: true, key: ['Escape'], system: true },
'shortcut.app.search_message': {
editable: true,
enabled: true,
key: ['CommandOrControl', 'Shift', 'F'],
system: false
},
'shortcut.app.show_main_window': { editable: true, enabled: true, key: [], system: true },
'shortcut.app.show_mini_window': { editable: true, enabled: false, key: ['CommandOrControl', 'E'], system: true },
'shortcut.app.show_settings': { editable: false, enabled: true, key: ['CommandOrControl', ','], system: true },
'shortcut.app.toggle_show_assistants': {
editable: true,
enabled: true,
key: ['CommandOrControl', '['],
system: false
},
'shortcut.app.zoom_in': { editable: false, enabled: true, key: ['CommandOrControl', '='], system: true },
'shortcut.app.zoom_out': { editable: false, enabled: true, key: ['CommandOrControl', '-'], system: true },
'shortcut.app.zoom_reset': { editable: false, enabled: true, key: ['CommandOrControl', '0'], system: true },
'shortcut.chat.clear': { editable: true, enabled: true, key: ['CommandOrControl', 'L'], system: false },
'shortcut.chat.copy_last_message': {
editable: true,
enabled: false,
key: ['CommandOrControl', 'Shift', 'C'],
system: false
},
'shortcut.chat.search_message': { editable: true, enabled: true, key: ['CommandOrControl', 'F'], system: false },
'shortcut.chat.toggle_new_context': {
editable: true,
enabled: true,
key: ['CommandOrControl', 'K'],
system: false
},
'shortcut.selection.get_text': { editable: true, enabled: false, key: [], system: true },
'shortcut.selection.toggle_enabled': { editable: true, enabled: false, key: [], system: true },
'shortcut.topic.new': { editable: true, enabled: true, key: ['CommandOrControl', 'N'], system: false },
'topic.naming.enabled': true,
'topic.naming_prompt': '',
'topic.position': 'left',
'topic.tab.pin_to_top': false,
'topic.tab.show': true,
'topic.tab.show_time': false,
'translate.settings.auto_copy': false,
'translate.settings.auto_detection_method': 'franc',
'translate.settings.enable_markdown': false,
'translate.settings.scroll_sync': false,
'translate.settings.target_langs': {
alter: 'zh-cn',
target: 'en-us'
},
'ui.custom_css': '',
'ui.navbar.position': 'top',
'ui.sidebar.icons.invisible': [],
'ui.sidebar.icons.visible': [
'assistants',
'store',
'paintings',
'translate',
'minapp',
'knowledge',
'files',
'code_tools',
'notes'
],
'ui.theme_mode': PreferenceTypes.ThemeMode.system,
'ui.theme_user.code_font_family': '',
'ui.theme_user.color_primary': '#00b96b',
'ui.theme_user.font_family': '',
'ui.window_style': 'opaque'
}
}
// === AUTO-GENERATED CONTENT END ===
/**
* 生成统计:
* - 总配置项: 197
* - electronStore项: 1
* - redux项: 196
* - localStorage项: 0
*/

View File

@@ -0,0 +1,100 @@
import type { TranslateLanguageCode } from '@types'
import * as z from 'zod'
import type { PreferenceSchemas } from './preferenceSchemas'
export type PreferenceDefaultScopeType = PreferenceSchemas['default']
export type PreferenceKeyType = keyof PreferenceDefaultScopeType
export type PreferenceUpdateOptions = {
optimistic: boolean
}
export type PreferenceShortcutType = {
key: string[]
editable: boolean
enabled: boolean
system: boolean
}
export enum SelectionTriggerMode {
Selected = 'selected',
Ctrlkey = 'ctrlkey',
Shortcut = 'shortcut'
}
export enum SelectionFilterMode {
Default = 'default',
Whitelist = 'whitelist',
Blacklist = 'blacklist'
}
export type SelectionActionItem = {
id: string
name: string
enabled: boolean
isBuiltIn: boolean
icon?: string
prompt?: string
assistantId?: string
selectedText?: string
searchEngine?: string
}
export enum ThemeMode {
light = 'light',
dark = 'dark',
system = 'system'
}
/** 有限的UI语言 */
export type LanguageVarious = 'zh-CN' | 'zh-TW' | 'el-GR' | 'en-US' | 'es-ES' | 'fr-FR' | 'ja-JP' | 'pt-PT' | 'ru-RU'
export type WindowStyle = 'transparent' | 'opaque'
export type SendMessageShortcut = 'Enter' | 'Shift+Enter' | 'Ctrl+Enter' | 'Command+Enter' | 'Alt+Enter'
export type AssistantTabSortType = 'tags' | 'list'
export type SidebarIcon =
| 'assistants'
| 'store'
| 'paintings'
| 'translate'
| 'minapp'
| 'knowledge'
| 'files'
| 'code_tools'
| 'notes'
export type AssistantIconType = 'model' | 'emoji' | 'none'
export type ProxyMode = 'system' | 'custom' | 'none'
export type MultiModelFoldDisplayMode = 'expanded' | 'compact'
export type MathEngine = 'KaTeX' | 'MathJax' | 'none'
export enum UpgradeChannel {
LATEST = 'latest', // 最新稳定版本
RC = 'rc', // 公测版本
BETA = 'beta' // 预览版本
}
export type ChatMessageStyle = 'plain' | 'bubble'
export type ChatMessageNavigationMode = 'none' | 'buttons' | 'anchor'
export type MultiModelMessageStyle = 'horizontal' | 'vertical' | 'fold' | 'grid'
export type MultiModelGridPopoverTrigger = 'hover' | 'click'
const AutoDetectionMethodSchema = z.enum(['franc', 'llm', 'auto'])
export type AutoDetectionMethod = z.infer<typeof AutoDetectionMethodSchema>
export const isAutoDetectionMethod = (method: string): method is AutoDetectionMethod => {
return AutoDetectionMethodSchema.safeParse(method).success
}
export type TargetLangs = {
target: TranslateLanguageCode
alter: TranslateLanguageCode
}

15
packages/ui/.gitignore vendored Normal file
View File

@@ -0,0 +1,15 @@
node_modules/
dist/
*.log
.DS_Store
# Storybook build output
storybook-static/
# IDE
.vscode/
.idea/
# Temporary files
*.tmp
*.temp

View File

@@ -0,0 +1,17 @@
import type { StorybookConfig } from '@storybook/react-vite'
const config: StorybookConfig = {
stories: ['../stories/components/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-docs', '@storybook/addon-themes'],
framework: '@storybook/react-vite',
viteFinal: async (config) => {
const { mergeConfig } = await import('vite')
// 动态导入 @tailwindcss/vite 以避免 ESM/CJS 兼容性问题
const tailwindPlugin = (await import('@tailwindcss/vite')).default
return mergeConfig(config, {
plugins: [tailwindPlugin()]
})
}
}
export default config

View File

@@ -0,0 +1,18 @@
import '../stories/tailwind.css'
import { withThemeByClassName } from '@storybook/addon-themes'
import type { Preview } from '@storybook/react'
const preview: Preview = {
decorators: [
withThemeByClassName({
themes: {
light: '',
dark: 'dark'
},
defaultTheme: 'light'
})
]
}
export default preview

View File

@@ -0,0 +1,152 @@
# UI 组件库迁移状态
## 使用示例
```typescript
// 从 @cherrystudio/ui 导入组件
import { Spinner, DividerWithText, InfoTooltip, CustomTag } from '@cherrystudio/ui'
// 在组件中使用
function MyComponent() {
return (
<div>
<Spinner size={24} />
<DividerWithText text="分隔文本" />
<InfoTooltip content="提示信息" />
<CustomTag color="var(--color-primary)">标签</CustomTag>
</div>
)
}
```
## 目录结构说明
```text
@packages/ui/
├── src/
│ ├── components/ # 组件主目录
│ │ ├── base/ # 基础组件(按钮、输入框、标签等)
│ │ ├── display/ # 显示组件(卡片、列表、表格等)
│ │ ├── layout/ # 布局组件(容器、网格、间距等)
│ │ ├── icons/ # 图标组件
│ │ ├── interactive/ # 交互组件(弹窗、提示、下拉等)
│ │ └── composite/ # 复合组件(多个基础组件组合而成)
│ ├── hooks/ # 自定义 React Hooks
│ └── types/ # TypeScript 类型定义
```
### 组件分类指南
提交 PR 时,请根据组件功能将其放入正确的目录:
- **base**: 最基础的 UI 元素,如按钮、输入框、开关、标签等
- **display**: 用于展示内容的组件,如卡片、列表、表格、标签页等
- **layout**: 用于页面布局的组件,如容器、网格系统、分隔符等
- **icons**: 所有图标相关的组件
- **interactive**: 需要用户交互的组件,如模态框、抽屉、提示框、下拉菜单等
- **composite**: 复合组件,由多个基础组件组合而成
## 迁移概览
- **总组件数**: 236
- **已迁移**: 34
- **已重构**: 18
- **待迁移**: 184
## 组件状态表
| Category | Component Name | Migration Status | Refactoring Status | Description |
| --------------- | ------------------------- | ---------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **base** | | | | 基础组件 |
| | CopyButton | ✅ | ✅ | 复制按钮 |
| | CustomTag | ✅ | ✅ | 自定义标签 |
| | DividerWithText | ✅ | ✅ | 带文本的分隔线 |
| | EmojiIcon | ✅ | ✅ | 表情图标 |
| | ErrorBoundary | ✅ | ✅ | 错误边界 (通过 props 解耦) |
| | StatusTag | ✅ | ✅ | 统一状态标签(合并了 ErrorTag、SuccessTag、WarnTag、InfoTag |
| | IndicatorLight | ✅ | ✅ | 指示灯 |
| | Spinner | ✅ | ✅ | 加载动画 |
| | TextBadge | ✅ | ✅ | 文本徽标 |
| | CustomCollapse | ✅ | ✅ | 自定义折叠面板 |
| **display** | | | | 显示组件 |
| | Ellipsis | ✅ | ✅ | 文本省略 |
| | ExpandableText | ✅ | ✅ | 可展开文本 |
| | ThinkingEffect | ✅ | ✅ | 思考效果动画 |
| | EmojiAvatar | ✅ | ✅ | 表情头像 |
| | ListItem | ✅ | ✅ | 列表项 |
| | MaxContextCount | ✅ | ✅ | 最大上下文数显示 |
| | ProviderAvatar | ✅ | ✅ | 提供者头像 |
| | CodeViewer | ❌ | ❌ | 代码查看器 (外部依赖) |
| | OGCard | ❌ | ❌ | OG 卡片 |
| | MarkdownShadowDOMRenderer | ❌ | ❌ | Markdown 渲染器 |
| | Preview/* | ❌ | ❌ | 预览组件 |
| **layout** | | | | 布局组件 |
| | HorizontalScrollContainer | ✅ | ❌ | 水平滚动容器 |
| | Scrollbar | ✅ | ❌ | 滚动条 |
| | Layout/* | ✅ | ✅ | 布局组件 |
| | Tab/* | ❌ | ❌ | 标签页 (Redux 依赖) |
| | TopView | ❌ | ❌ | 顶部视图 (window.api 依赖) |
| **icons** | | | | 图标组件 |
| | Icon | ✅ | ✅ | 图标工厂函数和预定义图标(合并了 CopyIcon、DeleteIcon、EditIcon、RefreshIcon、ResetIcon、ToolIcon、VisionIcon、WebSearchIcon、WrapIcon、UnWrapIcon、OcrIcon |
| | FileIcons | ✅ | ❌ | 文件图标 (FileSvgIcon、FilePngIcon) |
| | ReasoningIcon | ✅ | ❌ | 推理图标 |
| | SvgSpinners180Ring | ✅ | ❌ | 旋转加载图标 |
| | ToolsCallingIcon | ✅ | ❌ | 工具调用图标 |
| **interactive** | | | | 交互组件 |
| | InfoTooltip | ✅ | ❌ | 信息提示 |
| | HelpTooltip | ✅ | ❌ | 帮助提示 |
| | WarnTooltip | ✅ | ❌ | 警告提示 |
| | EditableNumber | ✅ | ❌ | 可编辑数字 |
| | InfoPopover | ✅ | ❌ | 信息弹出框 |
| | CollapsibleSearchBar | ✅ | ❌ | 可折叠搜索栏 |
| | ImageToolButton | ✅ | ❌ | 图片工具按钮 |
| | DraggableList | ✅ | ❌ | 可拖拽列表 |
| | CodeEditor | ✅ | ❌ | 代码编辑器 |
| | EmojiPicker | ❌ | ❌ | 表情选择器 (useTheme 依赖) |
| | Selector | ✅ | ❌ | 选择器 (i18n 依赖) |
| | ModelSelector | ❌ | ❌ | 模型选择器 (Redux 依赖) |
| | LanguageSelect | ❌ | ❌ | 语言选择 |
| | TranslateButton | ❌ | ❌ | 翻译按钮 (window.api 依赖) |
| **composite** | | | | 复合组件 |
| | - | - | - | 暂无复合组件 |
| **未分类** | | | | 需要分类的组件 |
| | Popups/* (16+ 文件) | ❌ | ❌ | 弹窗组件 (业务耦合) |
| | RichEditor/* (30+ 文件) | ❌ | ❌ | 富文本编辑器 |
| | MarkdownEditor/* | ❌ | ❌ | Markdown 编辑器 |
| | MinApp/* | ❌ | ❌ | 迷你应用 (Redux 依赖) |
| | Avatar/* | ❌ | ❌ | 头像组件 |
| | ActionTools/* | ❌ | ❌ | 操作工具 |
| | CodeBlockView/* | ❌ | ❌ | 代码块视图 (window.api 依赖) |
| | ContextMenu | ❌ | ❌ | 右键菜单 (Electron API) |
| | WindowControls | ❌ | ❌ | 窗口控制 (Electron API) |
| | ErrorBoundary | ❌ | ❌ | 错误边界 (window.api 依赖) |
## 迁移步骤
### 第一阶段:复制迁移(当前阶段)
- 将组件原样复制到 @packages/ui
- 保留原有依赖antd、styled-components 等)
- 在文件顶部添加原路径注释
### 第二阶段:重构优化
- 移除 antd 依赖,替换为 HeroUI
- 移除 styled-components替换为 Tailwind CSS
- 优化组件 API 和类型定义
## 注意事项
1. **不迁移**包含以下依赖的组件(解耦后可迁移):
- window.api 调用
- ReduxuseSelector、useDispatch 等)
- 其他外部数据源
2. **可迁移**但需要后续解耦的组件:
- 使用 i18n 的组件(将 i18n 改为 props 传入)
- 使用 antd 的组件(后续替换为 HeroUI
3. **提交规范**
- 每次 PR 专注于一个类别的组件
- 确保所有迁移的组件都有导出
- 更新此文档的迁移状态

View File

@@ -0,0 +1,151 @@
# UI Component Library Migration Status
## Usage Example
```typescript
// Import components from @cherrystudio/ui
import { Spinner, DividerWithText, InfoTooltip } from '@cherrystudio/ui'
// Use in components
function MyComponent() {
return (
<div>
<Spinner size={24} />
<DividerWithText text="Divider Text" />
<InfoTooltip content="Tooltip message" />
</div>
)
}
```
## Directory Structure
```text
@packages/ui/
├── src/
│ ├── components/ # Main components directory
│ │ ├── base/ # Basic components (buttons, inputs, labels, etc.)
│ │ ├── display/ # Display components (cards, lists, tables, etc.)
│ │ ├── layout/ # Layout components (containers, grids, spacing, etc.)
│ │ ├── icons/ # Icon components
│ │ ├── interactive/ # Interactive components (modals, tooltips, dropdowns, etc.)
│ │ └── composite/ # Composite components (made from multiple base components)
│ ├── hooks/ # Custom React Hooks
│ └── types/ # TypeScript type definitions
```
### Component Classification Guide
When submitting PRs, please place components in the correct directory based on their function:
- **base**: Most basic UI elements like buttons, inputs, switches, labels, etc.
- **display**: Components for displaying content like cards, lists, tables, tabs, etc.
- **layout**: Components for page layout like containers, grid systems, dividers, etc.
- **icons**: All icon-related components
- **interactive**: Components requiring user interaction like modals, drawers, tooltips, dropdowns, etc.
- **composite**: Composite components made from multiple base components
## Migration Overview
- **Total Components**: 236
- **Migrated**: 34
- **Refactored**: 18
- **Pending Migration**: 184
## Component Status Table
| Category | Component Name | Migration Status | Refactoring Status | Description |
| ----------------- | ------------------------- | ---------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **base** | | | | Base components |
| | CopyButton | ✅ | ✅ | Copy button |
| | CustomTag | ✅ | ✅ | Custom tag |
| | DividerWithText | ✅ | ✅ | Divider with text |
| | EmojiIcon | ✅ | ✅ | Emoji icon |
| | ErrorBoundary | ✅ | ✅ | Error boundary (decoupled via props) |
| | StatusTag | ✅ | ✅ | Unified status tag (merged ErrorTag, SuccessTag, WarnTag, InfoTag) |
| | IndicatorLight | ✅ | ✅ | Indicator light |
| | Spinner | ✅ | ✅ | Loading spinner |
| | TextBadge | ✅ | ✅ | Text badge |
| | CustomCollapse | ✅ | ✅ | Custom collapse panel |
| **display** | | | | Display components |
| | Ellipsis | ✅ | ✅ | Text ellipsis |
| | ExpandableText | ✅ | ✅ | Expandable text |
| | ThinkingEffect | ✅ | ✅ | Thinking effect animation |
| | EmojiAvatar | ✅ | ✅ | Emoji avatar |
| | ListItem | ✅ | ✅ | List item |
| | MaxContextCount | ✅ | ✅ | Max context count display |
| | ProviderAvatar | ✅ | ✅ | Provider avatar |
| | CodeViewer | ❌ | ❌ | Code viewer (external deps) |
| | OGCard | ❌ | ❌ | OG card |
| | MarkdownShadowDOMRenderer | ❌ | ❌ | Markdown renderer |
| | Preview/* | ❌ | ❌ | Preview components |
| **layout** | | | | Layout components |
| | HorizontalScrollContainer | ✅ | ❌ | Horizontal scroll container |
| | Scrollbar | ✅ | ❌ | Scrollbar |
| | Layout/* | ✅ | ✅ | Layout components |
| | Tab/* | ❌ | ❌ | Tab (Redux dependency) |
| | TopView | ❌ | ❌ | Top view (window.api dependency) |
| **icons** | | | | Icon components |
| | Icon | ✅ | ✅ | Icon factory function and predefined icons (merged CopyIcon, DeleteIcon, EditIcon, RefreshIcon, ResetIcon, ToolIcon, VisionIcon, WebSearchIcon, WrapIcon, UnWrapIcon, OcrIcon) |
| | FileIcons | ✅ | ❌ | File icons (FileSvgIcon, FilePngIcon) |
| | ReasoningIcon | ✅ | ❌ | Reasoning icon |
| | SvgSpinners180Ring | ✅ | ❌ | Spinner loading icon |
| | ToolsCallingIcon | ✅ | ❌ | Tools calling icon |
| **interactive** | | | | Interactive components |
| | InfoTooltip | ✅ | ❌ | Info tooltip |
| | HelpTooltip | ✅ | ❌ | Help tooltip |
| | WarnTooltip | ✅ | ❌ | Warning tooltip |
| | EditableNumber | ✅ | ❌ | Editable number |
| | InfoPopover | ✅ | ❌ | Info popover |
| | CollapsibleSearchBar | ✅ | ❌ | Collapsible search bar |
| | ImageToolButton | ✅ | ❌ | Image tool button |
| | DraggableList | ✅ | ❌ | Draggable list |
| | CodeEditor | ✅ | ❌ | Code editor |
| | EmojiPicker | ❌ | ❌ | Emoji picker (useTheme dependency) |
| | Selector | ✅ | ❌ | Selector (i18n dependency) |
| | ModelSelector | ❌ | ❌ | Model selector (Redux dependency) |
| | LanguageSelect | ❌ | ❌ | Language select |
| | TranslateButton | ❌ | ❌ | Translate button (window.api dependency) |
| **composite** | | | | Composite components |
| | - | - | - | No composite components yet |
| **Uncategorized** | | | | Components needing categorization |
| | Popups/* (16+ files) | ❌ | ❌ | Popup components (business coupled) |
| | RichEditor/* (30+ files) | ❌ | ❌ | Rich text editor |
| | MarkdownEditor/* | ❌ | ❌ | Markdown editor |
| | MinApp/* | ❌ | ❌ | Mini app (Redux dependency) |
| | Avatar/* | ❌ | ❌ | Avatar components |
| | ActionTools/* | ❌ | ❌ | Action tools |
| | CodeBlockView/* | ❌ | ❌ | Code block view (window.api dependency) |
| | ContextMenu | ❌ | ❌ | Context menu (Electron API) |
| | WindowControls | ❌ | ❌ | Window controls (Electron API) |
| | ErrorBoundary | ❌ | ❌ | Error boundary (window.api dependency) |
## Migration Steps
### Phase 1: Copy Migration (Current Phase)
- Copy components as-is to @packages/ui
- Retain original dependencies (antd, styled-components, etc.)
- Add original path comment at file top
### Phase 2: Refactor and Optimize
- Remove antd dependencies, replace with HeroUI
- Remove styled-components, replace with Tailwind CSS
- Optimize component APIs and type definitions
## Notes
1. **Do NOT migrate** components with these dependencies (can be migrated after decoupling):
- window.api calls
- Redux (useSelector, useDispatch, etc.)
- Other external data sources
2. **Can migrate** but need decoupling later:
- Components using i18n (change i18n to props)
- Components using antd (replace with HeroUI later)
3. **Submission Guidelines**:
- Each PR should focus on one category of components
- Ensure all migrated components are exported
- Update migration status in this document

200
packages/ui/README.md Normal file
View File

@@ -0,0 +1,200 @@
# @cherrystudio/ui
Cherry Studio UI 组件库 - 为 Cherry Studio 设计的 React 组件集合
## 特性
- 🎨 基于 Tailwind CSS 的现代化设计
- 📦 支持 ESM 和 CJS 格式
- 🔷 完整的 TypeScript 支持
- 🚀 可以作为 npm 包发布
- 🔧 开箱即用的常用 hooks 和工具函数
## 安装
```bash
# 安装组件库
npm install @cherrystudio/ui
# 安装必需的 peer dependencies
npm install @heroui/react framer-motion react react-dom tailwindcss
```
## 配置
### 1. Tailwind CSS v4 配置
本组件库使用 Tailwind CSS v4配置方式已改变。在你的主 CSS 文件(如 `src/styles/tailwind.css`)中:
```css
@import 'tailwindcss';
/* 必须扫描组件库文件以提取类名 */
@source '../node_modules/@cherrystudio/ui/dist/**/*.{js,mjs}';
/* 你的应用源文件 */
@source './src/**/*.{js,ts,jsx,tsx}';
/*
* 如果你的应用直接使用 HeroUI 组件,需要添加:
* @source '../node_modules/@heroui/theme/dist/**/*.{js,ts,jsx,tsx}';
* @plugin '@heroui/react/plugin';
*/
/* 自定义主题配置(可选) */
@theme {
/* 你的主题扩展 */
}
```
注意Tailwind CSS v4 不再使用 `tailwind.config.js` 文件,所有配置都在 CSS 中完成。
### 2. Provider 配置
在你的 App 根组件中添加 HeroUI Provider
```tsx
import { HeroUIProvider } from '@heroui/react'
function App() {
return (
<HeroUIProvider>
{/* 你的应用内容 */}
</HeroUIProvider>
)
}
```
## 使用
### 基础组件
```tsx
import { Button, Input } from '@cherrystudio/ui'
function App() {
return (
<div>
<Button variant="primary" size="md">
点击我
</Button>
<Input
type="text"
placeholder="请输入内容"
onChange={(value) => console.log(value)}
/>
</div>
)
}
```
### 分模块导入
```tsx
// 只导入组件
import { Button } from '@cherrystudio/ui/components'
// 只导入 hooks
import { useDebounce, useLocalStorage } from '@cherrystudio/ui/hooks'
// 只导入工具函数
import { cn, formatFileSize } from '@cherrystudio/ui/utils'
```
## 开发
```bash
# 安装依赖
yarn install
# 开发模式(监听文件变化)
yarn dev
# 构建
yarn build
# 类型检查
yarn type-check
# 运行测试
yarn test
```
## 目录结构
```text
src/
├── components/ # React 组件
│ ├── Button/ # 按钮组件
│ ├── Input/ # 输入框组件
│ └── index.ts # 组件导出
├── hooks/ # React Hooks
├── utils/ # 工具函数
├── types/ # 类型定义
└── index.ts # 主入口文件
```
## 组件列表
### Button 按钮
支持多种变体和尺寸的按钮组件。
**Props:**
- `variant`: 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger'
- `size`: 'sm' | 'md' | 'lg'
- `loading`: boolean
- `fullWidth`: boolean
- `leftIcon` / `rightIcon`: React.ReactNode
### Input 输入框
带有错误处理和密码显示切换的输入框组件。
**Props:**
- `type`: 'text' | 'password' | 'email' | 'number'
- `error`: boolean
- `errorMessage`: string
- `onChange`: (value: string) => void
## Hooks
### useDebounce
防抖处理,延迟执行状态更新。
### useLocalStorage
本地存储的 React Hook 封装。
### useClickOutside
检测点击元素外部区域。
### useCopyToClipboard
复制文本到剪贴板。
## 工具函数
### cn(...inputs)
基于 clsx 的类名合并工具,支持条件类名。
### formatFileSize(bytes)
格式化文件大小显示。
### debounce(func, delay)
防抖函数。
### throttle(func, delay)
节流函数。
## 许可证
MIT

View File

@@ -0,0 +1,21 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"aliases": {
"components": "@/components",
"hooks": "@/hooks",
"lib": "@/lib",
"ui": "@/components/ui",
"utils": "@/utils"
},
"iconLibrary": "lucide",
"rsc": false,
"style": "new-york",
"tailwind": {
"baseColor": "zinc",
"config": "",
"css": "src/styles/globals.css",
"cssVariables": true,
"prefix": ""
},
"tsx": true
}

129
packages/ui/package.json Normal file
View File

@@ -0,0 +1,129 @@
{
"name": "@cherrystudio/ui",
"version": "1.0.0-alpha.1",
"description": "Cherry Studio UI Component Library - React Components for Cherry Studio",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"react-native": "dist/index.js",
"scripts": {
"build": "tsdown",
"dev": "tsc -w",
"clean": "rm -rf dist",
"test": "vitest run",
"test:watch": "vitest",
"lint": "eslint src --ext .ts,.tsx --fix",
"type-check": "tsc --noEmit -p tsconfig.json --composite false",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"keywords": [
"ui",
"components",
"react",
"tailwindcss",
"typescript",
"cherry-studio"
],
"author": "Cherry Studio",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/CherryHQ/cherry-studio.git"
},
"bugs": {
"url": "https://github.com/CherryHQ/cherry-studio/issues"
},
"homepage": "https://github.com/CherryHQ/cherry-studio#readme",
"peerDependencies": {
"@heroui/react": "^2.8.4",
"framer-motion": "^11.0.0 || ^12.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tailwindcss": "^4.1.13"
},
"dependencies": {
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/modifiers": "^9.0.0",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-popover": "^1.1.15",
"@radix-ui/react-slot": "^1.2.3",
"@radix-ui/react-use-controllable-state": "^1.2.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"lucide-react": "^0.545.0",
"react-dropzone": "^14.3.8",
"tailwind-merge": "^2.5.5"
},
"devDependencies": {
"@heroui/react": "^2.8.4",
"@storybook/addon-docs": "^9.1.6",
"@storybook/addon-themes": "^9.1.6",
"@storybook/react-vite": "^9.1.6",
"@types/react": "^19.0.12",
"@types/react-dom": "^19.0.4",
"@types/styled-components": "^5.1.34",
"@uiw/codemirror-extensions-langs": "^4.25.1",
"@uiw/codemirror-themes-all": "^4.25.1",
"@uiw/react-codemirror": "^4.25.1",
"antd": "^5.22.5",
"eslint-plugin-storybook": "9.1.6",
"framer-motion": "^12.23.12",
"linguist-languages": "^9.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"storybook": "^9.1.6",
"styled-components": "^6.1.15",
"tsdown": "^0.15.5",
"tsx": "^4.20.5",
"typescript": "^5.6.2",
"vitest": "^3.2.4"
},
"resolutions": {
"@codemirror/language": "6.11.3",
"@codemirror/lint": "6.8.5",
"@codemirror/view": "6.38.1"
},
"sideEffects": false,
"engines": {
"node": ">=18.0.0"
},
"files": [
"dist",
"README.md"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"react-native": "./dist/index.js",
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"default": "./dist/index.js"
},
"./components": {
"types": "./dist/components/index.d.ts",
"react-native": "./dist/components/index.js",
"import": "./dist/components/index.mjs",
"require": "./dist/components/index.js",
"default": "./dist/components/index.js"
},
"./hooks": {
"types": "./dist/hooks/index.d.ts",
"react-native": "./dist/hooks/index.js",
"import": "./dist/hooks/index.mjs",
"require": "./dist/hooks/index.js",
"default": "./dist/hooks/index.js"
},
"./utils": {
"types": "./dist/utils/index.d.ts",
"react-native": "./dist/utils/index.js",
"import": "./dist/utils/index.mjs",
"require": "./dist/utils/index.js",
"default": "./dist/utils/index.js"
}
},
"packageManager": "yarn@4.9.1"
}

View File

@@ -0,0 +1,36 @@
import { cn } from '@heroui/react'
import React, { memo } from 'react'
interface EmojiAvatarProps {
children: string
size?: number
fontSize?: number
onClick?: React.MouseEventHandler<HTMLDivElement>
className?: string
style?: React.CSSProperties
}
const EmojiAvatar = ({ children, size = 31, fontSize, onClick, className, style }: EmojiAvatarProps) => (
<div
onClick={onClick}
className={cn(
'flex items-center justify-center',
'bg-background-soft border-border',
'rounded-[20%] cursor-pointer',
'transition-opacity hover:opacity-80',
'border-[0.5px]',
className
)}
style={{
width: size,
height: size,
fontSize: fontSize ?? size * 0.5,
...style
}}>
{children}
</div>
)
EmojiAvatar.displayName = 'EmojiAvatar'
export default memo(EmojiAvatar)

View File

@@ -0,0 +1,26 @@
import type { AvatarProps as HeroUIAvatarProps } from '@heroui/react'
import { Avatar as HeroUIAvatar, AvatarGroup as HeroUIAvatarGroup, cn } from '@heroui/react'
import EmojiAvatar from './EmojiAvatar'
export interface AvatarProps extends Omit<HeroUIAvatarProps, 'size'> {
size?: 'xs' | 'sm' | 'md' | 'lg'
}
const Avatar = (props: AvatarProps) => {
const { size, className = '', ...rest } = props
const isExtraSmall = size === 'xs'
const resolvedSize = isExtraSmall ? undefined : size
const mergedClassName = cn(isExtraSmall && 'w-6 h-6 text-tiny', 'shadow-lg', className)
return <HeroUIAvatar size={resolvedSize} className={mergedClassName} {...rest} />
}
Avatar.displayName = 'Avatar'
const AvatarGroup = HeroUIAvatarGroup
AvatarGroup.displayName = 'AvatarGroup'
export { Avatar, AvatarGroup, EmojiAvatar }

View File

@@ -0,0 +1,12 @@
import type { ButtonProps as HeroUIButtonProps } from '@heroui/react'
import { Button as HeroUIButton } from '@heroui/react'
export interface ButtonProps extends HeroUIButtonProps {}
const Button = ({ ...props }: ButtonProps) => {
return <HeroUIButton {...props} />
}
Button.displayName = 'Button'
export default Button

View File

@@ -0,0 +1,31 @@
// Original path: src/renderer/src/components/CopyButton.tsx
import { Tooltip } from '@heroui/react'
import { Copy } from 'lucide-react'
import type { FC } from 'react'
interface CopyButtonProps {
tooltip?: string
label?: string
size?: number
className?: string
[key: string]: any
}
const CopyButton: FC<CopyButtonProps> = ({ tooltip, label, size = 14, className = '', ...props }) => {
const button = (
<div
className={`flex flex-row items-center gap-1 cursor-pointer text-gray-600 dark:text-gray-400 transition-colors duration-200 hover:text-blue-600 dark:hover:text-blue-400 ${className}`}
{...props}>
<Copy size={size} className="transition-colors duration-200" />
{label && <span style={{ fontSize: `${size}px` }}>{label}</span>}
</div>
)
if (tooltip) {
return <Tooltip content={tooltip}>{button}</Tooltip>
}
return button
}
export default CopyButton

View File

@@ -0,0 +1,46 @@
import { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps } from '@heroui/react'
import type { FC } from 'react'
import { memo } from 'react'
// 重新导出 HeroUI 的组件,方便直接使用
export { Accordion, AccordionItem } from '@heroui/react'
interface CustomCollapseProps {
children: React.ReactNode
accordionProps?: Omit<AccordionProps, 'children'>
accordionItemProps?: Omit<AccordionItemProps, 'children'>
}
const CustomCollapse: FC<CustomCollapseProps> = ({ children, accordionProps = {}, accordionItemProps = {} }) => {
// 解构 Accordion 的 props
const {
defaultExpandedKeys = ['1'],
variant = 'bordered',
className = '',
isDisabled = false,
...restAccordionProps
} = accordionProps
// 解构 AccordionItem 的 props
const { title = 'Collapse Panel', ...restAccordionItemProps } = accordionItemProps
return (
<Accordion
defaultExpandedKeys={defaultExpandedKeys}
variant={variant}
className={className}
isDisabled={isDisabled}
selectionMode="multiple"
{...restAccordionProps}>
<AccordionItem
key="1"
aria-label={typeof title === 'string' ? title : 'collapse-item'}
title={title}
{...restAccordionItemProps}>
{children}
</AccordionItem>
</Accordion>
)
}
export default memo(CustomCollapse)

View File

@@ -0,0 +1,87 @@
// Original path: src/renderer/src/components/Tags/CustomTag.tsx
import { Tooltip } from '@heroui/react'
import { X } from 'lucide-react'
import type { CSSProperties, FC, MouseEventHandler } from 'react'
import { memo, useMemo } from 'react'
export interface CustomTagProps {
icon?: React.ReactNode
children?: React.ReactNode | string
color: string
size?: number
style?: CSSProperties
tooltip?: string
closable?: boolean
onClose?: () => void
onClick?: MouseEventHandler<HTMLDivElement>
disabled?: boolean
inactive?: boolean
className?: string
}
const CustomTag: FC<CustomTagProps> = ({
children,
icon,
color,
size = 12,
style,
tooltip,
closable = false,
onClose,
onClick,
disabled,
inactive,
className = ''
}) => {
const actualColor = inactive ? '#aaaaaa' : color
const tagContent = useMemo(
() => (
<div
className={`inline-flex items-center gap-1 rounded-full whitespace-nowrap relative transition-opacity duration-200 ${
!disabled && onClick ? 'cursor-pointer hover:opacity-80' : disabled ? 'cursor-not-allowed' : 'cursor-auto'
} ${className}`}
style={{
padding: `${size / 3}px ${closable ? size * 1.8 : size * 0.8}px ${size / 3}px ${size * 0.8}px`,
color: actualColor,
backgroundColor: actualColor + '20',
fontSize: `${size}px`,
lineHeight: 1,
...style
}}
onClick={disabled ? undefined : onClick}>
{icon && <span style={{ fontSize: `${size}px`, color: actualColor }}>{icon}</span>}
{children}
{closable && (
<div
className="absolute flex items-center justify-center cursor-pointer rounded-full transition-all duration-200 hover:bg-[#da8a8a] hover:text-white"
style={{
right: `${size * 0.2}px`,
top: `${size * 0.2}px`,
bottom: `${size * 0.2}px`,
fontSize: `${size * 0.8}px`,
color: actualColor,
aspectRatio: 1
}}
onClick={(e) => {
e.stopPropagation()
onClose?.()
}}>
<X size={size * 0.8} />
</div>
)}
</div>
),
[actualColor, children, closable, disabled, icon, onClick, onClose, size, style, className]
)
return tooltip ? (
<Tooltip content={tooltip} delay={300}>
{tagContent}
</Tooltip>
) : (
tagContent
)
}
export default memo(CustomTag)

View File

@@ -0,0 +1,20 @@
// Original: src/renderer/src/components/DividerWithText.tsx
import type { CSSProperties } from 'react'
import React from 'react'
interface DividerWithTextProps {
text: string
style?: CSSProperties
className?: string
}
const DividerWithText: React.FC<DividerWithTextProps> = ({ text, style, className = '' }) => {
return (
<div className={`flex items-center my-0 ${className}`} style={style}>
<span className="text-xs text-gray-600 dark:text-gray-400 mr-2">{text}</span>
<div className="flex-1 h-px bg-gray-200 dark:bg-gray-700" />
</div>
)
}
export default DividerWithText

View File

@@ -0,0 +1,34 @@
// Original path: src/renderer/src/components/EmojiIcon.tsx
import type { FC } from 'react'
interface EmojiIconProps {
emoji: string
className?: string
size?: number
fontSize?: number
}
const EmojiIcon: FC<EmojiIconProps> = ({ emoji, className = '', size = 26, fontSize = 15 }) => {
return (
<div
className={`flex items-center justify-center flex-shrink-0 relative overflow-hidden mr-1 rounded-full ${className}`}
style={{
width: `${size}px`,
height: `${size}px`,
borderRadius: `${size / 2}px`,
fontSize: `${fontSize}px`
}}>
<div
className="absolute inset-0 flex items-center justify-center blur-sm opacity-40"
style={{
fontSize: '200%',
transform: 'scale(1.5)'
}}>
{emoji || '⭐️'}
</div>
{emoji}
</div>
)
}
export default EmojiIcon

View File

@@ -0,0 +1,94 @@
// Original path: src/renderer/src/components/ErrorBoundary.tsx
import { Button } from '@heroui/react'
import { AlertTriangle } from 'lucide-react'
import type { ComponentType, ReactNode } from 'react'
import type { FallbackProps } from 'react-error-boundary'
import { ErrorBoundary } from 'react-error-boundary'
import { formatErrorMessage } from './utils'
interface CustomFallbackProps extends FallbackProps {
onDebugClick?: () => void | Promise<void>
onReloadClick?: () => void | Promise<void>
debugButtonText?: string
reloadButtonText?: string
errorMessage?: string
}
const DefaultFallback: ComponentType<CustomFallbackProps> = (props: CustomFallbackProps): ReactNode => {
const {
error,
onDebugClick,
onReloadClick,
debugButtonText = 'Open DevTools',
reloadButtonText = 'Reload',
errorMessage = 'An error occurred'
} = props
return (
<div className="flex justify-center items-center w-full p-2">
<div className="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 w-full">
<div className="flex items-start gap-3">
<AlertTriangle className="text-red-500 dark:text-red-400 flex-shrink-0 mt-0.5" size={20} />
<div className="flex-1">
<h3 className="text-red-800 dark:text-red-200 font-medium text-sm mb-1">{errorMessage}</h3>
<p className="text-red-700 dark:text-red-300 text-sm mb-3">{formatErrorMessage(error)}</p>
<div className="flex gap-2">
{onDebugClick && (
<Button size="sm" variant="flat" color="danger" onPress={onDebugClick}>
{debugButtonText}
</Button>
)}
{onReloadClick && (
<Button size="sm" variant="flat" color="danger" onPress={onReloadClick}>
{reloadButtonText}
</Button>
)}
</div>
</div>
</div>
</div>
</div>
)
}
interface ErrorBoundaryCustomizedProps {
children: ReactNode
fallbackComponent?: ComponentType<CustomFallbackProps>
onDebugClick?: () => void | Promise<void>
onReloadClick?: () => void | Promise<void>
debugButtonText?: string
reloadButtonText?: string
errorMessage?: string
}
const ErrorBoundaryCustomized = ({
children,
fallbackComponent,
onDebugClick,
onReloadClick,
debugButtonText,
reloadButtonText,
errorMessage
}: ErrorBoundaryCustomizedProps) => {
const FallbackComponent = fallbackComponent ?? DefaultFallback
return (
<ErrorBoundary
FallbackComponent={(props: FallbackProps) => (
<FallbackComponent
{...props}
onDebugClick={onDebugClick}
onReloadClick={onReloadClick}
debugButtonText={debugButtonText}
reloadButtonText={reloadButtonText}
errorMessage={errorMessage}
/>
)}>
{children}
</ErrorBoundary>
)
}
export { ErrorBoundaryCustomized as ErrorBoundary }
export type { CustomFallbackProps, ErrorBoundaryCustomizedProps }

View File

@@ -0,0 +1,8 @@
// Utility functions for ErrorBoundary component
export function formatErrorMessage(error: Error): string {
if (error.message) {
return error.message
}
return error.toString()
}

View File

@@ -0,0 +1,37 @@
// Original: src/renderer/src/components/IndicatorLight.tsx
import React from 'react'
interface IndicatorLightProps {
color: string
size?: number
shadow?: boolean
style?: React.CSSProperties
animation?: boolean
className?: string
}
const IndicatorLight: React.FC<IndicatorLightProps> = ({
color,
size = 8,
shadow = true,
style,
animation = true,
className = ''
}) => {
const actualColor = color === 'green' ? '#22c55e' : color
return (
<div
className={`rounded-full ${animation ? 'animate-pulse' : ''} ${className}`}
style={{
width: `${size}px`,
height: `${size}px`,
backgroundColor: actualColor,
boxShadow: shadow ? `0 0 6px ${actualColor}` : 'none',
...style
}}
/>
)
}
export default IndicatorLight

View File

@@ -0,0 +1,333 @@
# Selector 组件
基于 HeroUI Select 封装的下拉选择组件,简化了 Set 和 Selection 的转换逻辑。
## 核心特性
-**类型安全**: 单选和多选自动推断回调类型
-**智能转换**: 自动处理 `Set<Key>` 和原始值的转换
-**HeroUI 风格**: 保持与 HeroUI 生态一致的 API
-**支持数字和字符串**: 泛型支持,自动识别值类型
## 基础用法
### 单选模式(默认)
```tsx
import { Selector } from '@cherrystudio/ui'
import { useState } from 'react'
function Example() {
const [language, setLanguage] = useState('zh-CN')
const languageOptions = [
{ label: '中文', value: 'zh-CN' },
{ label: 'English', value: 'en-US' },
{ label: '日本語', value: 'ja-JP' }
]
return (
<Selector
selectedKeys={language}
onSelectionChange={(value) => {
// value 类型自动推断为 string
setLanguage(value)
}}
items={languageOptions}
placeholder="选择语言"
/>
)
}
```
### 多选模式
```tsx
import { Selector } from '@cherrystudio/ui'
import { useState } from 'react'
function Example() {
const [languages, setLanguages] = useState(['zh-CN', 'en-US'])
const languageOptions = [
{ label: '中文', value: 'zh-CN' },
{ label: 'English', value: 'en-US' },
{ label: '日本語', value: 'ja-JP' },
{ label: 'Français', value: 'fr-FR' }
]
return (
<Selector
selectionMode="multiple"
selectedKeys={languages}
onSelectionChange={(values) => {
// values 类型自动推断为 string[]
setLanguages(values)
}}
items={languageOptions}
placeholder="选择语言"
/>
)
}
```
### 数字类型值
```tsx
import { Selector } from '@cherrystudio/ui'
function Example() {
const [priority, setPriority] = useState<number>(1)
const priorityOptions = [
{ label: '低', value: 1 },
{ label: '中', value: 2 },
{ label: '高', value: 3 }
]
return (
<Selector<number>
selectedKeys={priority}
onSelectionChange={(value) => {
// value 类型为 number
setPriority(value)
}}
items={priorityOptions}
/>
)
}
```
### 禁用选项
```tsx
const options = [
{ label: '选项 1', value: '1' },
{ label: '选项 2 (禁用)', value: '2', disabled: true },
{ label: '选项 3', value: '3' }
]
<Selector
selectedKeys="1"
onSelectionChange={handleChange}
items={options}
/>
```
### 自定义 Label
```tsx
import { Flex } from '@cherrystudio/ui'
const options = [
{
label: (
<Flex className="items-center gap-2">
<span>🇨🇳</span>
<span>中文</span>
</Flex>
),
value: 'zh-CN'
},
{
label: (
<Flex className="items-center gap-2">
<span>🇺🇸</span>
<span>English</span>
</Flex>
),
value: 'en-US'
}
]
<Selector
selectedKeys="zh-CN"
onSelectionChange={handleChange}
items={options}
/>
```
## API
### SelectorProps
| 属性 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| `items` | `SelectorItem<V>[]` | - | 必填,选项列表 |
| `selectedKeys` | `V` \| `V[]` | - | 受控的选中值(单选为单个值,多选为数组) |
| `onSelectionChange` | `(key: V) => void` \| `(keys: V[]) => void` | - | 选择变化回调(类型根据 selectionMode 自动推断) |
| `selectionMode` | `'single'` \| `'multiple'` | `'single'` | 选择模式 |
| `placeholder` | `string` | - | 占位文本 |
| `disabled` | `boolean` | `false` | 是否禁用 |
| `isRequired` | `boolean` | `false` | 是否必填 |
| `label` | `ReactNode` | - | 标签文本 |
| `description` | `ReactNode` | - | 描述文本 |
| `errorMessage` | `ReactNode` | - | 错误提示 |
| ...rest | `SelectProps` | - | 其他 HeroUI Select 属性 |
### SelectorItem
```tsx
interface SelectorItem<V = string | number> {
label: string | ReactNode // 显示文本或自定义内容
value: V // 选项值
disabled?: boolean // 是否禁用
[key: string]: any // 其他自定义属性
}
```
## 类型安全
组件使用 TypeScript 条件类型,根据 `selectionMode` 自动推断回调类型:
```tsx
// 单选模式
<Selector
selectionMode="single" // 或省略(默认单选)
selectedKeys={value} // 类型: V
onSelectionChange={(v) => ...} // v 类型: V
/>
// 多选模式
<Selector
selectionMode="multiple"
selectedKeys={values} // 类型: V[]
onSelectionChange={(vs) => ...} // vs 类型: V[]
/>
```
## 与 HeroUI Select 的区别
| 特性 | HeroUI Select | Selector (本组件) |
|------|---------------|------------------|
| `selectedKeys` | `Set<Key> \| 'all'` | `V` \| `V[]` (自动转换) |
| `onSelectionChange` | `(keys: Selection) => void` | `(key: V) => void` \| `(keys: V[]) => void` |
| 单选回调 | 返回 `Set` (需手动提取) | 直接返回单个值 |
| 多选回调 | 返回 `Set` (需转数组) | 直接返回数组 |
| 类型推断 | 无 | 根据 selectionMode 自动推断 |
## 最佳实践
### 1. 显式声明 selectionMode
虽然单选是默认模式,但建议显式声明以提高代码可读性:
```tsx
// ✅ 推荐
<Selector selectionMode="single" ... />
// ⚠️ 可以但不够清晰
<Selector ... />
```
### 2. 使用泛型指定值类型
当值类型为数字或联合类型时,使用泛型获得更好的类型提示:
```tsx
// ✅ 推荐
<Selector<number> selectedKeys={priority} ... />
// ✅ 推荐(联合类型)
type Status = 'pending' | 'approved' | 'rejected'
<Selector<Status> selectedKeys={status} ... />
```
### 3. 避免在渲染时创建 items
```tsx
// ❌ 不推荐(每次渲染都创建新数组)
<Selector items={[{ label: 'A', value: '1' }]} />
// ✅ 推荐(在组件外或使用 useMemo
const items = [{ label: 'A', value: '1' }]
<Selector items={items} />
```
## 迁移指南
### 从 antd Select 迁移
```tsx
// antd Select
import { Select } from 'antd'
<Select
value={value}
onChange={(value) => onChange(value)}
options={[
{ label: 'A', value: '1' },
{ label: 'B', value: '2' }
]}
/>
// 迁移到 Selector
import { Selector } from '@cherrystudio/ui'
<Selector
selectedKeys={value} // value → selectedKeys
onSelectionChange={(value) => onChange(value)} // onChange → onSelectionChange
items={[ // options → items
{ label: 'A', value: '1' },
{ label: 'B', value: '2' }
]}
/>
```
### 从旧版 Selector 迁移
```tsx
// 旧版 Selector (返回数组)
<Selector
onSelectionChange={(values) => {
const value = values[0] // 需要手动提取
onChange(value)
}}
/>
// 新版 Selector (直接返回值)
<Selector
selectionMode="single"
onSelectionChange={(value) => {
onChange(value) // 直接使用
}}
/>
```
## 常见问题
### Q: 为什么单选模式下还需要 selectedKeys 而不是 selectedKey
A: 为了保持与 HeroUI API 命名的一致性,同时简化组件实现。组件内部会自动处理单个值和 Set 的转换。
### Q: 如何清空选择?
```tsx
// 单选模式
<Selector
selectedKeys={value}
onSelectionChange={setValue}
isClearable // 添加清空按钮
/>
// 或手动设置为 undefined
setValue(undefined)
```
### Q: 支持异步加载选项吗?
支持,配合 `isLoading` 属性使用:
```tsx
const [items, setItems] = useState([])
const [loading, setLoading] = useState(true)
useEffect(() => {
fetchItems().then(data => {
setItems(data)
setLoading(false)
})
}, [])
<Selector items={items} isLoading={loading} />
```

View File

@@ -0,0 +1,60 @@
import { Autocomplete, AutocompleteItem } from '@heroui/react'
import type { Key } from '@react-types/shared'
import { useMemo } from 'react'
import type { SearchableSelectorItem, SearchableSelectorProps } from './types'
const SearchableSelector = <T extends SearchableSelectorItem>(props: SearchableSelectorProps<T>) => {
const { items, onSelectionChange, selectedKeys, selectionMode = 'single', children, ...rest } = props
// 转换 selectedKeys: V | V[] → Key | undefined (Autocomplete 只支持单选)
const autocompleteSelectedKey = useMemo(() => {
if (selectedKeys === undefined) return undefined
if (selectionMode === 'multiple') {
// Autocomplete 不支持多选,取第一个
const keys = selectedKeys as T['value'][]
return keys.length > 0 ? String(keys[0]) : undefined
} else {
return String(selectedKeys)
}
}, [selectedKeys, selectionMode])
// 处理选择变化
const handleSelectionChange = (key: Key | null) => {
if (!onSelectionChange || key === null) return
const strKey = String(key)
// 尝试转换回数字类型
const num = Number(strKey)
const value = !isNaN(num) && items.some((item) => item.value === num) ? (num as T['value']) : (strKey as T['value'])
if (selectionMode === 'multiple') {
// 多选模式: 返回数组 (Autocomplete 只支持单选,这里简化处理)
;(onSelectionChange as (keys: T['value'][]) => void)([value])
} else {
// 单选模式: 返回单个值
;(onSelectionChange as (key: T['value']) => void)(value)
}
}
// 默认渲染函数
const defaultRenderItem = (item: T) => (
<AutocompleteItem key={String(item.value)} textValue={item.label ? String(item.label) : String(item.value)}>
{item.label ?? item.value}
</AutocompleteItem>
)
return (
<Autocomplete
{...rest}
items={items}
selectedKey={autocompleteSelectedKey}
onSelectionChange={handleSelectionChange}
allowsCustomValue={false}>
{children ?? defaultRenderItem}
</Autocomplete>
)
}
export default SearchableSelector

View File

@@ -0,0 +1,75 @@
import type { Selection } from '@heroui/react'
import { Select, SelectItem } from '@heroui/react'
import type { Key } from '@react-types/shared'
import { useMemo } from 'react'
import type { SelectorItem, SelectorProps } from './types'
const Selector = <T extends SelectorItem>(props: SelectorProps<T>) => {
const { items, onSelectionChange, selectedKeys, selectionMode = 'single', children, ...rest } = props
// 转换 selectedKeys: V | V[] | undefined → Set<Key> | undefined
const heroUISelectedKeys = useMemo(() => {
if (selectedKeys === undefined) return undefined
if (selectionMode === 'multiple') {
// 多选模式: V[] → Set<Key>
return new Set((selectedKeys as T['value'][]).map((key) => String(key) as Key))
} else {
// 单选模式: V → Set<Key>
return new Set([String(selectedKeys) as Key])
}
}, [selectedKeys, selectionMode])
// 处理选择变化,转换 Selection → V | V[]
const handleSelectionChange = (keys: Selection) => {
if (!onSelectionChange) return
if (keys === 'all') {
// 如果是全选,返回所有非禁用项的值
const allValues = items.filter((item) => !item.disabled).map((item) => item.value)
if (selectionMode === 'multiple') {
;(onSelectionChange as (keys: T['value'][]) => void)(allValues)
}
return
}
// 转换 Set<Key> 为原始类型
const keysArray = Array.from(keys).map((key) => {
const strKey = String(key)
// 尝试转换回数字类型(如果原始值是数字)
const num = Number(strKey)
return !isNaN(num) && items.some((item) => item.value === num) ? (num as T['value']) : (strKey as T['value'])
})
if (selectionMode === 'multiple') {
// 多选模式: 返回数组
;(onSelectionChange as (keys: T['value'][]) => void)(keysArray)
} else {
// 单选模式: 返回单个值
if (keysArray.length > 0) {
;(onSelectionChange as (key: T['value']) => void)(keysArray[0])
}
}
}
// 默认渲染函数
const defaultRenderItem = (item: T) => (
<SelectItem key={String(item.value)} textValue={item.label ? String(item.label) : String(item.value)}>
{item.label ?? item.value}
</SelectItem>
)
return (
<Select
{...rest}
items={items}
selectionMode={selectionMode}
selectedKeys={heroUISelectedKeys as 'all' | Iterable<Key> | undefined}
onSelectionChange={handleSelectionChange}>
{children ?? defaultRenderItem}
</Select>
)
}
export default Selector

View File

@@ -0,0 +1,13 @@
// 统一导出 Selector 相关组件和类型
export { default as SearchableSelector } from './SearchableSelector'
export { default } from './Selector'
export type {
MultipleSearchableSelectorProps,
MultipleSelectorProps,
SearchableSelectorItem,
SearchableSelectorProps,
SelectorItem,
SelectorProps,
SingleSearchableSelectorProps,
SingleSelectorProps
} from './types'

View File

@@ -0,0 +1,79 @@
import type { AutocompleteProps, SelectProps } from '@heroui/react'
import type { ReactElement, ReactNode } from 'react'
interface SelectorItem<V = string | number> {
label?: string | ReactNode
value: V
disabled?: boolean
[key: string]: any
}
// 自定义渲染函数类型
type SelectorRenderItem<T> = (item: T) => ReactElement
// 单选模式的 Props
interface SingleSelectorProps<T extends SelectorItem = SelectorItem>
extends Omit<SelectProps<T>, 'children' | 'onSelectionChange' | 'selectedKeys' | 'selectionMode'> {
items: T[]
selectionMode?: 'single'
selectedKeys?: T['value']
onSelectionChange?: (key: T['value']) => void
children?: SelectorRenderItem<T>
}
// 多选模式的 Props
interface MultipleSelectorProps<T extends SelectorItem = SelectorItem>
extends Omit<SelectProps<T>, 'children' | 'onSelectionChange' | 'selectedKeys' | 'selectionMode'> {
items: T[]
selectionMode: 'multiple'
selectedKeys?: T['value'][]
onSelectionChange?: (keys: T['value'][]) => void
children?: SelectorRenderItem<T>
}
type SelectorProps<T extends SelectorItem = SelectorItem> = SingleSelectorProps<T> | MultipleSelectorProps<T>
interface SearchableSelectorItem<V = string | number> {
label?: string | ReactNode
value: V
disabled?: boolean
[key: string]: any
}
// 自定义渲染函数类型
type SearchableRenderItem<T> = (item: T) => ReactElement
// 单选模式的 Props
interface SingleSearchableSelectorProps<T extends SearchableSelectorItem = SearchableSelectorItem>
extends Omit<AutocompleteProps<T>, 'children' | 'onSelectionChange' | 'selectedKey' | 'selectionMode'> {
items: T[]
selectionMode?: 'single'
selectedKeys?: T['value']
onSelectionChange?: (key: T['value']) => void
children?: SearchableRenderItem<T>
}
// 多选模式的 Props
interface MultipleSearchableSelectorProps<T extends SearchableSelectorItem = SearchableSelectorItem>
extends Omit<AutocompleteProps<T>, 'children' | 'onSelectionChange' | 'selectedKey' | 'selectionMode'> {
items: T[]
selectionMode: 'multiple'
selectedKeys?: T['value'][]
onSelectionChange?: (keys: T['value'][]) => void
children?: SearchableRenderItem<T>
}
type SearchableSelectorProps<T extends SearchableSelectorItem = SearchableSelectorItem> =
| SingleSearchableSelectorProps<T>
| MultipleSearchableSelectorProps<T>
export type {
MultipleSearchableSelectorProps,
MultipleSelectorProps,
SearchableSelectorItem,
SearchableSelectorProps,
SelectorItem,
SelectorProps,
SingleSearchableSelectorProps,
SingleSelectorProps
}

View File

@@ -0,0 +1,37 @@
// Original: src/renderer/src/components/Spinner.tsx
import { motion } from 'framer-motion'
import { Search } from 'lucide-react'
interface Props {
text: React.ReactNode
className?: string
}
// Define variants for the spinner animation
const spinnerVariants = {
defaultColor: {
color: '#2a2a2a'
},
dimmed: {
color: '#8C9296'
}
}
export default function Spinner({ text, className = '' }: Props) {
return (
<motion.div
className={`flex items-center gap-1 p-0 ${className}`}
variants={spinnerVariants}
initial="defaultColor"
animate={['defaultColor', 'dimmed']}
transition={{
duration: 0.8,
repeat: Infinity,
repeatType: 'reverse',
ease: 'easeInOut'
}}>
<Search size={16} style={{ color: 'unset' }} />
<span>{text}</span>
</motion.div>
)
}

View File

@@ -0,0 +1,53 @@
import type { LucideIcon } from 'lucide-react'
import { AlertTriangleIcon, CheckIcon, CircleXIcon, InfoIcon } from 'lucide-react'
import React from 'react'
import CustomTag from '../CustomTag'
export type StatusType = 'success' | 'error' | 'warning' | 'info'
export interface StatusTagProps {
type: StatusType
message: string
iconSize?: number
icon?: React.ReactNode
color?: string
className?: string
}
const statusConfig: Record<StatusType, { Icon: LucideIcon; color: string }> = {
success: { Icon: CheckIcon, color: '#10B981' }, // green-500
error: { Icon: CircleXIcon, color: '#EF4444' }, // red-500
warning: { Icon: AlertTriangleIcon, color: '#F59E0B' }, // amber-500
info: { Icon: InfoIcon, color: '#3B82F6' } // blue-500
}
export const StatusTag: React.FC<StatusTagProps> = ({ type, message, iconSize = 14, icon, color, className }) => {
const config = statusConfig[type]
const Icon = config.Icon
const finalColor = color || config.color
const finalIcon = icon || <Icon size={iconSize} color={finalColor} />
return (
<CustomTag icon={finalIcon} color={finalColor} className={className}>
{message}
</CustomTag>
)
}
// 保留原有的导出以保持向后兼容
export const SuccessTag = ({ iconSize, message }: { iconSize?: number; message: string }) => (
<StatusTag type="success" iconSize={iconSize} message={message} />
)
export const ErrorTag = ({ iconSize, message }: { iconSize?: number; message: string }) => (
<StatusTag type="error" iconSize={iconSize} message={message} />
)
export const WarnTag = ({ iconSize, message }: { iconSize?: number; message: string }) => (
<StatusTag type="warning" iconSize={iconSize} message={message} />
)
export const InfoTag = ({ iconSize, message }: { iconSize?: number; message: string }) => (
<StatusTag type="info" iconSize={iconSize} message={message} />
)

View File

@@ -0,0 +1,54 @@
import type { SwitchProps } from '@heroui/react'
import { cn, Spinner, Switch } from '@heroui/react'
// Enhanced Switch component with loading state support
interface CustomSwitchProps extends SwitchProps {
isLoading?: boolean
}
/**
* A customized Switch component based on HeroUI Switch
* @see https://www.heroui.com/docs/components/switch#api
* @param isLoading When true, displays a loading spinner in the switch thumb
*/
const CustomizedSwitch = ({ isLoading, children, ref, thumbIcon, ...props }: CustomSwitchProps) => {
const finalThumbIcon = isLoading ? <Spinner size="sm" /> : thumbIcon
return (
<Switch ref={ref} {...props} thumbIcon={finalThumbIcon}>
{children}
</Switch>
)
}
const DescriptionSwitch = ({ children, ...props }: CustomSwitchProps) => {
return (
<CustomizedSwitch
size="sm"
classNames={{
base: cn(
'inline-flex w-full max-w-md flex-row-reverse items-center hover:bg-content2',
'cursor-pointer justify-between gap-2 rounded-lg border-2 border-transparent py-2 pr-1',
'data-[selected=true]:border-primary'
),
wrapper: 'p-0 h-4 overflow-visible',
thumb: cn(
'h-6 w-6 border-2 shadow-lg',
'group-data-[hover=true]:border-primary',
//selected
'group-data-[selected=true]:ms-6',
// pressed
'group-data-[pressed=true]:w-7',
'group-data-pressed:group-data-selected:ms-4'
)
}}
{...props}>
{children}
</CustomizedSwitch>
)
}
CustomizedSwitch.displayName = 'Switch'
export { DescriptionSwitch, CustomizedSwitch as Switch }
export type { CustomSwitchProps as SwitchProps }

View File

@@ -0,0 +1,20 @@
// Original: src/renderer/src/components/TextBadge.tsx
import type { FC } from 'react'
interface TextBadgeProps {
text: string
style?: React.CSSProperties
className?: string
}
const TextBadge: FC<TextBadgeProps> = ({ text, style, className = '' }) => {
return (
<span
className={`text-xs text-blue-600 dark:text-blue-400 bg-blue-100 dark:bg-blue-900/30 px-1.5 py-0.5 rounded font-medium ${className}`}
style={style}>
{text}
</span>
)
}
export default TextBadge

View File

@@ -1,5 +1,6 @@
import { addToast, closeAll, closeToast, getToastQueue, isToastClosing } from '@heroui/toast'
import { RequireSome } from '@renderer/types'
import type { RequireSome } from '@/types'
type AddToastProps = Parameters<typeof addToast>[0]
type ToastPropsColored = Omit<AddToastProps, 'color'>
@@ -21,35 +22,35 @@ const createToast = (color: 'danger' | 'success' | 'warning' | 'default') => {
* @param arg - Toast content (string) or toast options object
* @returns Toast ID or null
*/
export const error = createToast('danger')
const error = createToast('danger')
/**
* Display a success toast notification with green color
* @param arg - Toast content (string) or toast options object
* @returns Toast ID or null
*/
export const success = createToast('success')
const success = createToast('success')
/**
* Display a warning toast notification with yellow color
* @param arg - Toast content (string) or toast options object
* @returns Toast ID or null
*/
export const warning = createToast('warning')
const warning = createToast('warning')
/**
* Display an info toast notification with default color
* @param arg - Toast content (string) or toast options object
* @returns Toast ID or null
*/
export const info = createToast('default')
const info = createToast('default')
/**
* Display a loading toast notification that resolves with a promise
* @param args - Toast options object containing a promise to resolve
* @returns Toast ID or null
*/
export const loading = (args: RequireSome<AddToastProps, 'promise'>) => {
const loading = (args: RequireSome<AddToastProps, 'promise'>) => {
// Disappear immediately by default
if (args.timeout === undefined) {
args.timeout = 1
@@ -57,7 +58,20 @@ export const loading = (args: RequireSome<AddToastProps, 'promise'>) => {
return addToast(args)
}
export const getToastUtilities = () =>
export type ToastUtilities = {
getToastQueue: typeof getToastQueue
addToast: typeof addToast
closeToast: typeof closeToast
closeAll: typeof closeAll
isToastClosing: typeof isToastClosing
error: typeof error
success: typeof success
warning: typeof warning
info: typeof info
loading: typeof loading
}
export const getToastUtilities = (): ToastUtilities =>
({
getToastQueue,
addToast,

View File

@@ -0,0 +1,34 @@
import type { TooltipProps as HeroUITooltipProps } from '@heroui/react'
import { cn, Tooltip as HeroUITooltip } from '@heroui/react'
export interface TooltipProps extends HeroUITooltipProps {}
/**
* Tooltip wrapper that applies consistent styling and arrow display.
* Differences from raw HeroUI Tooltip:
* 1. Defaults showArrow={true}
* 2. Merges a default max-w-60 class into the content slot, capping width at 240px.
* All other HeroUI Tooltip props/behaviors remain unchanged.
*
* @see https://www.heroui.com/docs/components/tooltip
*/
export const Tooltip = ({
children,
classNames,
showArrow,
...rest
}: Omit<TooltipProps, 'classNames'> & {
classNames?: TooltipProps['classNames'] & { placeholder?: string }
}) => {
return (
<HeroUITooltip
classNames={{
...classNames,
content: cn('max-w-60', classNames?.content)
}}
showArrow={showArrow ?? true}
{...rest}>
<div className={cn('relative z-10 inline-block', classNames?.placeholder)}>{children}</div>
</HeroUITooltip>
)
}

View File

@@ -0,0 +1,28 @@
// Original: src/renderer/src/components/Ellipsis/index.tsx
import type { HTMLAttributes } from 'react'
import { cn } from '../../../utils'
type Props = {
maxLine?: number
className?: string
ref?: React.Ref<HTMLDivElement>
} & HTMLAttributes<HTMLDivElement>
const Ellipsis = (props: Props) => {
const { maxLine = 1, children, className, ref, ...rest } = props
const ellipsisClasses = cn(
'overflow-hidden text-ellipsis',
maxLine > 1 ? `line-clamp-${maxLine} break-words` : 'block whitespace-nowrap',
className
)
return (
<div ref={ref} className={ellipsisClasses} {...rest}>
{children}
</div>
)
}
export default Ellipsis

View File

@@ -0,0 +1,50 @@
// Original: src/renderer/src/components/ExpandableText.tsx
import { Button } from '@heroui/react'
import { memo, useCallback, useState } from 'react'
interface ExpandableTextProps {
text: string
style?: React.CSSProperties
className?: string
expandText?: string
collapseText?: string
lineClamp?: number
ref?: React.RefObject<HTMLDivElement>
}
const ExpandableText = ({
text,
style,
className = '',
expandText = 'Expand',
collapseText = 'Collapse',
lineClamp = 1,
ref
}: ExpandableTextProps) => {
const [isExpanded, setIsExpanded] = useState(false)
const toggleExpand = useCallback(() => {
setIsExpanded((prev) => !prev)
}, [])
return (
<div
ref={ref}
className={`flex ${isExpanded ? 'flex-col' : 'flex-row items-center'} gap-2 ${className}`}
style={style}>
<div
className={`overflow-hidden ${
isExpanded ? '' : lineClamp === 1 ? 'text-ellipsis whitespace-nowrap' : `line-clamp-${lineClamp}`
} ${isExpanded ? '' : 'flex-1'}`}>
{text}
</div>
<Button size="sm" variant="light" color="primary" onClick={toggleExpand} className="min-w-fit px-2">
{isExpanded ? collapseText : expandText}
</Button>
</div>
)
}
ExpandableText.displayName = 'ExpandableText'
export default memo(ExpandableText)

View File

@@ -0,0 +1,61 @@
// Original path: src/renderer/src/components/ListItem/index.tsx
import { Tooltip } from '@heroui/react'
import type { ReactNode } from 'react'
import { cn } from '../../../utils'
interface ListItemProps {
active?: boolean
icon?: ReactNode
title: ReactNode
subtitle?: string
titleStyle?: React.CSSProperties
onClick?: () => void
rightContent?: ReactNode
style?: React.CSSProperties
className?: string
ref?: React.Ref<HTMLDivElement>
}
const ListItem = ({
active,
icon,
title,
subtitle,
titleStyle,
onClick,
rightContent,
style,
className,
ref
}: ListItemProps) => {
return (
<div
ref={ref}
className={cn(
'px-3 py-1.5 rounded-md text-xs flex flex-col justify-between relative cursor-pointer border border-transparent',
'hover:bg-gray-50 dark:hover:bg-gray-800',
active && 'bg-gray-50 dark:bg-gray-800 border-gray-200 dark:border-gray-700',
className
)}
onClick={onClick}
style={style}>
<div className="flex items-center gap-0.5 overflow-hidden text-xs">
{icon && <span className="flex items-center justify-center mr-2">{icon}</span>}
<div className="flex-1 flex flex-col overflow-hidden">
<Tooltip content={title}>
<div className="truncate text-gray-900 dark:text-gray-100" style={titleStyle}>
{title}
</div>
</Tooltip>
{subtitle && (
<div className="text-[10px] text-gray-500 dark:text-gray-400 mt-0.5 line-clamp-1">{subtitle}</div>
)}
</div>
{rightContent && <div className="ml-auto">{rightContent}</div>}
</div>
</div>
)
}
export default ListItem

View File

@@ -0,0 +1,23 @@
// Original path: src/renderer/src/components/MaxContextCount.tsx
import { Infinity as InfinityIcon } from 'lucide-react'
import type { CSSProperties } from 'react'
const MAX_CONTEXT_COUNT = 100
type Props = {
maxContext: number
style?: CSSProperties
size?: number
className?: string
ref?: React.Ref<HTMLSpanElement>
}
export default function MaxContextCount({ maxContext, style, size = 14, className, ref }: Props) {
return maxContext === MAX_CONTEXT_COUNT ? (
<InfinityIcon size={size} style={style} className={className} aria-label="infinity" />
) : (
<span ref={ref} style={style} className={className}>
{maxContext.toString()}
</span>
)
}

View File

@@ -0,0 +1,38 @@
import type { Variants } from 'motion/react'
export const lightbulbVariants: Variants = {
active: {
opacity: [1, 0.2, 1],
transition: {
duration: 1.2,
ease: 'easeInOut',
times: [0, 0.5, 1],
repeat: Infinity
}
},
idle: {
opacity: 1,
transition: {
duration: 0.3,
ease: 'easeInOut'
}
}
}
export const lightbulbSoftVariants: Variants = {
active: {
opacity: [1, 0.5, 1],
transition: {
duration: 2,
ease: 'easeInOut',
times: [0, 0.5, 1],
repeat: Infinity
}
},
idle: {
opacity: 1,
transition: {
duration: 0.3,
ease: 'easeInOut'
}
}
}

View File

@@ -0,0 +1,128 @@
// Original path: src/renderer/src/components/ThinkingEffect.tsx
import { isEqual } from 'lodash'
import { ChevronRight, Lightbulb } from 'lucide-react'
import { motion } from 'motion/react'
import React, { useEffect, useMemo, useState } from 'react'
import { cn } from '../../../utils'
import { lightbulbVariants } from './defaultVariants'
interface ThinkingEffectProps {
isThinking: boolean
thinkingTimeText: React.ReactNode
content: string
expanded: boolean
className?: string
ref?: React.Ref<HTMLDivElement>
}
const ThinkingEffect: React.FC<ThinkingEffectProps> = ({
isThinking,
thinkingTimeText,
content,
expanded,
className,
ref
}) => {
const [messages, setMessages] = useState<string[]>([])
useEffect(() => {
const allLines = (content || '').split('\n')
const newMessages = isThinking ? allLines.slice(0, -1) : allLines
const validMessages = newMessages.filter((line) => line.trim() !== '')
if (!isEqual(messages, validMessages)) {
setMessages(validMessages)
}
}, [content, isThinking, messages])
const showThinking = useMemo(() => {
return isThinking && !expanded
}, [expanded, isThinking])
const LINE_HEIGHT = 14
const containerHeight = useMemo(() => {
if (!showThinking || messages.length < 1) return 38
return Math.min(75, Math.max(messages.length + 1, 2) * LINE_HEIGHT + 25)
}, [showThinking, messages.length])
return (
<div
ref={ref}
style={{ height: containerHeight }}
className={cn(
'w-full rounded-xl overflow-hidden relative flex items-center border-0.5 border-gray-200 dark:border-gray-700 transition-all duration-150 pointer-events-none select-none',
expanded && 'rounded-b-none',
className
)}>
<div className="w-12 flex justify-center items-center h-full flex-shrink-0 relative pl-1.5 transition-all duration-150">
<motion.div
variants={lightbulbVariants}
animate={isThinking ? 'active' : 'idle'}
initial="idle"
className="flex justify-center items-center">
<Lightbulb
size={!showThinking || messages.length < 2 ? 20 : 30}
style={{ transition: 'width,height, 150ms' }}
/>
</motion.div>
</div>
<div className="flex-1 h-full py-1.5 overflow-hidden relative">
<div
className={cn(
'absolute inset-x-0 top-0 text-sm leading-3.5 font-medium py-2.5 z-50 transition-all duration-150',
(!showThinking || !messages.length) && 'pt-3'
)}>
{thinkingTimeText}
</div>
{showThinking && (
<div
className="w-full h-full relative"
style={{
mask: 'linear-gradient(to bottom, rgb(0 0 0 / 0%) 0%, rgb(0 0 0 / 0%) 35%, rgb(0 0 0 / 25%) 40%, rgb(0 0 0 / 100%) 90%, rgb(0 0 0 / 100%) 100%)'
}}>
<motion.div
className="w-full absolute top-full flex flex-col justify-end"
style={{
height: messages.length * LINE_HEIGHT
}}
initial={{
y: -2
}}
animate={{
y: -messages.length * LINE_HEIGHT - 2
}}
transition={{
duration: 0.15,
ease: 'linear'
}}>
{messages.map((message, index) => {
if (index < messages.length - 5) return null
return (
<div
key={index}
className="w-full leading-3.5 text-xs text-gray-600 dark:text-gray-300 whitespace-nowrap overflow-hidden text-ellipsis">
{message}
</div>
)
})}
</motion.div>
</div>
)}
</div>
<div
className={cn(
'w-10 flex justify-center items-center h-full flex-shrink-0 relative text-gray-400 dark:text-gray-500 transition-transform duration-150',
expanded && 'rotate-90'
)}>
<ChevronRight size={20} strokeWidth={1} />
</div>
</div>
)
}
export default ThinkingEffect

Some files were not shown because too many files have changed in this diff Show More