feat(frontend): 同步 agent 页面头部并保留本地行为

This commit is contained in:
肖应宇 2026-03-29 00:11:01 +08:00
parent a0ce3d8b08
commit 7071ead062
3 changed files with 11 additions and 9 deletions

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
"use client"; "use client";
import type { UseStream } from "@langchain/langgraph-sdk/react";
import { BotIcon, PlusSquare } from "lucide-react"; import { BotIcon, PlusSquare } from "lucide-react";
import { useParams, useRouter } from "next/navigation"; import { useParams, useRouter } from "next/navigation";
import { useCallback } from "react"; import { useCallback } from "react";
@ -23,6 +22,7 @@ import { useAgent } from "@/core/agents";
import { useI18n } from "@/core/i18n/hooks"; import { useI18n } from "@/core/i18n/hooks";
import { useNotification } from "@/core/notification/hooks"; import { useNotification } from "@/core/notification/hooks";
import { useLocalSettings } from "@/core/settings"; import { useLocalSettings } from "@/core/settings";
import type { AgentThreadState } from "@/core/threads";
import { useThreadStream } from "@/core/threads/hooks"; import { useThreadStream } from "@/core/threads/hooks";
import { textOfMessage } from "@/core/threads/utils"; import { textOfMessage } from "@/core/threads/utils";
import { env } from "@/env"; import { env } from "@/env";
@ -82,6 +82,7 @@ export default function AgentChatPage() {
const handleStop = useCallback(async () => { const handleStop = useCallback(async () => {
await thread.stop(); await thread.stop();
}, [thread]); }, [thread]);
const legacyThread = thread as unknown as UseStream<AgentThreadState>;
return ( return (
<ThreadContext.Provider value={{ thread }}> <ThreadContext.Provider value={{ thread }}>
@ -104,7 +105,7 @@ export default function AgentChatPage() {
</div> </div>
<div className="flex w-full items-center text-sm font-medium"> <div className="flex w-full items-center text-sm font-medium">
<ThreadTitle threadId={threadId} thread={thread} /> <ThreadTitle threadId={threadId} thread={legacyThread} />
</div> </div>
<div className="mr-4 flex items-center"> <div className="mr-4 flex items-center">
<Tooltip content={t.agents.newChat}> <Tooltip content={t.agents.newChat}>
@ -129,7 +130,7 @@ export default function AgentChatPage() {
<MessageList <MessageList
className={cn("size-full", !isNewThread && "pt-10")} className={cn("size-full", !isNewThread && "pt-10")}
threadId={threadId} threadId={threadId}
thread={thread} thread={legacyThread}
/> />
</div> </div>
@ -158,7 +159,6 @@ export default function AgentChatPage() {
<InputBox <InputBox
className={cn("bg-background/5 w-full -translate-y-4")} className={cn("bg-background/5 w-full -translate-y-4")}
isNewThread={isNewThread} isNewThread={isNewThread}
threadId={threadId}
autoFocus={isNewThread} autoFocus={isNewThread}
status={ status={
thread.error thread.error

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
"use client"; "use client";
import type { UseStream } from "@langchain/langgraph-sdk/react";
import { ArrowLeftIcon, BotIcon, CheckCircleIcon } from "lucide-react"; import { ArrowLeftIcon, BotIcon, CheckCircleIcon } from "lucide-react";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useCallback, useMemo, useState } from "react"; import { useCallback, useMemo, useState } from "react";
@ -20,6 +19,7 @@ import { ThreadContext } from "@/components/workspace/messages/context";
import type { Agent } from "@/core/agents"; import type { Agent } from "@/core/agents";
import { checkAgentName, getAgent } from "@/core/agents/api"; import { checkAgentName, getAgent } from "@/core/agents/api";
import { useI18n } from "@/core/i18n/hooks"; import { useI18n } from "@/core/i18n/hooks";
import type { AgentThreadState } from "@/core/threads";
import { useThreadStream } from "@/core/threads/hooks"; import { useThreadStream } from "@/core/threads/hooks";
import { uuid } from "@/core/utils/uuid"; import { uuid } from "@/core/utils/uuid";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
@ -120,6 +120,7 @@ export default function NewAgentPage() {
); );
// ── Shared header ────────────────────────────────────────────────────────── // ── Shared header ──────────────────────────────────────────────────────────
const legacyThread = thread as unknown as UseStream<AgentThreadState>;
const header = ( const header = (
<header className="flex shrink-0 items-center gap-3 border-b px-4 py-3"> <header className="flex shrink-0 items-center gap-3 border-b px-4 py-3">
@ -199,7 +200,7 @@ export default function NewAgentPage() {
<MessageList <MessageList
className="size-full pt-10" className="size-full pt-10"
threadId={threadId} threadId={threadId}
thread={thread} thread={legacyThread}
/> />
</div> </div>

View File

@ -38,7 +38,8 @@
"**/*.tsx", "**/*.tsx",
"**/*.cjs", "**/*.cjs",
"**/*.js", "**/*.js",
".next/types/**/*.ts" ".next/types/**/*.ts",
".next/dev/types/**/*.ts"
], ],
"exclude": ["node_modules", "generated", "imports"] "exclude": ["node_modules", "generated", "imports"]
} }