From cb804b3f96dc51d1dbe47f6f273ab811a537054a Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Wed, 8 Oct 2025 17:23:31 +0800 Subject: [PATCH] fix: usage repeat --- .../workflow/dispatch/ai/agent/toolCall.ts | 1 + .../service/support/wallet/usage/schema.ts | 96 ++++++++++--------- 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/packages/service/core/workflow/dispatch/ai/agent/toolCall.ts b/packages/service/core/workflow/dispatch/ai/agent/toolCall.ts index 70f11eaea..d9328c65a 100644 --- a/packages/service/core/workflow/dispatch/ai/agent/toolCall.ts +++ b/packages/service/core/workflow/dispatch/ai/agent/toolCall.ts @@ -386,6 +386,7 @@ export const runToolCall = async ( initToolNodes(runtimeNodes, [toolNode.nodeId], startParams); const toolRunResponse = await runWorkflow({ ...workflowProps, + usageId: undefined, isToolCall: true }); diff --git a/packages/service/support/wallet/usage/schema.ts b/packages/service/support/wallet/usage/schema.ts index db644447f..9cb8c727b 100644 --- a/packages/service/support/wallet/usage/schema.ts +++ b/packages/service/support/wallet/usage/schema.ts @@ -8,52 +8,60 @@ import { } from '@fastgpt/global/support/user/team/constant'; import { UsageCollectionName, UsageItemCollectionName } from './constants'; -const UsageSchema = new Schema({ - teamId: { - type: Schema.Types.ObjectId, - ref: TeamCollectionName, - required: true - }, - tmbId: { - type: Schema.Types.ObjectId, - ref: TeamMemberCollectionName, - required: true - }, - source: { - type: String, - enum: Object.values(UsageSourceEnum), - required: true - }, - appName: { - // usage name - type: String, - default: '' - }, - totalPoints: { - // total points - type: Number, - required: true - }, - appId: { - type: Schema.Types.ObjectId, - ref: 'apps', - required: false - }, - pluginId: { - type: Schema.Types.ObjectId, - ref: 'plugins', - required: false - }, - time: { - type: Date, - default: () => new Date() - }, +const UsageSchema = new Schema( + { + teamId: { + type: Schema.Types.ObjectId, + ref: TeamCollectionName, + required: true + }, + tmbId: { + type: Schema.Types.ObjectId, + ref: TeamMemberCollectionName, + required: true + }, + source: { + type: String, + enum: Object.values(UsageSourceEnum), + required: true + }, + appName: { + // usage name + type: String, + default: '' + }, + totalPoints: { + // total points + type: Number, + required: true + }, + appId: { + type: Schema.Types.ObjectId, + ref: 'apps', + required: false + }, + pluginId: { + type: Schema.Types.ObjectId, + ref: 'plugins', + required: false + }, + time: { + type: Date, + default: () => new Date() + }, - // @description It will not be used again in the future. - list: { - type: Array + // @description It will not be used again in the future. + list: { + type: Array + } + }, + { + // Auto update time + timestamps: { + updatedAt: 'time' + } } -}); +); UsageSchema.virtual('usageItems', { ref: UsageItemCollectionName,