fix(quota): exclude agents from quota rules and usage records (#325)

* fix(quota): exclude agents from quota rules and usage records

* refactor(quota): remove agent_skill_call_count resource type and related logic

* chore(db): replace manual migration with prisma-generated migration
This commit is contained in:
Yiling-J
2026-08-18 11:56:03 +08:00
committed by GitHub
parent f806272c06
commit 8a75d015a1
22 changed files with 127 additions and 318 deletions
@@ -37,7 +37,6 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar'
import {
Cpu,
DollarSign,
Puzzle,
Server,
Terminal,
Wrench,
@@ -93,12 +92,6 @@ const RESOURCE_CONFIG = {
unit: '$',
defaultLimit: 10,
},
agent_skill_call_count: {
label: () => m.quota_resource_agent_skill_call_count(),
icon: Puzzle,
unit: 'calls',
defaultLimit: 100,
},
agent_mcp_call_count: {
label: () => m.quota_resource_agent_mcp_call_count(),
icon: Server,
@@ -134,7 +127,6 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
const [roleScope, setRoleScope] = useState<string>('team') // 'team' | 'owner' | 'editor' | 'reviewer'
const [selectedUserIds, setSelectedUserIds] = useState<string[]>([])
const [resource, setResource] = useState<QuotaResourceTypeEnum>('agent_total_tokens')
const [skillId, setSkillId] = useState<string>('')
const [mcpServerId, setMcpServerId] = useState<string>('')
const [bashMatch, setBashMatch] = useState<string>('*')
const [toolName, setToolName] = useState<string>('analyze_image')
@@ -158,18 +150,6 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
enabled: open,
})
// Fetch team skills when needed
const { data: skillsData } = useQuery({
queryKey: ['teams', teamId, 'skills'],
queryFn: async () => {
const res = await client.api.teams[':teamId'].skills.$get({ param: { teamId } })
if (!res.ok) return { skills: [] }
return await res.json()
},
enabled: open && resource === 'agent_skill_call_count',
})
const skills = skillsData?.skills || []
// Fetch team MCP servers when needed
const { data: mcpData } = useQuery({
queryKey: ['teams', teamId, 'mcp', 'servers'],
@@ -190,7 +170,6 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
setSelectedUserIds(rule.userIds || [])
setResource(rule.resource)
const resData = (rule.resourceData as Record<string, unknown> | null) || {}
setSkillId(typeof resData.id === 'string' ? resData.id : '')
setMcpServerId(typeof resData.id === 'string' ? resData.id : '')
setBashMatch(typeof resData.match === 'string' ? resData.match : '*')
setToolName(
@@ -208,7 +187,6 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
setRoleScope('team')
setSelectedUserIds([])
setResource('agent_total_tokens')
setSkillId('')
setMcpServerId('')
setBashMatch('*')
setToolName('analyze_image')
@@ -230,9 +208,7 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
const createMutation = useMutation({
mutationFn: async () => {
const resourceData: Record<string, unknown> = {}
if (resource === 'agent_skill_call_count') {
resourceData.id = skillId
} else if (resource === 'agent_mcp_call_count') {
if (resource === 'agent_mcp_call_count') {
resourceData.id = mcpServerId
} else if (resource === 'agent_bash_call_count') {
resourceData.match = bashMatch.trim() || '*'
@@ -280,9 +256,7 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
mutationFn: async () => {
if (!rule) return
const resourceData: Record<string, unknown> = {}
if (resource === 'agent_skill_call_count') {
resourceData.id = skillId
} else if (resource === 'agent_mcp_call_count') {
if (resource === 'agent_mcp_call_count') {
resourceData.id = mcpServerId
} else if (resource === 'agent_bash_call_count') {
resourceData.match = bashMatch.trim() || '*'
@@ -351,10 +325,6 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
toast.error(m.select_user())
return
}
if (resource === 'agent_skill_call_count' && !skillId.trim()) {
toast.error(m.enter_skill_id())
return
}
if (resource === 'agent_mcp_call_count' && !mcpServerId.trim()) {
toast.error(m.enter_mcp_id())
return
@@ -570,12 +540,6 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
<span>{m.quota_resource_agent_cost()}</span>
</div>
</SelectItem>
<SelectItem value="agent_skill_call_count">
<div className="flex items-center gap-2">
<Puzzle className="w-4 h-4 text-amber-500" />
<span>{m.quota_resource_agent_skill_call_count()}</span>
</div>
</SelectItem>
<SelectItem value="agent_mcp_call_count">
<div className="flex items-center gap-2">
<Server className="w-4 h-4 text-blue-500" />
@@ -599,40 +563,6 @@ export const QuotaRuleDialog: React.FC<QuotaRuleDialogProps> = ({
</div>
{/* Resource Specific Fields */}
{resource === 'agent_skill_call_count' && (
<div className="space-y-2">
<Label htmlFor="quota-skill" className="text-sm font-semibold">
{m.select_skill()}
</Label>
{skills.length > 0 ? (
<Select
value={skillId}
onValueChange={setSkillId}
disabled={isEditing || isPending}
>
<SelectTrigger id="quota-skill" className="w-full">
<SelectValue placeholder={m.select_skill()} />
</SelectTrigger>
<SelectContent>
{skills.map((s: { id: string; name: string }) => (
<SelectItem key={s.id} value={s.id}>
{s.name} ({s.id})
</SelectItem>
))}
</SelectContent>
</Select>
) : (
<Input
id="quota-skill"
value={skillId}
onChange={(e) => setSkillId(e.target.value)}
placeholder={m.enter_skill_id()}
disabled={isEditing || isPending}
/>
)}
</div>
)}
{resource === 'agent_mcp_call_count' && (
<div className="space-y-2">
<Label htmlFor="quota-mcp" className="text-sm font-semibold">
@@ -16,7 +16,6 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar'
import {
Cpu,
DollarSign,
Puzzle,
Server,
Terminal,
Wrench,
@@ -54,11 +53,6 @@ const RESOURCE_META: Record<
icon: DollarSign,
unit: '$',
},
agent_skill_call_count: {
label: () => m.quota_resource_agent_skill_call_count(),
icon: Puzzle,
unit: 'calls',
},
agent_mcp_call_count: {
label: () => m.quota_resource_agent_mcp_call_count(),
icon: Server,
@@ -30,7 +30,6 @@ import {
Trash2,
Cpu,
DollarSign,
Puzzle,
Server,
Terminal,
Wrench,
@@ -66,11 +65,6 @@ const RESOURCE_META: Record<
icon: DollarSign,
unit: '$',
},
agent_skill_call_count: {
label: () => m.quota_resource_agent_skill_call_count(),
icon: Puzzle,
unit: 'calls',
},
agent_mcp_call_count: {
label: () => m.quota_resource_agent_mcp_call_count(),
icon: Server,
@@ -230,9 +224,6 @@ export const QuotasSettings: React.FC<QuotasSettingsProps> = ({ teamId }) => {
</div>
{/* Subtitle / target details */}
<div className="text-xs text-muted-foreground line-clamp-1">
{rule.resource === 'agent_skill_call_count' && (
<span>Skill: {String(resData.id || '')}</span>
)}
{rule.resource === 'agent_mcp_call_count' && (
<span>Server: {String(resData.id || '')}</span>
)}
-3
View File
@@ -1071,7 +1071,6 @@
"quota_resource": "Resource",
"quota_resource_agent_total_tokens": "AI Tokens",
"quota_resource_agent_cost": "AI Cost ($)",
"quota_resource_agent_skill_call_count": "Skill Calls",
"quota_resource_agent_mcp_call_count": "MCP Server Calls",
"quota_resource_agent_bash_call_count": "Agent Bash Calls",
"quota_resource_agent_tool_call_count": "Agent Tool Calls",
@@ -1120,14 +1119,12 @@
"select_members": "Select Members",
"select_role": "Select Role",
"select_user": "Select User",
"select_skill": "Select Skill",
"select_mcp_server": "Select MCP Server",
"select_tool": "Select Tool",
"custom_id": "Custom ID",
"enter_custom_id": "Enter custom ID",
"bash_command_pattern": "Bash Match Wildcard",
"bash_command_pattern_placeholder": "e.g. * or npm*",
"enter_skill_id": "Enter Skill ID",
"enter_mcp_id": "Enter MCP Server ID",
"quota_bash_hint": "Supports wildcards (*). Examples: git *, npm test, curl *, python script.py (use * for all commands)",
"quota_tool_hint": "Select a specific agent tool to configure its quota limit"
+1 -4
View File
@@ -1071,7 +1071,6 @@
"quota_resource": "资源类型",
"quota_resource_agent_total_tokens": "AI Token 总量",
"quota_resource_agent_cost": "AI 费用 ($)",
"quota_resource_agent_skill_call_count": "Skill 调用次数",
"quota_resource_agent_mcp_call_count": "MCP 服务调用次数",
"quota_resource_agent_bash_call_count": "智能体 Bash 执行次数",
"quota_resource_agent_tool_call_count": "智能体工具调用次数",
@@ -1090,7 +1089,7 @@
"quota_period_resets": "重置于",
"quota_active_window": "生效周期",
"no_quotas_title": "暂未配置资源配额",
"no_quotas_description": "为 AI Token、费用、Skill 执行和智能体工具调用设置限制,以便管理团队的使用情况。",
"no_quotas_description": "为 AI Token、费用、MCP 服务和智能体工具调用设置限制,以便管理团队的使用情况。",
"delete_quota": "删除配额",
"delete_quota_confirm": "确定要删除此配额规则吗?此操作无法撤销。",
"quota_created_successfully": "配额规则创建成功",
@@ -1120,14 +1119,12 @@
"select_members": "选择成员",
"select_role": "选择角色",
"select_user": "选择用户",
"select_skill": "选择 Skill",
"select_mcp_server": "选择 MCP 服务",
"select_tool": "选择工具",
"custom_id": "自定义 ID",
"enter_custom_id": "输入自定义 ID",
"bash_command_pattern": "Bash 命令通配符",
"bash_command_pattern_placeholder": "例如 * 或 npm*",
"enter_skill_id": "输入技能 ID",
"enter_mcp_id": "输入 MCP 服务 ID",
"quota_bash_hint": "支持通配符 (*)。示例:git *、npm test、curl *、python script.py(使用 * 匹配所有命令)",
"quota_tool_hint": "选择特定的智能体工具以配置其配额限制"
-3
View File
@@ -1015,7 +1015,6 @@ export * from "./quota_scope_user_description.js";
export * from "./quota_resource.js";
export * from "./quota_resource_agent_total_tokens.js";
export * from "./quota_resource_agent_cost.js";
export * from "./quota_resource_agent_skill_call_count.js";
export * from "./quota_resource_agent_mcp_call_count.js";
export * from "./quota_resource_agent_bash_call_count.js";
export * from "./quota_resource_agent_tool_call_count.js";
@@ -1064,14 +1063,12 @@ export * from "./quota_selected_users_count.js";
export * from "./select_members.js";
export * from "./select_role.js";
export * from "./select_user.js";
export * from "./select_skill.js";
export * from "./select_mcp_server.js";
export * from "./select_tool.js";
export * from "./custom_id.js";
export * from "./enter_custom_id.js";
export * from "./bash_command_pattern.js";
export * from "./bash_command_pattern_placeholder.js";
export * from "./enter_skill_id.js";
export * from "./enter_mcp_id.js";
export * from "./quota_bash_hint.js";
export * from "./quota_tool_hint.js";
-3
View File
@@ -1017,7 +1017,6 @@ export * from './quota_scope_user_description.js'
export * from './quota_resource.js'
export * from './quota_resource_agent_total_tokens.js'
export * from './quota_resource_agent_cost.js'
export * from './quota_resource_agent_skill_call_count.js'
export * from './quota_resource_agent_mcp_call_count.js'
export * from './quota_resource_agent_bash_call_count.js'
export * from './quota_resource_agent_tool_call_count.js'
@@ -1066,14 +1065,12 @@ export * from './quota_selected_users_count.js'
export * from './select_members.js'
export * from './select_role.js'
export * from './select_user.js'
export * from './select_skill.js'
export * from './select_mcp_server.js'
export * from './select_tool.js'
export * from './custom_id.js'
export * from './enter_custom_id.js'
export * from './bash_command_pattern.js'
export * from './bash_command_pattern_placeholder.js'
export * from './enter_skill_id.js'
export * from './enter_mcp_id.js'
export * from './quota_bash_hint.js'
export * from './quota_tool_hint.js'
-16
View File
@@ -1,16 +0,0 @@
/**
* | output |
* | --- |
* | "Enter Skill ID" |
*
* @param {Enter_Skill_IdInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const enter_skill_id: ((inputs?: Enter_Skill_IdInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Enter_Skill_IdInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Enter_Skill_IdInputs = {};
-29
View File
@@ -1,29 +0,0 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Enter_Skill_IdInputs */
const en_enter_skill_id = /** @type {(inputs: Enter_Skill_IdInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Enter Skill ID`)
};
const zh_enter_skill_id = /** @type {(inputs: Enter_Skill_IdInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`输入技能 ID`)
};
/**
* | output |
* | --- |
* | "Enter Skill ID" |
*
* @param {Enter_Skill_IdInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const enter_skill_id = /** @type {((inputs?: Enter_Skill_IdInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Enter_Skill_IdInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_enter_skill_id(inputs)
return zh_enter_skill_id(inputs)
});
+1 -1
View File
@@ -10,7 +10,7 @@ const en_no_quotas_description = /** @type {(inputs: No_Quotas_DescriptionInputs
};
const zh_no_quotas_description = /** @type {(inputs: No_Quotas_DescriptionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`为 AI Token、费用、Skill 执行和智能体工具调用设置限制,以便管理团队的使用情况。`)
return /** @type {LocalizedString} */ (`为 AI Token、费用、MCP 服务和智能体工具调用设置限制,以便管理团队的使用情况。`)
};
/**
@@ -1,16 +0,0 @@
/**
* | output |
* | --- |
* | "Skill Calls" |
*
* @param {Quota_Resource_Agent_Skill_Call_CountInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const quota_resource_agent_skill_call_count: ((inputs?: Quota_Resource_Agent_Skill_Call_CountInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Quota_Resource_Agent_Skill_Call_CountInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Quota_Resource_Agent_Skill_Call_CountInputs = {};
@@ -1,29 +0,0 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Quota_Resource_Agent_Skill_Call_CountInputs */
const en_quota_resource_agent_skill_call_count = /** @type {(inputs: Quota_Resource_Agent_Skill_Call_CountInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Skill Calls`)
};
const zh_quota_resource_agent_skill_call_count = /** @type {(inputs: Quota_Resource_Agent_Skill_Call_CountInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Skill 调用次数`)
};
/**
* | output |
* | --- |
* | "Skill Calls" |
*
* @param {Quota_Resource_Agent_Skill_Call_CountInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const quota_resource_agent_skill_call_count = /** @type {((inputs?: Quota_Resource_Agent_Skill_Call_CountInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Quota_Resource_Agent_Skill_Call_CountInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_quota_resource_agent_skill_call_count(inputs)
return zh_quota_resource_agent_skill_call_count(inputs)
});
-16
View File
@@ -1,16 +0,0 @@
/**
* | output |
* | --- |
* | "Select Skill" |
*
* @param {Select_SkillInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const select_skill: ((inputs?: Select_SkillInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Select_SkillInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Select_SkillInputs = {};
-29
View File
@@ -1,29 +0,0 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Select_SkillInputs */
const en_select_skill = /** @type {(inputs: Select_SkillInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Select Skill`)
};
const zh_select_skill = /** @type {(inputs: Select_SkillInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`选择 Skill`)
};
/**
* | output |
* | --- |
* | "Select Skill" |
*
* @param {Select_SkillInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const select_skill = /** @type {((inputs?: Select_SkillInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Select_SkillInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_select_skill(inputs)
return zh_select_skill(inputs)
});