From 93a7786c4aae7e85c71b0665a22c26710d795811 Mon Sep 17 00:00:00 2001 From: heheer <1239331448@qq.com> Date: Thu, 21 Nov 2024 15:40:52 +0800 Subject: [PATCH] plugin usage --- packages/global/core/workflow/type/index.d.ts | 2 +- packages/global/core/workflow/type/node.d.ts | 1 + .../service/core/app/plugin/controller.ts | 6 +- packages/service/core/app/plugin/type.d.ts | 2 +- packages/service/core/app/plugin/utils.ts | 37 +-- .../core/workflow/dispatch/plugin/run.ts | 2 +- .../web/components/common/Icon/constants.ts | 3 - .../common/Icon/icons/common/pluginFill.svg | 10 - .../components/common/Icon/icons/store.svg | 5 - .../common/Icon/icons/storeFill.svg | 4 - packages/web/i18n/en/common.json | 1 - packages/web/i18n/zh-CN/common.json | 1 - .../Flow/NodeTemplatesModal.tsx | 240 +++++++++--------- 13 files changed, 157 insertions(+), 157 deletions(-) delete mode 100644 packages/web/components/common/Icon/icons/common/pluginFill.svg delete mode 100644 packages/web/components/common/Icon/icons/store.svg delete mode 100644 packages/web/components/common/Icon/icons/storeFill.svg diff --git a/packages/global/core/workflow/type/index.d.ts b/packages/global/core/workflow/type/index.d.ts index 332f90e70a9..d6aaca53313 100644 --- a/packages/global/core/workflow/type/index.d.ts +++ b/packages/global/core/workflow/type/index.d.ts @@ -63,7 +63,7 @@ export type TemplateMarketListItemType = { // system plugin export type SystemPluginTemplateItemType = WorkflowTemplateType & { customWorkflow?: string; - associatedPlugin?: Omit; + associatedPlugin?: SystemPluginListItemType; userGuide?: string; templateType: string; diff --git a/packages/global/core/workflow/type/node.d.ts b/packages/global/core/workflow/type/node.d.ts index 54b897d7659..2359ac0ee70 100644 --- a/packages/global/core/workflow/type/node.d.ts +++ b/packages/global/core/workflow/type/node.d.ts @@ -85,6 +85,7 @@ export type NodeTemplateListItemType = { author?: string; unique?: boolean; // 唯一的 currentCost?: number; // 当前积分消耗 + hasTokenFee?: boolean; // 是否配置积分 instructions?: string; // 使用说明 }; diff --git a/packages/service/core/app/plugin/controller.ts b/packages/service/core/app/plugin/controller.ts index ec4a912f3a3..f708369ca20 100644 --- a/packages/service/core/app/plugin/controller.ts +++ b/packages/service/core/app/plugin/controller.ts @@ -78,7 +78,8 @@ export async function getChildAppPreviewNode({ version: version.versionId, originCost: 0, currentCost: 0, - hasTokenFee: false + hasTokenFee: false, + pluginOrder: 0 }; } else { return getSystemPluginTemplateById(pluginId); @@ -163,7 +164,8 @@ export async function getChildAppRuntimeById( version: item?.pluginData?.nodeVersion || defaultNodeVersion, originCost: 0, currentCost: 0, - hasTokenFee: false + hasTokenFee: false, + pluginOrder: 0 }; } else { return getSystemPluginTemplateById(pluginId); diff --git a/packages/service/core/app/plugin/type.d.ts b/packages/service/core/app/plugin/type.d.ts index 17354210fab..d2cd04a8505 100644 --- a/packages/service/core/app/plugin/type.d.ts +++ b/packages/service/core/app/plugin/type.d.ts @@ -23,7 +23,7 @@ export type SystemPluginConfigSchemaType = { weight?: number; workflow: WorkflowTemplateBasicType; templateType: string; - associatedPlugin: Omit; + associatedPlugin: SystemPluginListItemType; userGuide: string; }; }; diff --git a/packages/service/core/app/plugin/utils.ts b/packages/service/core/app/plugin/utils.ts index 06222773c88..6a28543ffef 100644 --- a/packages/service/core/app/plugin/utils.ts +++ b/packages/service/core/app/plugin/utils.ts @@ -1,22 +1,29 @@ -import { PluginRuntimeType } from '@fastgpt/global/core/workflow/runtime/type'; import { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type'; -import { splitCombinePluginId } from './controller'; -import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants'; +import { SystemPluginTemplateItemType } from '@fastgpt/global/core/workflow/type'; /* - 1. Commercial plugin: n points per times - 2. Other plugin: sum of children points + Plugin points calculation: + 1. Return 0 if error + 2. Add configured points if commercial plugin + 3. Add sum of child nodes points */ -export const computedPluginUsage = async ( - plugin: PluginRuntimeType, - childrenUsage: ChatNodeUsageType[] -) => { - // const { source } = await splitCombinePluginId(plugin.id); +export const computedPluginUsage = async ({ + plugin, + childrenUsage, + error +}: { + plugin?: SystemPluginTemplateItemType; + childrenUsage: ChatNodeUsageType[]; + error?: boolean; +}) => { + if (error) { + return 0; + } - // Commercial plugin: n points per times - // if (source === PluginSourceEnum.commercial) { - // return plugin.currentCost ?? 0; - // } + let tokenFee = 0; + if (plugin && plugin.hasTokenFee) { + tokenFee = plugin.currentCost ?? 0; + } - return childrenUsage.reduce((sum, item) => sum + (item.totalPoints || 0), 0); + return tokenFee + childrenUsage.reduce((sum, item) => sum + (item.totalPoints || 0), 0); }; diff --git a/packages/service/core/workflow/dispatch/plugin/run.ts b/packages/service/core/workflow/dispatch/plugin/run.ts index 2bce8e4b810..58b50fbaf35 100644 --- a/packages/service/core/workflow/dispatch/plugin/run.ts +++ b/packages/service/core/workflow/dispatch/plugin/run.ts @@ -123,7 +123,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise import('./icons/common/paused.svg'), 'common/playFill': () => import('./icons/common/playFill.svg'), 'common/playLight': () => import('./icons/common/playLight.svg'), - 'common/pluginFill': () => import('./icons/common/pluginFill.svg'), 'common/publishFill': () => import('./icons/common/publishFill.svg'), 'common/refreshLight': () => import('./icons/common/refreshLight.svg'), 'common/resultLight': () => import('./icons/common/resultLight.svg'), @@ -347,8 +346,6 @@ export const iconPaths = { 'price/right': () => import('./icons/price/right.svg'), save: () => import('./icons/save.svg'), stop: () => import('./icons/stop.svg'), - store: () => import('./icons/store.svg'), - storeFill: () => import('./icons/storeFill.svg'), 'support/account/loginoutLight': () => import('./icons/support/account/loginoutLight.svg'), 'support/account/plans': () => import('./icons/support/account/plans.svg'), 'support/account/promotionLight': () => import('./icons/support/account/promotionLight.svg'), diff --git a/packages/web/components/common/Icon/icons/common/pluginFill.svg b/packages/web/components/common/Icon/icons/common/pluginFill.svg deleted file mode 100644 index 759ba80b9a9..00000000000 --- a/packages/web/components/common/Icon/icons/common/pluginFill.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/packages/web/components/common/Icon/icons/store.svg b/packages/web/components/common/Icon/icons/store.svg deleted file mode 100644 index 9fea876f487..00000000000 --- a/packages/web/components/common/Icon/icons/store.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/web/components/common/Icon/icons/storeFill.svg b/packages/web/components/common/Icon/icons/storeFill.svg deleted file mode 100644 index b8c3280df56..00000000000 --- a/packages/web/components/common/Icon/icons/storeFill.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/web/i18n/en/common.json b/packages/web/i18n/en/common.json index e68de2f5010..7d2888365fe 100644 --- a/packages/web/i18n/en/common.json +++ b/packages/web/i18n/en/common.json @@ -232,7 +232,6 @@ "common.request_more": "Click to Load More", "common.speech.error tip": "Speech to Text Failed", "common.speech.not support": "Your Browser Does Not Support Speech Input", - "common.store": "Store", "common.submit_success": "Submitted Successfully", "common.submitted": "Submitted", "common.support": "Support", diff --git a/packages/web/i18n/zh-CN/common.json b/packages/web/i18n/zh-CN/common.json index b42bc93bde8..bf729495fcc 100644 --- a/packages/web/i18n/zh-CN/common.json +++ b/packages/web/i18n/zh-CN/common.json @@ -232,7 +232,6 @@ "common.request_more": "点击加载更多", "common.speech.error tip": "语音转文字失败", "common.speech.not support": "您的浏览器不支持语音输入", - "common.store": "商城", "common.submit_success": "提交成功", "common.submitted": "已提交", "common.support": "支持", diff --git a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/NodeTemplatesModal.tsx b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/NodeTemplatesModal.tsx index dafa8880125..a210e489db1 100644 --- a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/NodeTemplatesModal.tsx +++ b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/NodeTemplatesModal.tsx @@ -52,6 +52,7 @@ import { LoopEndNode } from '@fastgpt/global/core/workflow/template/system/loop/ import { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants'; import { WorkflowNodeEdgeContext } from '../context/workflowInitContext'; import { defaultGroup } from '@/pages/toolkit'; +import CostTooltip from '@/components/core/app/plugin/CostTooltip'; type ModuleTemplateListProps = { isOpen: boolean; @@ -265,8 +266,8 @@ const NodeTemplatesModal = ({ isOpen, onClose }: ModuleTemplateListProps) => { value: TemplateTypeEnum.basic }, { - icon: 'store', - label: t('common:common.store'), + icon: 'phoneTabbar/tool', + label: t('common:navbar.Toolkit'), value: TemplateTypeEnum.systemPlugin }, { @@ -639,125 +640,138 @@ const RenderList = React.memo(function RenderList({ )} {!collapsedGroups.includes(label) && ( - {list.map((item, i) => ( - - {item.label && item.list.length > 0 && ( - - - {t(item.label as any)} - - - )} - {item.list.length > 0 && ( - - {item.list.map((template) => ( - - + {list.map((item, i) => { + return ( + + {item.label && item.list.length > 0 && ( + + + {t(item.label as any)} + + + )} + {item.list.length > 0 && ( + + {item.list.map((template) => { + console.log(template); + return ( + + + + + {t(template.name as any)} + + + + {t(template.intro as any) || + t('common:core.workflow.Not intro')} + + {template.hasTokenFee && ( + + )} + + } + > + { + if (e.clientX < sliderWidth) return; + onAddNode({ + template, + position: { x: e.clientX, y: e.clientY } + }); + }} + onClick={(e) => { + if (template.isFolder) { + return setParentId(template.id); + } + if (isPc) { + return onAddNode({ + template, + position: { x: sliderWidth * 1.5, y: 200 } + }); + } + onAddNode({ + template, + position: { x: e.clientX, y: e.clientY } + }); + onClose(); + }} + whiteSpace={'nowrap'} + overflow={'hidden'} + textOverflow={'ellipsis'} + > - + {t(template.name as any)} + + {gridStyle.authorInRight && + template.authorAvatar && + template.author && ( + + + + {template.author} + + + )} - - {t(template.intro as any) || - t('common:core.workflow.Not intro')} - - - } - > - { - if (e.clientX < sliderWidth) return; - onAddNode({ - template, - position: { x: e.clientX, y: e.clientY } - }); - }} - onClick={(e) => { - if (template.isFolder) { - return setParentId(template.id); - } - if (isPc) { - return onAddNode({ - template, - position: { x: sliderWidth * 1.5, y: 200 } - }); - } - onAddNode({ - template, - position: { x: e.clientX, y: e.clientY } - }); - onClose(); - }} - > - - - - {t(template.name as any)} - - - - {gridStyle.authorInRight && - template.authorAvatar && - template.author && ( - - - - {template.author} - - - )} - - - ))} - - )} - - ))} + + ); + })} + + )} + + ); + })} )}