feat(*): 技能库与认证体验 - 重构共享技能库并优化登录页面与默认创作入口
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { imageReferenceLabel } from "@/lib/image-reference-prompt";
|
||||
import { seedanceReferenceLabel } from "@/lib/seedance-video";
|
||||
import type { UpdreamSkill } from "@/services/api/skills";
|
||||
import type { Skill } from "@/services/api/skills";
|
||||
import { CanvasNodeType, type CanvasConnection, type CanvasNodeData } from "@/types/canvas";
|
||||
|
||||
export type CanvasResourceKind = "image" | "video" | "audio" | "text" | "skill" | "character";
|
||||
@@ -16,11 +16,11 @@ export type CanvasResourceReference = {
|
||||
text?: string;
|
||||
active: boolean;
|
||||
sourceType?: CanvasNodeType;
|
||||
skill?: UpdreamSkill;
|
||||
skill?: Skill;
|
||||
};
|
||||
|
||||
export function canvasResourceMentionToken(reference: CanvasResourceReference) {
|
||||
if (reference.kind === "skill" && reference.skill?.dir) return `@[skill:${reference.skill.dir}]`;
|
||||
if (reference.kind === "skill" && reference.skill?.skill_id) return `@[skill:${reference.skill.skill_id}]`;
|
||||
return `@[node:${reference.nodeId}]`;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import type { CanvasResourceReference } from "@/lib/canvas/canvas-resource-references";
|
||||
import type { UpdreamSkill } from "@/services/api/skills";
|
||||
import type { Skill } from "@/services/api/skills";
|
||||
|
||||
const SKILL_REF_PATTERN = /@\[skill:([^\]]+)\]/g;
|
||||
|
||||
export function buildSkillMentionReferences(skills: UpdreamSkill[]): CanvasResourceReference[] {
|
||||
export function buildSkillMentionReferences(skills: Skill[]): CanvasResourceReference[] {
|
||||
return skills
|
||||
.filter((skill) => skill.activated ?? true)
|
||||
.filter((skill) => skill.is_added)
|
||||
.map((skill) => ({
|
||||
id: `skill:${skill.dir}`,
|
||||
nodeId: `skill:${skill.dir}`,
|
||||
id: `skill:${skill.skill_id}`,
|
||||
nodeId: `skill:${skill.skill_id}`,
|
||||
kind: "skill" as const,
|
||||
label: skill.name,
|
||||
title: skill.name,
|
||||
text: skill.description || skill.detail_text,
|
||||
label: skill.skill_name,
|
||||
title: skill.skill_name,
|
||||
text: skill.instruction || skill.description,
|
||||
active: true,
|
||||
skill,
|
||||
}));
|
||||
}
|
||||
|
||||
export function expandSkillMentions(prompt: string, skills: UpdreamSkill[]) {
|
||||
export function expandSkillMentions(prompt: string, skills: Skill[]) {
|
||||
if (!prompt.trim()) return prompt;
|
||||
const activeSkills = skills.filter((skill) => skill.activated ?? true);
|
||||
const activeSkills = skills.filter((skill) => skill.is_added);
|
||||
if (!activeSkills.length) return prompt;
|
||||
|
||||
const byId = new Map(activeSkills.map((skill) => [skill.dir, skill]));
|
||||
const byId = new Map(activeSkills.map((skill) => [skill.skill_id, skill]));
|
||||
let next = prompt.replace(SKILL_REF_PATTERN, (token, id) => {
|
||||
const skill = byId.get(id);
|
||||
return skill ? renderSkillPrompt(skill) : token;
|
||||
@@ -31,7 +31,7 @@ export function expandSkillMentions(prompt: string, skills: UpdreamSkill[]) {
|
||||
|
||||
activeSkills
|
||||
.slice()
|
||||
.sort((a, b) => b.name.length - a.name.length)
|
||||
.sort((a, b) => b.skill_name.length - a.skill_name.length)
|
||||
.forEach((skill) => {
|
||||
next = replaceNaturalSkillMention(next, skill);
|
||||
});
|
||||
@@ -39,19 +39,19 @@ export function expandSkillMentions(prompt: string, skills: UpdreamSkill[]) {
|
||||
return next;
|
||||
}
|
||||
|
||||
export function renderSkillPrompt(skill: Pick<UpdreamSkill, "name" | "description" | "detail_text">) {
|
||||
export function renderSkillPrompt(skill: Pick<Skill, "skill_name" | "description" | "instruction">) {
|
||||
return [
|
||||
`【技能:${skill.name}】`,
|
||||
`【技能:${skill.skill_name}】`,
|
||||
skill.description ? `用途:${skill.description}` : "",
|
||||
skill.detail_text ? `技能详情:\n${skill.detail_text}` : "",
|
||||
skill.instruction ? `执行指令:\n${skill.instruction}` : "",
|
||||
"请严格执行该技能,只输出结果,不要输出解释性套话。",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n\n");
|
||||
}
|
||||
|
||||
function replaceNaturalSkillMention(value: string, skill: UpdreamSkill) {
|
||||
const token = `@${skill.name}`;
|
||||
function replaceNaturalSkillMention(value: string, skill: Skill) {
|
||||
const token = `@${skill.skill_name}`;
|
||||
let result = "";
|
||||
let index = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user