页面结构修改
This commit is contained in:
1 parent
543d78e040
commit
8ecc32da6d
14 files changed
+87
-29
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { createContext, useCallback, useContext } from "react";
|
||||
import { useNavigate, type NavigateOptions } from "react-router-dom";
|
||||
|
||||
export const RouteBaseContext = createContext("/page/workspace");
|
||||
export const RouteBaseProvider = RouteBaseContext.Provider;
|
||||
|
||||
export function useRouteBase() {
|
||||
return useContext(RouteBaseContext);
|
||||
}
|
||||
|
||||
export function useRouteNavigate() {
|
||||
const navigate = useNavigate();
|
||||
const base = useRouteBase();
|
||||
return useCallback(
|
||||
(path: string | number, opts?: NavigateOptions) => {
|
||||
if (typeof path === "string") {
|
||||
navigate(path.replace("/page/workspace", base), opts);
|
||||
} else {
|
||||
navigate(path);
|
||||
}
|
||||
},
|
||||
[navigate, base],
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useContext } from "react";
|
||||
import type { Message } from "@langchain/langgraph-sdk";
|
||||
|
||||
import { RouteBaseContext } from "@/core/route-base";
|
||||
import type { AgentThread, AgentThreadContext } from "./types";
|
||||
|
||||
type ThreadAgentRef = Pick<AgentThreadContext, "agent_id" | "agent_name">;
|
||||
@@ -28,6 +30,7 @@ function pickAgentRef(
|
||||
export function pathOfThread(
|
||||
thread: ThreadRouteTarget,
|
||||
context?: ThreadAgentRef | null,
|
||||
base = "/page/workspace",
|
||||
) {
|
||||
const threadId = typeof thread === "string" ? thread : thread.thread_id;
|
||||
const agentRef =
|
||||
@@ -36,8 +39,14 @@ export function pathOfThread(
|
||||
: pickAgentRef(thread.context, thread.metadata);
|
||||
|
||||
return agentRef
|
||||
? `/page/workspace/agents/${encodeURIComponent(agentRef)}/chats/${threadId}`
|
||||
: `/page/workspace/chats/${threadId}`;
|
||||
? `${base}/agents/${encodeURIComponent(agentRef)}/chats/${threadId}`
|
||||
: `${base}/chats/${threadId}`;
|
||||
}
|
||||
|
||||
export function usePathOfThread() {
|
||||
const base = useContext(RouteBaseContext);
|
||||
return (thread: ThreadRouteTarget, context?: ThreadAgentRef | null) =>
|
||||
pathOfThread(thread, context, base);
|
||||
}
|
||||
|
||||
export function textOfMessage(message: Message) {
|
||||
|
||||
Reference in new issue
Block a user