update
This commit is contained in:
@ -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,
|
||||
});
|
||||
|
||||
@ -1,6 +1,30 @@
|
||||
import { ChatWorkspace } from "@/components/chat-workspace";
|
||||
import {
|
||||
getActiveChatRun,
|
||||
getConversationContinuation,
|
||||
getDefaultConversation,
|
||||
listMessages,
|
||||
listSkills,
|
||||
} from "@/lib/db";
|
||||
import { hasDeepSeekApiKey } from "@/lib/deepseek";
|
||||
import { connection } from "next/server";
|
||||
|
||||
export default function Home() {
|
||||
return <ChatWorkspace />;
|
||||
export default async function Home() {
|
||||
await connection();
|
||||
const conversation = getDefaultConversation();
|
||||
const activeRun = getActiveChatRun(conversation.id);
|
||||
const continuation = getConversationContinuation(conversation.id);
|
||||
|
||||
return (
|
||||
<ChatWorkspace
|
||||
initialData={{
|
||||
skills: listSkills(),
|
||||
conversation,
|
||||
messages: listMessages(conversation.id),
|
||||
activeRun,
|
||||
continuation,
|
||||
apiConfigured: hasDeepSeekApiKey(),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user