diff --git a/config/config.ts b/config/config.ts index 961eb601..7c1e7492 100644 --- a/config/config.ts +++ b/config/config.ts @@ -1,4 +1,5 @@ import { defineConfig } from '@umijs/max'; +import keepAlive from './keep-alive'; import proxy from './proxy'; import routes from './routes'; import theme from './theme'; @@ -90,7 +91,7 @@ export default defineConfig({ model: {}, initialState: {}, request: {}, - keepalive: ['/playground/text-to-image', '/playground/speech'], + keepalive: keepAlive, locale: { antd: true, baseNavigator: true, diff --git a/config/keep-alive.ts b/config/keep-alive.ts new file mode 100644 index 00000000..8987e8d7 --- /dev/null +++ b/config/keep-alive.ts @@ -0,0 +1,6 @@ +export const keepAliveRoutes = { + text2images: '/playground/text-to-image', + speech: '/playground/speech' +}; + +export default [keepAliveRoutes.text2images, keepAliveRoutes.speech]; diff --git a/config/routes.ts b/config/routes.ts index 1abe3e49..cb4f7826 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -1,3 +1,5 @@ +import { keepAliveRoutes } from './keep-alive'; + export default [ { name: 'dashboard', @@ -28,7 +30,7 @@ export default [ { name: 'text2images', title: 'Text2Images', - path: '/playground/text-to-image', + path: keepAliveRoutes.text2images, key: 'text2images', icon: 'Comment', component: './playground/images' @@ -36,7 +38,7 @@ export default [ { name: 'speech', title: 'Speech', - path: '/playground/speech', + path: keepAliveRoutes.speech, key: 'speech', icon: 'Comment', component: './playground/speech' diff --git a/src/assets/styles/menu.less b/src/assets/styles/menu.less index 2aa4ae8b..e54340ad 100644 --- a/src/assets/styles/menu.less +++ b/src/assets/styles/menu.less @@ -1,8 +1,5 @@ .ant-pro-layout { .ant-pro-sider { - // &.ant-layout-sider { - // background: var(--color-white-1); - // } .ant-layout-sider-children { background-color: var(--color-fill-1); border-inline: none; diff --git a/src/components/logs-viewer/parse-ansi.ts b/src/components/logs-viewer/parse-ansi.ts deleted file mode 100644 index 255c6fbe..00000000 --- a/src/components/logs-viewer/parse-ansi.ts +++ /dev/null @@ -1,141 +0,0 @@ -import { controlSeqRegex } from './config'; - -const useParseAnsi = () => { - const removeBrackets = (str: string) => { - return str?.replace?.(/^\(…\)/, ''); - }; - - const isClean = (input: string) => { - let match = controlSeqRegex.exec(input) || []; - const command = match?.[3]; - const n = parseInt(match?.[1], 10) || 1; - return command === 'J' && n === 2; - }; - - const parseAnsi = (input: string, setId: () => number) => { - let cursorRow = 0; - let cursorCol = 0; - let screen = [['']]; - let lastIndex = 0; - - // let input = inputStr.replace(replaceLineRegex, '\n'); - - // handle the \r and \n characters in the text - const handleText = (text: string) => { - let processed = ''; - for (let char of text) { - if (char === '\r') { - cursorCol = 0; // move to the beginning of the line - } else if (char === '\n') { - cursorRow++; // move to the next line - cursorCol = 0; // move to the beginning of the line - screen[cursorRow] = screen[cursorRow] || ['']; // create a new line if it does not exist - } else { - // add the character to the screen content array - screen[cursorRow][cursorCol] = char; - cursorCol++; - } - } - return processed; - }; - - let output = ''; // output text - - let match; - - // ANSI color map - const colorMap: Record = { - '30': 'black', - '31': 'red', - '32': 'green', - '33': 'yellow', - '34': 'blue', - '35': 'magenta', - '36': 'cyan', - '37': 'white' - }; - - let currentStyle = ''; // current text style - - // match ANSI control characters - while ((match = controlSeqRegex.exec(input)) !== null) { - // handle text before the control character - let textBeforeControl = input.slice(lastIndex, match.index); - output += handleText(textBeforeControl); // add the processed text to the output - lastIndex = controlSeqRegex.lastIndex; // update the last index - - const n = parseInt(match[1], 10) || 1; - const m = parseInt(match[2], 10) || 1; - const command = match[3]; - - // handle ANSI control characters - switch (command) { - case 'A': // up - cursorRow = Math.max(0, cursorRow - n); - if (cursorRow === 0) { - // screen = [['']]; - // cursorCol = 0; - } - break; - case 'B': // down - cursorRow += n; - break; - case 'C': // right - cursorCol += n; - break; - case 'D': // left - cursorCol = Math.max(0, cursorCol - n); - break; - case 'H': // move the cursor to the specified position (n, m) - cursorRow = Math.max(0, n - 1); - cursorCol = Math.max(0, m - 1); - break; - case 'J': // clear the screen - if (n === 2) { - screen = [['']]; - cursorRow = 0; - cursorCol = 0; - } - break; - case 'm': - // if (match[1] === '0') { - // currentStyle = ''; - // } else if (colorMap[match[1]]) { - // currentStyle = `color: ${colorMap[match[1]]};`; - // } - break; - } - - // check if the row and column are within the screen content array - while (screen.length <= cursorRow) { - screen.push(['']); - } - while (screen[cursorRow].length <= cursorCol) { - screen[cursorRow].push(''); - } - } - - // handle the remaining text - output += handleText(input.slice(lastIndex)); - - let result = []; - for (let row = 0; row < screen.length; row++) { - let rowContent = screen[row].join(''); - result.push({ - content: removeBrackets(rowContent), - uid: setId() - }); - } - - result.push({ - content: output, - uid: setId() - }); - - return result; - }; - - return { parseAnsi, isClean }; -}; - -export default useParseAnsi; diff --git a/src/global.less b/src/global.less index 03574c84..0bb1a42a 100644 --- a/src/global.less +++ b/src/global.less @@ -390,6 +390,12 @@ body { .ant-pro-layout { height: 100vh; + .ant-menu-inline-collapsed { + .anticon { + font-size: 16px; + } + } + .ant-pro-page-container-children-container { padding-block: var(--layout-content-blockpadding); padding-inline: var(--layout-content-inlinepadding); diff --git a/src/pages/playground/components/ground-images.tsx b/src/pages/playground/components/ground-images.tsx index 108c0238..3ac7a863 100644 --- a/src/pages/playground/components/ground-images.tsx +++ b/src/pages/playground/components/ground-images.tsx @@ -386,9 +386,9 @@ const GroundImages: React.FC = forwardRef((props, ref) => { } }; const handleClear = () => { - setMessageId(); - setImageList([]); - setTokenResult(null); + // setMessageId(); + // setImageList([]); + // setTokenResult(null); }; const handleInputChange = (e: any) => { diff --git a/src/pages/playground/components/multiple-chat/content-item.tsx b/src/pages/playground/components/multiple-chat/content-item.tsx index 3c42c176..1542f938 100644 --- a/src/pages/playground/components/multiple-chat/content-item.tsx +++ b/src/pages/playground/components/multiple-chat/content-item.tsx @@ -15,6 +15,11 @@ interface MessageItemProps { onDelete?: () => void; } +const contentRenderOptions = [ + { label: 'Markdown', value: 'markdown' }, + { label: 'Plain Text', value: 'plain' } +]; + const ContentItem: React.FC = ({ updateMessage, onDelete,