refactor(workspace): extract resolveMentionCommandUsage (R-32 eighth cut)

R-32 eighth cut:提取 resolveMentionCommandUsage 函数

提取内容(43 行):
- resolveMentionCommandUsage 函数
- CompletedMentionUsage 类型定义
- 原文件:3852 → 3809 行(累计减少 1308 行,-25.6%)

验证:
- 文件体量守卫通过
- import 边界守卫通过
This commit is contained in:
coso
2026-06-11 14:29:18 +08:00
parent c4712595cd
commit 52acb696c7
2 changed files with 56 additions and 45 deletions
@@ -6,7 +6,17 @@
* @module mentionCommandUtils
*/
import type { ServiceSkillSlotValues } from "../../service-skills/types";
import type {
ServiceSkillHomeItem,
ServiceSkillSlotValues,
} from "../../service-skills/types";
export type CompletedMentionUsage = {
skillId: string;
runnerType: ServiceSkillHomeItem["runnerType"];
slotValues?: ServiceSkillSlotValues;
launchUserInput?: string;
};
import {
buildMentionCommandReplayText,
resolveMentionCommandPrefillReplayText,
@@ -402,3 +412,47 @@ export function resolveBareMentionCommandPrefillSourceText(
return `${matched.commandPrefix} ${replayText}`;
}
export function resolveMentionCommandUsage(params: {
commandKey: string;
serviceSkills: ServiceSkillHomeItem[];
requestMetadata?: Record<string, unknown>;
mentionCommandSkillIdMap: Map<string, string>;
}): CompletedMentionUsage | null {
const normalizedCommandKey = params.commandKey.trim();
if (!normalizedCommandKey) {
return null;
}
const boundSkillId =
params.mentionCommandSkillIdMap.get(normalizedCommandKey);
if (!boundSkillId) {
return null;
}
const matchedSkill = params.serviceSkills.find((skill) => {
const normalizedSkillId = skill.id.trim();
const normalizedSkillKey = skill.skillKey?.trim();
return (
normalizedSkillId === boundSkillId || normalizedSkillKey === boundSkillId
);
});
if (!matchedSkill) {
return null;
}
const slotValues = resolveMentionCommandUsageSlotValues(
params.requestMetadata,
);
const launchUserInput = resolveMentionCommandUsageLaunchUserInput(
params.requestMetadata,
);
return {
skillId: matchedSkill.id,
runnerType: matchedSkill.runnerType,
...(slotValues ? { slotValues } : {}),
...(launchUserInput ? { launchUserInput } : {}),
};
}
@@ -236,6 +236,7 @@ import {
resolveMentionCommandReplayText,
resolveBareMentionCommandPrefillSourceText,
} from "./commands/mentionCommandUtils";
import { resolveMentionCommandUsage } from "./commands/mentionCommandUtils";
type CurrentExecutionStrategy = "react";
type SetStringState = (value: string) => void;
@@ -582,50 +583,6 @@ function buildImageWorkbenchAssistantDraft(
// 命令 recent defaults 合并函数已提取到 ./commands/commandRecentDefaults.ts
// build*DispatchBody 函数已提取到 ./commands/dispatchBodyBuilders.ts
function resolveMentionCommandUsage(params: {
commandKey: string;
serviceSkills: ServiceSkillHomeItem[];
requestMetadata?: Record<string, unknown>;
mentionCommandSkillIdMap: Map<string, string>;
}): CompletedMentionUsage | null {
const normalizedCommandKey = params.commandKey.trim();
if (!normalizedCommandKey) {
return null;
}
const boundSkillId =
params.mentionCommandSkillIdMap.get(normalizedCommandKey);
if (!boundSkillId) {
return null;
}
const matchedSkill = params.serviceSkills.find((skill) => {
const normalizedSkillId = skill.id.trim();
const normalizedSkillKey = skill.skillKey?.trim();
return (
normalizedSkillId === boundSkillId || normalizedSkillKey === boundSkillId
);
});
if (!matchedSkill) {
return null;
}
const slotValues = resolveMentionCommandUsageSlotValues(
params.requestMetadata,
);
const launchUserInput = resolveMentionCommandUsageLaunchUserInput(
params.requestMetadata,
);
return {
skillId: matchedSkill.id,
runnerType: matchedSkill.runnerType,
...(slotValues ? { slotValues } : {}),
...(launchUserInput ? { launchUserInput } : {}),
};
}
}
// matchesVoice/GrowthCommandSkill + resolve*CommandServiceSkill 已提取到 ./commands/serviceSkillMatch.ts