mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-22 07:56:48 +00:00
fix(frontend): preserve agent context in thread history routes (#1771)
* fix(frontend): preserve agent context in thread history routes * fix(frontend): preserve agent thread fallback context * style(frontend): format thread route utils test --------- Co-authored-by: luoxiao6645 <luoxiao6645@gmail.com>
This commit is contained in:
@@ -528,7 +528,7 @@ export function useThreads(
|
||||
limit: 50,
|
||||
sortBy: "updated_at",
|
||||
sortOrder: "desc",
|
||||
select: ["thread_id", "updated_at", "values"],
|
||||
select: ["thread_id", "updated_at", "values", "context"],
|
||||
},
|
||||
) {
|
||||
const apiClient = getAPIClient();
|
||||
|
||||
@@ -9,8 +9,6 @@ export interface AgentThreadState extends Record<string, unknown> {
|
||||
todos?: Todo[];
|
||||
}
|
||||
|
||||
export interface AgentThread extends Thread<AgentThreadState> {}
|
||||
|
||||
export interface AgentThreadContext extends Record<string, unknown> {
|
||||
thread_id: string;
|
||||
model_name: string | undefined;
|
||||
@@ -20,3 +18,7 @@ export interface AgentThreadContext extends Record<string, unknown> {
|
||||
reasoning_effort?: "minimal" | "low" | "medium" | "high";
|
||||
agent_name?: string;
|
||||
}
|
||||
|
||||
export interface AgentThread extends Thread<AgentThreadState> {
|
||||
context?: AgentThreadContext;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
const { pathOfThread } = await import(
|
||||
new URL("./utils.ts", import.meta.url).href
|
||||
);
|
||||
|
||||
void test("uses standard chat route when thread has no agent context", () => {
|
||||
assert.equal(pathOfThread("thread-123"), "/workspace/chats/thread-123");
|
||||
assert.equal(
|
||||
pathOfThread({
|
||||
thread_id: "thread-123",
|
||||
}),
|
||||
"/workspace/chats/thread-123",
|
||||
);
|
||||
});
|
||||
|
||||
void test("uses agent chat route when thread context has agent_name", () => {
|
||||
assert.equal(
|
||||
pathOfThread({
|
||||
thread_id: "thread-123",
|
||||
context: { agent_name: "researcher" },
|
||||
}),
|
||||
"/workspace/agents/researcher/chats/thread-123",
|
||||
);
|
||||
});
|
||||
|
||||
void test("uses provided context when pathOfThread is called with a thread id", () => {
|
||||
assert.equal(
|
||||
pathOfThread("thread-123", { agent_name: "ops agent" }),
|
||||
"/workspace/agents/ops%20agent/chats/thread-123",
|
||||
);
|
||||
});
|
||||
@@ -1,9 +1,28 @@
|
||||
import type { Message } from "@langchain/langgraph-sdk";
|
||||
|
||||
import type { AgentThread } from "./types";
|
||||
import type { AgentThread, AgentThreadContext } from "./types";
|
||||
|
||||
export function pathOfThread(threadId: string) {
|
||||
return `/workspace/chats/${threadId}`;
|
||||
type ThreadRouteTarget =
|
||||
| string
|
||||
| Pick<AgentThread, "thread_id" | "context">
|
||||
| {
|
||||
thread_id: string;
|
||||
context?: Pick<AgentThreadContext, "agent_name"> | null;
|
||||
};
|
||||
|
||||
export function pathOfThread(
|
||||
thread: ThreadRouteTarget,
|
||||
context?: Pick<AgentThreadContext, "agent_name"> | null,
|
||||
) {
|
||||
const threadId = typeof thread === "string" ? thread : thread.thread_id;
|
||||
const agentName =
|
||||
typeof thread === "string"
|
||||
? context?.agent_name
|
||||
: thread.context?.agent_name;
|
||||
|
||||
return agentName
|
||||
? `/workspace/agents/${encodeURIComponent(agentName)}/chats/${threadId}`
|
||||
: `/workspace/chats/${threadId}`;
|
||||
}
|
||||
|
||||
export function textOfMessage(message: Message) {
|
||||
|
||||
Reference in New Issue
Block a user