Skip to content

Commit

Permalink
plugin usage
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Nov 26, 2024
1 parent f30bd66 commit 93a7786
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 157 deletions.
2 changes: 1 addition & 1 deletion packages/global/core/workflow/type/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type TemplateMarketListItemType = {
// system plugin
export type SystemPluginTemplateItemType = WorkflowTemplateType & {
customWorkflow?: string;
associatedPlugin?: Omit<SystemPluginListItemType, 'workflow'>;
associatedPlugin?: SystemPluginListItemType;
userGuide?: string;

templateType: string;
Expand Down
1 change: 1 addition & 0 deletions packages/global/core/workflow/type/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export type NodeTemplateListItemType = {
author?: string;
unique?: boolean; // 唯一的
currentCost?: number; // 当前积分消耗
hasTokenFee?: boolean; // 是否配置积分
instructions?: string; // 使用说明
};

Expand Down
6 changes: 4 additions & 2 deletions packages/service/core/app/plugin/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/service/core/app/plugin/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type SystemPluginConfigSchemaType = {
weight?: number;
workflow: WorkflowTemplateBasicType;
templateType: string;
associatedPlugin: Omit<SystemPluginListItemType, 'workflow'>;
associatedPlugin: SystemPluginListItemType;
userGuide: string;
};
};
37 changes: 22 additions & 15 deletions packages/service/core/app/plugin/utils.ts
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion packages/service/core/workflow/dispatch/plugin/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
}

const usagePoints = await computedPluginUsage({
plugin,
plugin: pluginTemplate,
childrenUsage: flowUsages,
error: !!output?.pluginOutput?.error
});
Expand Down
3 changes: 0 additions & 3 deletions packages/web/components/common/Icon/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const iconPaths = {
'common/paused': () => 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'),
Expand Down Expand Up @@ -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'),
Expand Down
10 changes: 0 additions & 10 deletions packages/web/components/common/Icon/icons/common/pluginFill.svg

This file was deleted.

5 changes: 0 additions & 5 deletions packages/web/components/common/Icon/icons/store.svg

This file was deleted.

4 changes: 0 additions & 4 deletions packages/web/components/common/Icon/icons/storeFill.svg

This file was deleted.

1 change: 0 additions & 1 deletion packages/web/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/web/i18n/zh-CN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
"common.request_more": "点击加载更多",
"common.speech.error tip": "语音转文字失败",
"common.speech.not support": "您的浏览器不支持语音输入",
"common.store": "商城",
"common.submit_success": "提交成功",
"common.submitted": "已提交",
"common.support": "支持",
Expand Down
Loading

0 comments on commit 93a7786

Please sign in to comment.