Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/global/core/app/plugin/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type PluginRuntimeType = {
nodes: StoreNodeItemType[];
edges: StoreEdgeItemType[];
currentCost?: number;
systemKeyCost?: number;
hasTokenFee?: boolean;
};

Expand Down Expand Up @@ -46,12 +47,14 @@ export type SystemPluginTemplateItemType = WorkflowTemplateType & {
currentCost?: number;
hasTokenFee?: boolean;
pluginOrder?: number;
systemKeyCost?: number;

isActive?: boolean;
isOfficial?: boolean;

// Admin config
inputList?: FlowNodeInputItemType['inputList'];
inputListVal?: Record<string, any>;
hasSystemSecret?: boolean;
};

Expand Down
2 changes: 2 additions & 0 deletions packages/global/core/workflow/type/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type FlowNodeCommonType = {

// Not store, just computed
currentCost?: number;
systemKeyCost?: number;
hasTokenFee?: boolean;
hasSystemSecret?: boolean;
};
Expand Down Expand Up @@ -135,6 +136,7 @@ export type NodeTemplateListItemType = {
author?: string;
unique?: boolean; // 唯一的
currentCost?: number; // 当前积分消耗
systemKeyCost?: number; // 系统密钥费用,统一为数字
hasTokenFee?: boolean; // 是否配置积分
instructions?: string; // 使用说明
courseUrl?: string; // 教程链接
Expand Down
17 changes: 10 additions & 7 deletions packages/service/core/app/plugin/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,10 @@ export async function getChildAppPreviewNode({
showTargetHandle: true,

currentCost: app.currentCost,
systemKeyCost: app.systemKeyCost,
hasTokenFee: app.hasTokenFee,
hasSystemSecret: app.hasSystemSecret,
isFolder: app.isFolder,

...nodeIOConfig,
outputs: nodeIOConfig.outputs.some((item) => item.type === FlowNodeOutputTypeEnum.error)
Expand Down Expand Up @@ -427,6 +429,7 @@ export async function getChildAppRuntimeById({

originCost: 0,
currentCost: 0,
systemKeyCost: 0,
hasTokenFee: false,
pluginOrder: 0
};
Expand All @@ -443,6 +446,7 @@ export async function getChildAppRuntimeById({
avatar: app.avatar || '',
showStatus: true,
currentCost: app.currentCost,
systemKeyCost: app.systemKeyCost,
nodes: app.workflow.nodes,
edges: app.workflow.edges,
hasTokenFee: app.hasTokenFee
Expand All @@ -469,6 +473,7 @@ const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplat
currentCost: item.currentCost,
hasTokenFee: item.hasTokenFee,
pluginOrder: item.pluginOrder,
systemKeyCost: item.systemKeyCost,
associatedPluginId,
userGuide,
workflow: {
Expand Down Expand Up @@ -532,34 +537,32 @@ export const getSystemTools = async (): Promise<SystemPluginTemplateItemType[]>

const formatTools = tools.map<SystemPluginTemplateItemType>((item) => {
const dbPluginConfig = systemPlugins.get(item.id);
const isFolder = tools.some((tool) => tool.parentId === item.id);

const versionList = (item.versionList as SystemPluginTemplateItemType['versionList']) || [];

return {
id: item.id,
parentId: item.parentId,
isFolder: tools.some((tool) => tool.parentId === item.id),

isFolder,
name: item.name,
avatar: item.avatar,
intro: item.description,

author: item.author,
courseUrl: item.courseUrl,
weight: item.weight,

workflow: {
nodes: [],
edges: []
},
versionList,

templateType: item.templateType,
showStatus: true,

isActive: item.isActive,
inputList: item?.secretInputConfig,
hasSystemSecret: !!dbPluginConfig?.inputListVal
hasSystemSecret: !!dbPluginConfig?.inputListVal,
currentCost: dbPluginConfig?.currentCost ?? 0,
systemKeyCost: dbPluginConfig?.systemKeyCost ?? 0
};
});

Expand Down
4 changes: 4 additions & 0 deletions packages/service/core/app/plugin/systemPluginSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const SystemPluginSchema = new Schema({
pluginOrder: {
type: Number
},
systemKeyCost: {
type: Number,
default: 0
},
customConfig: Object,
inputListVal: Object,

Expand Down
2 changes: 2 additions & 0 deletions packages/service/core/app/plugin/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SystemPluginListItemType } from '@fastgpt/global/core/app/type';
import { FlowNodeTemplateTypeEnum } from '@fastgpt/global/core/workflow/constants';
import type { WorkflowTemplateBasicType } from '@fastgpt/global/core/workflow/type';
import type { InputConfigType } from '@fastgpt/global/core/workflow/type/io';

export type SystemPluginConfigSchemaType = {
pluginId: string;
Expand All @@ -10,6 +11,7 @@ export type SystemPluginConfigSchemaType = {
hasTokenFee: boolean;
isActive: boolean;
pluginOrder?: number;
systemKeyCost?: number;

customConfig?: {
name: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/service/core/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ export async function rewriteAppWorkflowToDetail({
node.version = preview.version;

node.currentCost = preview.currentCost;
node.systemKeyCost = preview.systemKeyCost;
node.hasTokenFee = preview.hasTokenFee;
node.hasSystemSecret = preview.hasSystemSecret;
node.isFolder = preview.isFolder;

node.toolConfig = preview.toolConfig;

Expand Down
8 changes: 7 additions & 1 deletion packages/service/core/workflow/dispatch/child/runTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,17 @@ export const dispatchRunTool = async (props: RunToolProps): Promise<RunToolRespo
};
}

const dbPlugin = await MongoSystemPlugin.findOne({
pluginId: toolConfig.systemTool?.toolId
}).lean();

const usagePoints = (() => {
if (params.system_input_config?.type !== SystemToolInputTypeEnum.system) {
return 0;
}
return tool.currentCost ?? 0;
const systemKeyCost = dbPlugin?.systemKeyCost;
const systemCost = typeof systemKeyCost === 'number' ? systemKeyCost : 0;
return (tool.currentCost ?? 0) + systemCost;
})();

pushTrack.runSystemTool({
Expand Down
2 changes: 2 additions & 0 deletions packages/web/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"permission.des.write": "Can view and edit apps",
"plugin.Instructions": "Instructions",
"plugin_cost_by_token": "Charged based on token usage",
"plugin_cost_folder_tip": "This tool set contains subordinate tools, and the call points are determined based on the actual calling tool",
"plugin_cost_per_times": "{{cost}} points/time",
"plugin_dispatch": "Plugin Invocation",
"plugin_dispatch_tip": "Adds extra capabilities to the model. The specific plugins to be invoked will be autonomously decided by the model.\nIf a plugin is selected, the Dataset invocation will automatically be treated as a special plugin.",
Expand Down Expand Up @@ -246,6 +247,7 @@
"tool_active_manual_config_desc": "The temporary key is saved in this application and is only for use by this application.",
"tool_active_system_config_desc": "Use the system configured key",
"tool_active_system_config_price_desc": "Additional payment for key price ({{price}} points/time)",
"tool_active_system_config_price_desc_folder": "The additional key price is required, and the fee will be deducted based on the actual use of the tool.",
"tool_detail": "Tool details",
"tool_input_param_tip": "This plugin requires configuration of related information to run properly.",
"tool_not_active": "This tool has not been activated yet",
Expand Down
2 changes: 2 additions & 0 deletions packages/web/i18n/zh-CN/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"permission.des.write": "可查看和编辑应用",
"plugin.Instructions": "使用说明",
"plugin_cost_by_token": "依据 token 消耗计费",
"plugin_cost_folder_tip": "该工具集包含下属工具,调用积分依据实际调用工具决定",
"plugin_cost_per_times": "{{cost}} 积分/次",
"plugin_dispatch": "插件调用",
"plugin_dispatch_tip": "给模型附加获取外部数据的能力,具体调用哪些插件,将由模型自主决定,所有插件都将以非流模式运行。\n若选择了插件,知识库调用将自动作为一个特殊的插件。",
Expand Down Expand Up @@ -255,6 +256,7 @@
"tool_active_manual_config_desc": "临时密钥保存在本应用中,仅供该应用使用",
"tool_active_system_config_desc": "使用系统已配置好的密钥",
"tool_active_system_config_price_desc": "需额外支付密钥价格( {{price}} 积分/次)",
"tool_active_system_config_price_desc_folder": "需额外支付密钥价格,依据实际使用工具扣费。",
"tool_detail": "工具详情",
"tool_input_param_tip": "该插件正常运行需要配置相关信息",
"tool_not_active": "该工具尚未激活",
Expand Down
2 changes: 2 additions & 0 deletions packages/web/i18n/zh-Hant/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"permission.des.write": "可以檢視和編輯應用程式",
"plugin.Instructions": "使用說明",
"plugin_cost_by_token": "根據 token 消耗計費",
"plugin_cost_folder_tip": "該工具集包含下屬工具,調用積分依據實際調用工具決定",
"plugin_cost_per_times": "{{cost}} 積分/次",
"plugin_dispatch": "外掛呼叫",
"plugin_dispatch_tip": "賦予模型取得外部資料的能力,具體呼叫哪些外掛,將由模型自主決定,所有外掛都將以非串流模式執行。\n若選擇了外掛,知識庫呼叫將自動作為一個特殊的外掛。",
Expand Down Expand Up @@ -246,6 +247,7 @@
"tool_active_manual_config_desc": "臨時密鑰保存在本應用中,僅供該應用使用",
"tool_active_system_config_desc": "使用系統已配置好的密鑰",
"tool_active_system_config_price_desc": "需額外支付密鑰價格( {{price}} 積分/次)",
"tool_active_system_config_price_desc_folder": "需額外支付密鑰價格,依據實際使用工具扣費。",
"tool_detail": "工具詳情",
"tool_input_param_tip": "這個外掛正常執行需要設定相關資訊",
"tool_not_active": "該工具尚未激活",
Expand Down
18 changes: 15 additions & 3 deletions projects/app/src/components/core/app/plugin/CostTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ import { Box, Flex, Divider } from '@chakra-ui/react';
import React from 'react';
import { useTranslation } from 'next-i18next';

const CostTooltip = ({ cost, hasTokenFee }: { cost?: number; hasTokenFee?: boolean }) => {
const CostTooltip = ({
cost,
hasTokenFee,
isFolder
}: {
cost?: number;
hasTokenFee?: boolean;
isFolder?: boolean;
}) => {
const { t } = useTranslation();

const getCostText = () => {
if (isFolder) {
return t('app:plugin_cost_folder_tip');
}

if (hasTokenFee && cost && cost > 0) {
return `${t('app:plugin_cost_per_times', {
cost: cost
Expand All @@ -25,8 +37,8 @@ const CostTooltip = ({ cost, hasTokenFee }: { cost?: number; hasTokenFee?: boole
return (
<>
<Divider mt={4} mb={2} />
<Flex>
<Box>{t('common:core.plugin.cost')}</Box>
<Flex alignItems={'center'}>
<Box whiteSpace={'nowrap'}>{t('common:core.plugin.cost')}</Box>
<Box color={'myGray.600'}>{getCostText()}</Box>
</Flex>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ const ConfigToolModal = ({

{isOpenSecretModal && (
<SecretInputModal
isFolder={configTool?.isFolder}
inputConfig={{
...input,
value: value as ToolParamsFormType
}}
hasSystemSecret={configTool?.hasSystemSecret}
secretCost={configTool?.currentCost}
secretCost={configTool?.systemKeyCost}
courseUrl={configTool?.courseUrl}
parentId={configTool?.pluginId}
onClose={setFalseSecretModal}
onSubmit={(data) => {
onChange(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { useToast } from '@fastgpt/web/hooks/useToast';
import type { LLMModelItemType } from '@fastgpt/global/core/ai/model.d';
import { workflowStartNodeId } from '@/web/core/app/constants';
import ConfigToolModal from './ConfigToolModal';
import CostTooltip from '@/components/core/app/plugin/CostTooltip';

type Props = {
selectedTools: FlowNodeTemplateType[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ const NodeTemplateListItem = ({
<Box mt={2} color={'myGray.500'} maxH={'100px'} overflow={'hidden'}>
{t(template.intro as any) || t('common:core.workflow.Not intro')}
</Box>
{/* {templateType === TemplateTypeEnum.systemPlugin && (
<CostTooltip cost={template.currentCost} hasTokenFee={template.hasTokenFee} />
)} */}
<CostTooltip
cost={template.currentCost}
hasTokenFee={template.hasTokenFee}
isFolder={template.isFolder}
/>
</Box>
}
shouldWrapChildren={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ const ToolConfig = ({ nodeId, inputs }: { nodeId?: string; inputs?: FlowNodeInpu
</Button>
{isOpen && (
<SecretInputModal
isFolder={node?.isFolder}
inputConfig={inputConfig}
hasSystemSecret={node?.hasSystemSecret}
secretCost={node?.currentCost}
secretCost={node?.systemKeyCost}
courseUrl={node?.courseUrl}
parentId={node?.pluginId}
onClose={setFalse}
onSubmit={onSubmit}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ const NodeCard = (props: Props) => {

return { node, parentNode };
}, [nodeList, nodeId]);

// get child tools info (if it is a tool set)

const isAppNode = node && AppNodeFlowNodeTypeMap[node?.flowNodeType];
const showVersion = useMemo(() => {
// 1. MCP tool set do not have version
Expand Down Expand Up @@ -409,6 +412,7 @@ const NodeCard = (props: Props) => {
<EditTitleModal maxLength={100} />
{inputConfig && isOpenToolParamConfigModal && (
<SecretInputModal
isFolder={node?.isFolder}
onClose={onCloseToolParamConfigModal}
onSubmit={(data) => {
onChangeNode({
Expand All @@ -425,7 +429,8 @@ const NodeCard = (props: Props) => {
courseUrl={node?.courseUrl}
inputConfig={inputConfig}
hasSystemSecret={node?.hasSystemSecret}
secretCost={node?.currentCost}
parentId={node?.pluginId}
secretCost={node?.systemKeyCost}
/>
)}
</Flex>
Expand Down
Loading
Loading