This commit is contained in:
2026-07-30 08:42:55 +08:00
parent 48b7391365
commit 1867649527
19 changed files with 1877 additions and 486 deletions

View File

@ -10,6 +10,11 @@ import {
listMessages,
} from "@/lib/db";
import { hasDeepSeekApiKey } from "@/lib/deepseek";
import {
pinSkillsToSnapshots,
snapshotsForSkills,
} from "@/lib/skill-snapshots";
import { classifyContinuationReply } from "@/lib/skill-continuation";
import type { ChatMessage, Skill } from "@/lib/types";
import { createId } from "@/lib/utils";
import { chatRequestSchema } from "@/lib/validation";
@ -44,11 +49,27 @@ export async function POST(request: Request) {
const continuation = getConversationContinuation(
input.conversationId,
);
const selectedSkills = [...new Set(input.selectedSkillIds)]
const currentSelectedSkills = [...new Set(input.selectedSkillIds)]
.map((id) => getSkill(id))
.filter(
(skill): skill is Skill => skill?.status === "active",
);
const replyKind = classifyContinuationReply(input.message);
const continuesExistingTask =
!["complete", "abandoned"].includes(continuation.state) &&
replyKind !== "new_topic" &&
replyKind !== "decline";
const retainedSnapshots = continuesExistingTask
? continuation.skillSnapshots
: [];
const selectedSkills = pinSkillsToSnapshots(
currentSelectedSkills,
retainedSnapshots,
);
const skillSnapshots = snapshotsForSkills(
selectedSkills,
retainedSnapshots,
);
const userMessageId = createId("message");
const assistantMessageId = createId("message");
@ -63,6 +84,8 @@ export async function POST(request: Request) {
content: input.message,
selectedSkillIds: selectedSkills.map((skill) => skill.id),
usedSkillIds: [],
skillSnapshots,
skillExecutions: [],
status: "complete",
createdAt: now,
},
@ -72,6 +95,8 @@ export async function POST(request: Request) {
content: "",
selectedSkillIds: selectedSkills.map((skill) => skill.id),
usedSkillIds: [],
skillSnapshots,
skillExecutions: [],
status: "streaming",
createdAt: new Date(Date.now() + 1).toISOString(),
},
@ -109,6 +134,7 @@ export async function POST(request: Request) {
conversationId: input.conversationId,
userMessage: input.message,
selectedSkills,
skillSnapshots,
continuation,
history,
});