Skip to content

Commit caf85dc

Browse files
authored
Tool price (#5376)
* resolve conflicts for cherry-pick * fix i18n * Enhance system plugin template data structure and update ToolSelectModal to include CostTooltip component * refactor: update systemKeyCost type to support array of objects in plugin and workflow types * refactor: simplify systemKeyCost type across plugin and workflow types to a single number * refactor: streamline systemKeyCost handling in plugin and workflow components * fix * fix
1 parent fada05a commit caf85dc

File tree

17 files changed

+173
-30
lines changed

17 files changed

+173
-30
lines changed

packages/global/core/app/plugin/type.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type PluginRuntimeType = {
1919
nodes: StoreNodeItemType[];
2020
edges: StoreEdgeItemType[];
2121
currentCost?: number;
22+
systemKeyCost?: number;
2223
hasTokenFee?: boolean;
2324
};
2425

@@ -44,6 +45,7 @@ export type SystemPluginTemplateItemType = WorkflowTemplateType & {
4445
// commercial plugin config
4546
originCost?: number; // n points/one time
4647
currentCost?: number;
48+
systemKeyCost?: number;
4749
hasTokenFee?: boolean;
4850
pluginOrder?: number;
4951

@@ -52,6 +54,7 @@ export type SystemPluginTemplateItemType = WorkflowTemplateType & {
5254

5355
// Admin config
5456
inputList?: FlowNodeInputItemType['inputList'];
57+
inputListVal?: Record<string, any>;
5558
hasSystemSecret?: boolean;
5659
};
5760

packages/global/core/workflow/type/node.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export type FlowNodeCommonType = {
7777

7878
// Not store, just computed
7979
currentCost?: number;
80+
systemKeyCost?: number;
8081
hasTokenFee?: boolean;
8182
hasSystemSecret?: boolean;
8283
};
@@ -135,6 +136,7 @@ export type NodeTemplateListItemType = {
135136
author?: string;
136137
unique?: boolean; // 唯一的
137138
currentCost?: number; // 当前积分消耗
139+
systemKeyCost?: number; // 系统密钥费用,统一为数字
138140
hasTokenFee?: boolean; // 是否配置积分
139141
instructions?: string; // 使用说明
140142
courseUrl?: string; // 教程链接

packages/service/core/app/plugin/controller.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,10 @@ export async function getChildAppPreviewNode({
373373
showTargetHandle: true,
374374

375375
currentCost: app.currentCost,
376+
systemKeyCost: app.systemKeyCost,
376377
hasTokenFee: app.hasTokenFee,
377378
hasSystemSecret: app.hasSystemSecret,
379+
isFolder: app.isFolder,
378380

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

428430
originCost: 0,
429431
currentCost: 0,
432+
systemKeyCost: 0,
430433
hasTokenFee: false,
431434
pluginOrder: 0
432435
};
@@ -443,6 +446,7 @@ export async function getChildAppRuntimeById({
443446
avatar: app.avatar || '',
444447
showStatus: true,
445448
currentCost: app.currentCost,
449+
systemKeyCost: app.systemKeyCost,
446450
nodes: app.workflow.nodes,
447451
edges: app.workflow.edges,
448452
hasTokenFee: app.hasTokenFee
@@ -469,6 +473,7 @@ const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplat
469473
currentCost: item.currentCost,
470474
hasTokenFee: item.hasTokenFee,
471475
pluginOrder: item.pluginOrder,
476+
systemKeyCost: item.systemKeyCost,
472477
associatedPluginId,
473478
userGuide,
474479
workflow: {
@@ -532,34 +537,32 @@ export const getSystemTools = async (): Promise<SystemPluginTemplateItemType[]>
532537

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

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

538544
return {
539545
id: item.id,
540546
parentId: item.parentId,
541-
isFolder: tools.some((tool) => tool.parentId === item.id),
542-
547+
isFolder,
543548
name: item.name,
544549
avatar: item.avatar,
545550
intro: item.description,
546-
547551
author: item.author,
548552
courseUrl: item.courseUrl,
549553
weight: item.weight,
550-
551554
workflow: {
552555
nodes: [],
553556
edges: []
554557
},
555558
versionList,
556-
557559
templateType: item.templateType,
558560
showStatus: true,
559-
560561
isActive: item.isActive,
561562
inputList: item?.secretInputConfig,
562-
hasSystemSecret: !!dbPluginConfig?.inputListVal
563+
hasSystemSecret: !!dbPluginConfig?.inputListVal,
564+
currentCost: dbPluginConfig?.currentCost ?? 0,
565+
systemKeyCost: dbPluginConfig?.systemKeyCost ?? 0
563566
};
564567
});
565568

packages/service/core/app/plugin/systemPluginSchema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const SystemPluginSchema = new Schema({
2727
pluginOrder: {
2828
type: Number
2929
},
30+
systemKeyCost: {
31+
type: Number,
32+
default: 0
33+
},
3034
customConfig: Object,
3135
inputListVal: Object,
3236

packages/service/core/app/plugin/type.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SystemPluginListItemType } from '@fastgpt/global/core/app/type';
22
import { FlowNodeTemplateTypeEnum } from '@fastgpt/global/core/workflow/constants';
33
import type { WorkflowTemplateBasicType } from '@fastgpt/global/core/workflow/type';
4+
import type { InputConfigType } from '@fastgpt/global/core/workflow/type/io';
45

56
export type SystemPluginConfigSchemaType = {
67
pluginId: string;
@@ -10,6 +11,7 @@ export type SystemPluginConfigSchemaType = {
1011
hasTokenFee: boolean;
1112
isActive: boolean;
1213
pluginOrder?: number;
14+
systemKeyCost?: number;
1315

1416
customConfig?: {
1517
name: string;

packages/service/core/app/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ export async function rewriteAppWorkflowToDetail({
8282
node.version = preview.version;
8383

8484
node.currentCost = preview.currentCost;
85+
node.systemKeyCost = preview.systemKeyCost;
8586
node.hasTokenFee = preview.hasTokenFee;
8687
node.hasSystemSecret = preview.hasSystemSecret;
88+
node.isFolder = preview.isFolder;
8789

8890
node.toolConfig = preview.toolConfig;
8991

packages/service/core/workflow/dispatch/child/runTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const dispatchRunTool = async (props: RunToolProps): Promise<RunToolRespo
150150
if (params.system_input_config?.type !== SystemToolInputTypeEnum.system) {
151151
return 0;
152152
}
153-
return tool.currentCost ?? 0;
153+
return (tool.systemKeyCost ?? 0) + (tool.currentCost ?? 0);
154154
})();
155155

156156
pushTrack.runSystemTool({

packages/web/i18n/en/app.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
"permission.des.write": "Can view and edit apps",
184184
"plugin.Instructions": "Instructions",
185185
"plugin_cost_by_token": "Charged based on token usage",
186+
"plugin_cost_folder_tip": "This tool set contains subordinate tools, and the call points are determined based on the actual calling tool",
186187
"plugin_cost_per_times": "{{cost}} points/time",
187188
"plugin_dispatch": "Plugin Invocation",
188189
"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.",
@@ -246,6 +247,7 @@
246247
"tool_active_manual_config_desc": "The temporary key is saved in this application and is only for use by this application.",
247248
"tool_active_system_config_desc": "Use the system configured key",
248249
"tool_active_system_config_price_desc": "Additional payment for key price ({{price}} points/time)",
250+
"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.",
249251
"tool_detail": "Tool details",
250252
"tool_input_param_tip": "This plugin requires configuration of related information to run properly.",
251253
"tool_not_active": "This tool has not been activated yet",

packages/web/i18n/zh-CN/app.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
"permission.des.write": "可查看和编辑应用",
193193
"plugin.Instructions": "使用说明",
194194
"plugin_cost_by_token": "依据 token 消耗计费",
195+
"plugin_cost_folder_tip": "该工具集包含下属工具,调用积分依据实际调用工具决定",
195196
"plugin_cost_per_times": "{{cost}} 积分/次",
196197
"plugin_dispatch": "插件调用",
197198
"plugin_dispatch_tip": "给模型附加获取外部数据的能力,具体调用哪些插件,将由模型自主决定,所有插件都将以非流模式运行。\n若选择了插件,知识库调用将自动作为一个特殊的插件。",
@@ -255,6 +256,7 @@
255256
"tool_active_manual_config_desc": "临时密钥保存在本应用中,仅供该应用使用",
256257
"tool_active_system_config_desc": "使用系统已配置好的密钥",
257258
"tool_active_system_config_price_desc": "需额外支付密钥价格( {{price}} 积分/次)",
259+
"tool_active_system_config_price_desc_folder": "需额外支付密钥价格,依据实际使用工具扣费。",
258260
"tool_detail": "工具详情",
259261
"tool_input_param_tip": "该插件正常运行需要配置相关信息",
260262
"tool_not_active": "该工具尚未激活",

packages/web/i18n/zh-Hant/app.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
"permission.des.write": "可以檢視和編輯應用程式",
184184
"plugin.Instructions": "使用說明",
185185
"plugin_cost_by_token": "根據 token 消耗計費",
186+
"plugin_cost_folder_tip": "該工具集包含下屬工具,調用積分依據實際調用工具決定",
186187
"plugin_cost_per_times": "{{cost}} 積分/次",
187188
"plugin_dispatch": "外掛呼叫",
188189
"plugin_dispatch_tip": "賦予模型取得外部資料的能力,具體呼叫哪些外掛,將由模型自主決定,所有外掛都將以非串流模式執行。\n若選擇了外掛,知識庫呼叫將自動作為一個特殊的外掛。",
@@ -246,6 +247,7 @@
246247
"tool_active_manual_config_desc": "臨時密鑰保存在本應用中,僅供該應用使用",
247248
"tool_active_system_config_desc": "使用系統已配置好的密鑰",
248249
"tool_active_system_config_price_desc": "需額外支付密鑰價格( {{price}} 積分/次)",
250+
"tool_active_system_config_price_desc_folder": "需額外支付密鑰價格,依據實際使用工具扣費。",
249251
"tool_detail": "工具詳情",
250252
"tool_input_param_tip": "這個外掛正常執行需要設定相關資訊",
251253
"tool_not_active": "該工具尚未激活",

0 commit comments

Comments
 (0)