Skip to content

Commit 80bfe1e

Browse files
ctrlz526c121914yu
authored andcommitted
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 224f859 commit 80bfe1e

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
@@ -379,8 +379,10 @@ export async function getChildAppPreviewNode({
379379
showTargetHandle: true,
380380

381381
currentCost: app.currentCost,
382+
systemKeyCost: app.systemKeyCost,
382383
hasTokenFee: app.hasTokenFee,
383384
hasSystemSecret: app.hasSystemSecret,
385+
isFolder: app.isFolder,
384386

385387
...nodeIOConfig,
386388
outputs: nodeIOConfig.outputs.some((item) => item.type === FlowNodeOutputTypeEnum.error)
@@ -433,6 +435,7 @@ export async function getChildAppRuntimeById({
433435

434436
originCost: 0,
435437
currentCost: 0,
438+
systemKeyCost: 0,
436439
hasTokenFee: false,
437440
pluginOrder: 0
438441
};
@@ -449,6 +452,7 @@ export async function getChildAppRuntimeById({
449452
avatar: app.avatar || '',
450453
showStatus: true,
451454
currentCost: app.currentCost,
455+
systemKeyCost: app.systemKeyCost,
452456
nodes: app.workflow.nodes,
453457
edges: app.workflow.edges,
454458
hasTokenFee: app.hasTokenFee
@@ -475,6 +479,7 @@ const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplat
475479
currentCost: item.currentCost,
476480
hasTokenFee: item.hasTokenFee,
477481
pluginOrder: item.pluginOrder,
482+
systemKeyCost: item.systemKeyCost,
478483
associatedPluginId,
479484
userGuide,
480485
workflow: {
@@ -538,34 +543,32 @@ export const getSystemTools = async (): Promise<SystemPluginTemplateItemType[]>
538543

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

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

544550
return {
545551
id: item.id,
546552
parentId: item.parentId,
547-
isFolder: tools.some((tool) => tool.parentId === item.id),
548-
553+
isFolder,
549554
name: item.name,
550555
avatar: item.avatar,
551556
intro: item.description,
552-
553557
author: item.author,
554558
courseUrl: item.courseUrl,
555559
weight: item.weight,
556-
557560
workflow: {
558561
nodes: [],
559562
edges: []
560563
},
561564
versionList,
562-
563565
templateType: item.templateType,
564566
showStatus: true,
565-
566567
isActive: item.isActive,
567568
inputList: item?.secretInputConfig,
568-
hasSystemSecret: !!dbPluginConfig?.inputListVal
569+
hasSystemSecret: !!dbPluginConfig?.inputListVal,
570+
currentCost: dbPluginConfig?.currentCost ?? 0,
571+
systemKeyCost: dbPluginConfig?.systemKeyCost ?? 0
569572
};
570573
});
571574

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
@@ -185,6 +185,7 @@
185185
"permission.name.readChatLog": "View chat logs",
186186
"plugin.Instructions": "Instructions",
187187
"plugin_cost_by_token": "Charged based on token usage",
188+
"plugin_cost_folder_tip": "This tool set contains subordinate tools, and the call points are determined based on the actual calling tool",
188189
"plugin_cost_per_times": "{{cost}} points/time",
189190
"plugin_dispatch": "Plugin Invocation",
190191
"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.",
@@ -248,6 +249,7 @@
248249
"tool_active_manual_config_desc": "The temporary key is saved in this application and is only for use by this application.",
249250
"tool_active_system_config_desc": "Use the system configured key",
250251
"tool_active_system_config_price_desc": "Additional payment for key price ({{price}} points/time)",
252+
"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.",
251253
"tool_detail": "Tool details",
252254
"tool_input_param_tip": "This plugin requires configuration of related information to run properly.",
253255
"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
@@ -194,6 +194,7 @@
194194
"permission.name.readChatLog": "查看对话日志",
195195
"plugin.Instructions": "使用说明",
196196
"plugin_cost_by_token": "依据 token 消耗计费",
197+
"plugin_cost_folder_tip": "该工具集包含下属工具,调用积分依据实际调用工具决定",
197198
"plugin_cost_per_times": "{{cost}} 积分/次",
198199
"plugin_dispatch": "插件调用",
199200
"plugin_dispatch_tip": "给模型附加获取外部数据的能力,具体调用哪些插件,将由模型自主决定,所有插件都将以非流模式运行。\n若选择了插件,知识库调用将自动作为一个特殊的插件。",
@@ -257,6 +258,7 @@
257258
"tool_active_manual_config_desc": "临时密钥保存在本应用中,仅供该应用使用",
258259
"tool_active_system_config_desc": "使用系统已配置好的密钥",
259260
"tool_active_system_config_price_desc": "需额外支付密钥价格( {{price}} 积分/次)",
261+
"tool_active_system_config_price_desc_folder": "需额外支付密钥价格,依据实际使用工具扣费。",
260262
"tool_detail": "工具详情",
261263
"tool_input_param_tip": "该插件正常运行需要配置相关信息",
262264
"tool_not_active": "该工具尚未激活",

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

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

0 commit comments

Comments
 (0)