Files
FastGPT/packages/global/core/app/utils.ts
Archer 095b75ee27 V4.9.12 feature (#5022)
* New chatinput (#4995)

* feat: Change border style

* refactor: Improve layout and styling of ChatInput component

* style: Update ChatInput component styling and mobile layout

* fix: update key detection for Enter key in ChatInput component

* feat: 添加 WelcomePage 组件,支持变量输入和欢迎信息展示

* style: Updated the PC voice input interface of the VoiceInput component and optimized the layout and style

* style: Optimize the layout and style of the WelcomePage component, and adjust the responsive design

* feat: Dynamically load the WelcomePage component and optimize the welcome information display logic

* refactor: Adjust the style and behavior of the ChatInput component and delete the WelcomePage component

* style: Modify the minimum height setting of the ChatInput component to simplify responsive design

* style: Optimize the layout and style of PC voice input components, and enhance the processing and drawing logic of waveform data

* style: Adjust ChatInput component's margin and textarea height logic for improved layout and responsiveness; refine PCVoiceInput component's positioning and display elements

* style: Enhance PCVoiceInput component's time display styling with custom font properties

* feat: Change border style

* refactor: Improve layout and styling of ChatInput component

* style: Update ChatInput component styling and mobile layout

* fix: update key detection for Enter key in ChatInput component

* feat: 添加 WelcomePage 组件,支持变量输入和欢迎信息展示

* style: Updated the PC voice input interface of the VoiceInput component and optimized the layout and style

* style: Optimize the layout and style of the WelcomePage component, and adjust the responsive design

* feat: Dynamically load the WelcomePage component and optimize the welcome information display logic

* refactor: Adjust the style and behavior of the ChatInput component and delete the WelcomePage component

* style: Modify the minimum height setting of the ChatInput component to simplify responsive design

* style: Optimize the layout and style of PC voice input components, and enhance the processing and drawing logic of waveform data

* style: Adjust ChatInput component's margin and textarea height logic for improved layout and responsiveness; refine PCVoiceInput component's positioning and display elements

* style: Enhance PCVoiceInput component's time display styling with custom font properties

* style: Add new 'xxl' size to theme spacing for improved layout options

* style: Update close icon fill color to use currentColor for better theming support

* style: Enhance voice input functionality and UI responsiveness; improve waveform sensitivity and amplitude

* style: Conditionally render file preview based on voice input state

* style: 优化移动端音频波形渲染,增强清晰度和敏感度

* style: Update comments to English to enhance code readability and consistency

* style: Adjust the mobile audio waveform update frequency and optimize rendering performance

* style: Optimize the file preview rendering logic in voice input mode to enhance user experience

* style: Optimize the file preview rendering logic in voice input mode to enhance user experience

* style: Adjust the chat input box placeholder color and border color to enhance visual effects

* fix: pg test

* Test secret (#5011)

* add http header auth config (#4982)

* add http header auth config

* optimize code

* add mcp tools header auth

* fix build

* fix ui

* fix

* teamid

* secret value encrypt (#5002)

* perf: secret code

* header auth ui (#5012)

* header auth ui

* fix i18n

* doc

* perf: type

* header secret ui

* reset ui

* perf: check secret invalid

---------

Co-authored-by: heheer <heheer@sealos.io>

* feat: cq and extrat AI memory (#5013)

* fix: login xss

* feat: Users can download the invoice by self (#5015)

* Users can download the invoice by themselves

* Direct file stream implementation for transmission presentation

* i18n

* Chatbox-fix (#5018)

* feat: Change border style

* refactor: Improve layout and styling of ChatInput component

* style: Update ChatInput component styling and mobile layout

* fix: update key detection for Enter key in ChatInput component

* feat: 添加 WelcomePage 组件,支持变量输入和欢迎信息展示

* style: Updated the PC voice input interface of the VoiceInput component and optimized the layout and style

* style: Optimize the layout and style of the WelcomePage component, and adjust the responsive design

* feat: Dynamically load the WelcomePage component and optimize the welcome information display logic

* refactor: Adjust the style and behavior of the ChatInput component and delete the WelcomePage component

* style: Modify the minimum height setting of the ChatInput component to simplify responsive design

* style: Optimize the layout and style of PC voice input components, and enhance the processing and drawing logic of waveform data

* style: Adjust ChatInput component's margin and textarea height logic for improved layout and responsiveness; refine PCVoiceInput component's positioning and display elements

* style: Enhance PCVoiceInput component's time display styling with custom font properties

* feat: Change border style

* refactor: Improve layout and styling of ChatInput component

* style: Update ChatInput component styling and mobile layout

* fix: update key detection for Enter key in ChatInput component

* feat: 添加 WelcomePage 组件,支持变量输入和欢迎信息展示

* style: Updated the PC voice input interface of the VoiceInput component and optimized the layout and style

* style: Optimize the layout and style of the WelcomePage component, and adjust the responsive design

* feat: Dynamically load the WelcomePage component and optimize the welcome information display logic

* refactor: Adjust the style and behavior of the ChatInput component and delete the WelcomePage component

* style: Modify the minimum height setting of the ChatInput component to simplify responsive design

* style: Optimize the layout and style of PC voice input components, and enhance the processing and drawing logic of waveform data

* style: Adjust ChatInput component's margin and textarea height logic for improved layout and responsiveness; refine PCVoiceInput component's positioning and display elements

* style: Enhance PCVoiceInput component's time display styling with custom font properties

* style: Add new 'xxl' size to theme spacing for improved layout options

* style: Update close icon fill color to use currentColor for better theming support

* style: Enhance voice input functionality and UI responsiveness; improve waveform sensitivity and amplitude

* style: Conditionally render file preview based on voice input state

* style: 优化移动端音频波形渲染,增强清晰度和敏感度

* style: Update comments to English to enhance code readability and consistency

* style: Adjust the mobile audio waveform update frequency and optimize rendering performance

* style: Optimize the file preview rendering logic in voice input mode to enhance user experience

* style: Optimize the file preview rendering logic in voice input mode to enhance user experience

* style: Adjust the chat input box placeholder color and border color to enhance visual effects

* New chatinput (#4995)

* feat: Change border style

* refactor: Improve layout and styling of ChatInput component

* style: Update ChatInput component styling and mobile layout

* fix: update key detection for Enter key in ChatInput component

* feat: 添加 WelcomePage 组件,支持变量输入和欢迎信息展示

* style: Updated the PC voice input interface of the VoiceInput component and optimized the layout and style

* style: Optimize the layout and style of the WelcomePage component, and adjust the responsive design

* feat: Dynamically load the WelcomePage component and optimize the welcome information display logic

* refactor: Adjust the style and behavior of the ChatInput component and delete the WelcomePage component

* style: Modify the minimum height setting of the ChatInput component to simplify responsive design

* style: Optimize the layout and style of PC voice input components, and enhance the processing and drawing logic of waveform data

* style: Adjust ChatInput component's margin and textarea height logic for improved layout and responsiveness; refine PCVoiceInput component's positioning and display elements

* style: Enhance PCVoiceInput component's time display styling with custom font properties

* feat: Change border style

* refactor: Improve layout and styling of ChatInput component

* style: Update ChatInput component styling and mobile layout

* fix: update key detection for Enter key in ChatInput component

* feat: 添加 WelcomePage 组件,支持变量输入和欢迎信息展示

* style: Updated the PC voice input interface of the VoiceInput component and optimized the layout and style

* style: Optimize the layout and style of the WelcomePage component, and adjust the responsive design

* feat: Dynamically load the WelcomePage component and optimize the welcome information display logic

* refactor: Adjust the style and behavior of the ChatInput component and delete the WelcomePage component

* style: Modify the minimum height setting of the ChatInput component to simplify responsive design

* style: Optimize the layout and style of PC voice input components, and enhance the processing and drawing logic of waveform data

* style: Adjust ChatInput component's margin and textarea height logic for improved layout and responsiveness; refine PCVoiceInput component's positioning and display elements

* style: Enhance PCVoiceInput component's time display styling with custom font properties

* style: Add new 'xxl' size to theme spacing for improved layout options

* style: Update close icon fill color to use currentColor for better theming support

* style: Enhance voice input functionality and UI responsiveness; improve waveform sensitivity and amplitude

* style: Conditionally render file preview based on voice input state

* style: 优化移动端音频波形渲染,增强清晰度和敏感度

* style: Update comments to English to enhance code readability and consistency

* style: Adjust the mobile audio waveform update frequency and optimize rendering performance

* style: Optimize the file preview rendering logic in voice input mode to enhance user experience

* style: Optimize the file preview rendering logic in voice input mode to enhance user experience

* style: Adjust the chat input box placeholder color and border color to enhance visual effects

* fix: pg test

* Test secret (#5011)

* add http header auth config (#4982)

* add http header auth config

* optimize code

* add mcp tools header auth

* fix build

* fix ui

* fix

* teamid

* secret value encrypt (#5002)

* perf: secret code

* header auth ui (#5012)

* header auth ui

* fix i18n

* doc

* perf: type

* header secret ui

* reset ui

* perf: check secret invalid

---------

Co-authored-by: heheer <heheer@sealos.io>

* feat: cq and extrat AI memory (#5013)

* refactor: Refactored the ChatInput component, optimized the layout of the text area and button group, and improved the user experience

* refactor: Updated ChatInput component, optimized layout and style, and enhanced user experience

* feat: update docs

---------

Co-authored-by: archer <545436317@qq.com>
Co-authored-by: heheer <heheer@sealos.io>

* input ui

* fix: chat input ux

* Return in JSON format to handle checkres (#5019)

* Users can download the invoice by themselves

* Direct file stream implementation for transmission presentation

* Return in JSON format to handle checkres

* fix: invoice

* fix: ui

* doc

* update package

* fix: ts

* fix: login checker

* fix: team plan

* perf: aiproxy ux

---------

Co-authored-by: Theresa <63280168+sd0ric4@users.noreply.github.com>
Co-authored-by: heheer <heheer@sealos.io>
Co-authored-by: Zhuangzai fa <143257420+ctrlz526@users.noreply.github.com>
2025-06-13 00:42:09 +08:00

199 lines
6.5 KiB
TypeScript

import type { AppChatConfigType, AppSimpleEditFormType } from '../app/type';
import { FlowNodeTypeEnum } from '../workflow/node/constant';
import { NodeInputKeyEnum, FlowNodeTemplateTypeEnum } from '../workflow/constants';
import type { FlowNodeInputItemType } from '../workflow/type/io.d';
import { getAppChatConfig } from '../workflow/utils';
import { type StoreNodeItemType } from '../workflow/type/node';
import { DatasetSearchModeEnum } from '../dataset/constants';
import { type WorkflowTemplateBasicType } from '../workflow/type';
import { AppTypeEnum } from './constants';
import appErrList from '../../common/error/code/app';
import pluginErrList from '../../common/error/code/plugin';
export const getDefaultAppForm = (): AppSimpleEditFormType => {
return {
aiSettings: {
model: 'gpt-4o-mini',
systemPrompt: '',
temperature: 0,
isResponseAnswerText: true,
maxHistories: 6,
maxToken: 4000,
aiChatReasoning: true
},
dataset: {
datasets: [],
similarity: 0.4,
limit: 3000,
searchMode: DatasetSearchModeEnum.embedding,
usingReRank: true,
rerankModel: '',
rerankWeight: 0.5,
datasetSearchUsingExtensionQuery: true,
datasetSearchExtensionBg: ''
},
selectedTools: [],
chatConfig: {}
};
};
/* format app nodes to edit form */
export const appWorkflow2Form = ({
nodes,
chatConfig
}: {
nodes: StoreNodeItemType[];
chatConfig: AppChatConfigType;
}) => {
const defaultAppForm = getDefaultAppForm();
const findInputValueByKey = (inputs: FlowNodeInputItemType[], key: string) => {
return inputs.find((item) => item.key === key)?.value;
};
nodes.forEach((node) => {
if (
node.flowNodeType === FlowNodeTypeEnum.chatNode ||
node.flowNodeType === FlowNodeTypeEnum.tools
) {
defaultAppForm.aiSettings.model = findInputValueByKey(node.inputs, NodeInputKeyEnum.aiModel);
defaultAppForm.aiSettings.systemPrompt = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.aiSystemPrompt
);
defaultAppForm.aiSettings.temperature = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.aiChatTemperature
);
defaultAppForm.aiSettings.maxToken = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.aiChatMaxToken
);
defaultAppForm.aiSettings.maxHistories = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.history
);
defaultAppForm.aiSettings.aiChatReasoning = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.aiChatReasoning
);
defaultAppForm.aiSettings.aiChatTopP = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.aiChatTopP
);
defaultAppForm.aiSettings.aiChatStopSign = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.aiChatStopSign
);
defaultAppForm.aiSettings.aiChatResponseFormat = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.aiChatResponseFormat
);
defaultAppForm.aiSettings.aiChatJsonSchema = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.aiChatJsonSchema
);
} else if (node.flowNodeType === FlowNodeTypeEnum.datasetSearchNode) {
defaultAppForm.dataset.datasets = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSelectList
);
defaultAppForm.dataset.similarity = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSimilarity
);
defaultAppForm.dataset.limit = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetMaxTokens
);
defaultAppForm.dataset.searchMode =
findInputValueByKey(node.inputs, NodeInputKeyEnum.datasetSearchMode) ||
DatasetSearchModeEnum.embedding;
defaultAppForm.dataset.embeddingWeight = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSearchEmbeddingWeight
);
// Rerank
defaultAppForm.dataset.usingReRank = !!findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSearchUsingReRank
);
defaultAppForm.dataset.rerankModel = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSearchRerankModel
);
defaultAppForm.dataset.rerankWeight = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSearchRerankWeight
);
// Query extension
defaultAppForm.dataset.datasetSearchUsingExtensionQuery = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSearchUsingExtensionQuery
);
defaultAppForm.dataset.datasetSearchExtensionModel = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSearchExtensionModel
);
defaultAppForm.dataset.datasetSearchExtensionBg = findInputValueByKey(
node.inputs,
NodeInputKeyEnum.datasetSearchExtensionBg
);
} else if (
node.flowNodeType === FlowNodeTypeEnum.pluginModule ||
node.flowNodeType === FlowNodeTypeEnum.appModule ||
node.flowNodeType === FlowNodeTypeEnum.tool ||
node.flowNodeType === FlowNodeTypeEnum.toolSet
) {
if (!node.pluginId) return;
defaultAppForm.selectedTools.push({
id: node.nodeId,
pluginId: node.pluginId,
name: node.name,
avatar: node.avatar,
intro: node.intro || '',
flowNodeType: node.flowNodeType,
showStatus: node.showStatus,
version: node.version,
inputs: node.inputs,
outputs: node.outputs,
templateType: FlowNodeTemplateTypeEnum.other,
pluginData: node.pluginData
});
} else if (node.flowNodeType === FlowNodeTypeEnum.systemConfig) {
defaultAppForm.chatConfig = getAppChatConfig({
chatConfig,
systemConfigNode: node,
isPublicFetch: true
});
}
});
return defaultAppForm;
};
export const getAppType = (config?: WorkflowTemplateBasicType | AppSimpleEditFormType) => {
if (!config) return '';
if ('aiSettings' in config) {
return AppTypeEnum.simple;
}
if (!('nodes' in config)) return '';
if (config.nodes.some((node) => node.flowNodeType === 'workflowStart')) {
return AppTypeEnum.workflow;
}
if (config.nodes.some((node) => node.flowNodeType === 'pluginInput')) {
return AppTypeEnum.plugin;
}
return '';
};
export const formatToolError = (error?: any) => {
if (!error || typeof error !== 'string') return;
const errorText = appErrList[error]?.message || pluginErrList[error]?.message;
return errorText || error;
};