♻️ refactor(helpers): standardize file naming conventions and improve code organization

- Rename files to follow camelCase naming convention:
  • auth-header.js → authUtils.js
  • other.js → logUtils.js
  • rehypeSplitWordsIntoSpans.js → textAnimationUtils.js

- Update import paths in affected components:
  • Update exports in helpers/index.js
  • Fix import in LogsTable.js for logUtils
  • Fix import in MarkdownRenderer.js for textAnimationUtils

- Remove old files after successful migration

- Improve file naming clarity:
  • authUtils.js better describes authentication utilities
  • logUtils.js clearly indicates log processing functions
  • textAnimationUtils.js concisely describes text animation functionality

This refactoring enhances code maintainability and follows consistent naming patterns throughout the helpers directory.
This commit is contained in:
Apple\Apple
2025-06-03 16:13:50 +08:00
parent 8a65a4174a
commit a7535aab99
18 changed files with 28 additions and 23 deletions

View File

@@ -44,7 +44,7 @@ import {
stringToColor, stringToColor,
} from '../helpers/render'; } from '../helpers/render';
import Paragraph from '@douyinfe/semi-ui/lib/es/typography/paragraph'; import Paragraph from '@douyinfe/semi-ui/lib/es/typography/paragraph';
import { getLogOther } from '../helpers/other.js'; import { getLogOther } from '../helpers/logUtils.js';
import { import {
IconRefresh, IconRefresh,
IconSetting, IconSetting,

View File

@@ -1,6 +1,6 @@
import ReactMarkdown from 'react-markdown'; import ReactMarkdown from 'react-markdown';
import 'katex/dist/katex.min.css'; import 'katex/dist/katex.min.css';
import 'highlight.js/styles/default.css'; import 'highlight.js/styles/github.css';
import './markdown.css'; import './markdown.css';
import RemarkMath from 'remark-math'; import RemarkMath from 'remark-math';
import RemarkBreaks from 'remark-breaks'; import RemarkBreaks from 'remark-breaks';
@@ -16,7 +16,7 @@ import { Button, Tooltip, Toast } from '@douyinfe/semi-ui';
import { copy } from '../../../helpers/utils'; import { copy } from '../../../helpers/utils';
import { IconCopy } from '@douyinfe/semi-icons'; import { IconCopy } from '@douyinfe/semi-icons';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { rehypeSplitWordsIntoSpans } from '../../../utils/rehypeSplitWordsIntoSpans'; import { rehypeSplitWordsIntoSpans } from '../../../helpers/textAnimationUtils';
mermaid.initialize({ mermaid.initialize({
startOnLoad: false, startOnLoad: false,

View File

@@ -1,4 +1,4 @@
import { STORAGE_KEYS, DEFAULT_CONFIG } from '../../utils/constants'; import { STORAGE_KEYS, DEFAULT_CONFIG } from '../../constants/playground.constants';
const MESSAGES_STORAGE_KEY = 'playground_messages'; const MESSAGES_STORAGE_KEY = 'playground_messages';

View File

@@ -3,3 +3,4 @@ export * from './user.constants';
export * from './toast.constants'; export * from './toast.constants';
export * from './common.constant'; export * from './common.constant';
export * from './model.constants'; export * from './model.constants';
export * from './playground.constants';

View File

@@ -1,4 +1,8 @@
export * from './history'; export * from './history';
export * from './auth-header'; export * from './authUtils';
export * from './utils'; export * from './utils';
export * from './api'; export * from './api';
export * from './apiUtils';
export * from './messageUtils';
export * from './textAnimationUtils';
export * from './logUtils';

View File

@@ -1,4 +1,4 @@
import { THINK_TAG_REGEX, MESSAGE_ROLES } from './constants'; import { THINK_TAG_REGEX, MESSAGE_ROLES } from '../constants/playground.constants';
// 生成唯一ID // 生成唯一ID
let messageId = 4; let messageId = 4;

View File

@@ -6,15 +6,15 @@ import {
API_ENDPOINTS, API_ENDPOINTS,
MESSAGE_STATUS, MESSAGE_STATUS,
DEBUG_TABS DEBUG_TABS
} from '../utils/constants'; } from '../constants/playground.constants';
import { import {
buildApiPayload, buildApiPayload,
handleApiError handleApiError
} from '../utils/apiUtils'; } from '../helpers/apiUtils';
import { import {
processThinkTags, processThinkTags,
processIncompleteThinkTags processIncompleteThinkTags
} from '../utils/messageUtils'; } from '../helpers/messageUtils';
export const useApiRequest = ( export const useApiRequest = (
setMessage, setMessage,

View File

@@ -1,8 +1,8 @@
import { useCallback, useEffect } from 'react'; import { useCallback, useEffect } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { API, showError } from '../helpers/index.js'; import { API } from '../helpers/api';
import { API_ENDPOINTS } from '../utils/constants'; import { API_ENDPOINTS } from '../constants/playground.constants';
import { processModelsData, processGroupsData } from '../utils/apiUtils'; import { processModelsData, processGroupsData } from '../helpers/apiUtils';
export const useDataLoader = ( export const useDataLoader = (
userState, userState,

View File

@@ -1,8 +1,8 @@
import { useCallback } from 'react'; import { useCallback } from 'react';
import { Toast, Modal } from '@douyinfe/semi-ui'; import { Toast, Modal } from '@douyinfe/semi-ui';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { getTextContent } from '../utils/messageUtils'; import { getTextContent } from '../helpers/messageUtils';
import { ERROR_MESSAGES } from '../utils/constants'; import { ERROR_MESSAGES } from '../constants/playground.constants';
export const useMessageActions = (message, setMessage, onMessageSend, saveMessages) => { export const useMessageActions = (message, setMessage, onMessageSend, saveMessages) => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@@ -1,8 +1,8 @@
import { useCallback, useState, useRef } from 'react'; import { useCallback, useState, useRef } from 'react';
import { Toast, Modal } from '@douyinfe/semi-ui'; import { Toast, Modal } from '@douyinfe/semi-ui';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { getTextContent, buildApiPayload, createLoadingAssistantMessage } from '../utils/messageUtils'; import { getTextContent, buildApiPayload, createLoadingAssistantMessage } from '../helpers/messageUtils';
import { MESSAGE_ROLES } from '../utils/constants'; import { MESSAGE_ROLES } from '../constants/playground.constants';
export const useMessageEdit = ( export const useMessageEdit = (
setMessage, setMessage,

View File

@@ -1,7 +1,7 @@
import { useState, useCallback, useRef, useEffect } from 'react'; import { useState, useCallback, useRef, useEffect } from 'react';
import { DEFAULT_MESSAGES, DEFAULT_CONFIG, DEBUG_TABS, MESSAGE_STATUS } from '../utils/constants'; import { DEFAULT_MESSAGES, DEFAULT_CONFIG, DEBUG_TABS, MESSAGE_STATUS } from '../constants/playground.constants';
import { loadConfig, saveConfig, loadMessages, saveMessages } from '../components/playground/configStorage'; import { loadConfig, saveConfig, loadMessages, saveMessages } from '../components/playground/configStorage';
import { processIncompleteThinkTags } from '../utils/messageUtils'; import { processIncompleteThinkTags } from '../helpers/messageUtils';
export const usePlaygroundState = () => { export const usePlaygroundState = () => {
// 使用惰性初始化,确保只在组件首次挂载时加载配置和消息 // 使用惰性初始化,确保只在组件首次挂载时加载配置和消息

View File

@@ -1,5 +1,5 @@
import { useCallback, useRef } from 'react'; import { useCallback, useRef } from 'react';
import { MESSAGE_ROLES } from '../utils/constants'; import { MESSAGE_ROLES } from '../constants/playground.constants';
export const useSyncMessageAndCustomBody = ( export const useSyncMessageAndCustomBody = (
customRequestMode, customRequestMode,

View File

@@ -22,14 +22,14 @@ import {
DEFAULT_MESSAGES, DEFAULT_MESSAGES,
MESSAGE_ROLES, MESSAGE_ROLES,
ERROR_MESSAGES ERROR_MESSAGES
} from '../../utils/constants.js'; } from '../../constants/playground.constants.js';
import { import {
buildMessageContent, buildMessageContent,
createMessage, createMessage,
createLoadingAssistantMessage, createLoadingAssistantMessage,
getTextContent, getTextContent,
buildApiPayload buildApiPayload
} from '../../utils/messageUtils.js'; } from '../../helpers/messageUtils.js';
// Components // Components
import { import {