Merge branch 'master' of http://192.168.0.200/knowledge-base-bj/deerflow-server into xuhd
This commit is contained in:
commit
9a67ca7c03
97 files changed
+20759
-306
No files matched your search
@@ -59,7 +59,7 @@ export const zhCN: Translations = {
|
||||
|
||||
// Welcome
|
||||
welcome: {
|
||||
greeting: "你好,欢迎回来!",
|
||||
greeting: "你好,欢迎使用CM助手",
|
||||
description:
|
||||
"欢迎使用 CM 助手",
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { apiFetch } from "@/core/api";
|
||||
import { getBackendBaseURL } from "@/core/config";
|
||||
|
||||
import type {
|
||||
CreateQuestionRequest,
|
||||
RecommendedQuestion,
|
||||
UpdateQuestionRequest,
|
||||
} from "./index";
|
||||
|
||||
const BASE = () => `${getBackendBaseURL()}/api/recommended-questions`;
|
||||
|
||||
export async function listRecommendedQuestions(): Promise<RecommendedQuestion[]> {
|
||||
const res = await apiFetch(BASE());
|
||||
if (!res.ok) throw new Error(`Failed to load questions: ${res.statusText}`);
|
||||
const data = (await res.json()) as { questions: RecommendedQuestion[] };
|
||||
return data.questions;
|
||||
}
|
||||
|
||||
export async function createRecommendedQuestion(
|
||||
body: CreateQuestionRequest,
|
||||
): Promise<RecommendedQuestion> {
|
||||
const res = await apiFetch(BASE(), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = (await res.json().catch(() => ({}))) as { detail?: string };
|
||||
throw new Error(err.detail ?? `Failed to create question: ${res.statusText}`);
|
||||
}
|
||||
return res.json() as Promise<RecommendedQuestion>;
|
||||
}
|
||||
|
||||
export async function updateRecommendedQuestion(
|
||||
id: string,
|
||||
body: UpdateQuestionRequest,
|
||||
): Promise<RecommendedQuestion> {
|
||||
const res = await apiFetch(`${BASE()}/${id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = (await res.json().catch(() => ({}))) as { detail?: string };
|
||||
throw new Error(err.detail ?? `Failed to update question: ${res.statusText}`);
|
||||
}
|
||||
return res.json() as Promise<RecommendedQuestion>;
|
||||
}
|
||||
|
||||
export async function deleteRecommendedQuestion(id: string): Promise<void> {
|
||||
const res = await apiFetch(`${BASE()}/${id}`, { method: "DELETE" });
|
||||
if (!res.ok) throw new Error(`Failed to delete question: ${res.statusText}`);
|
||||
}
|
||||
|
||||
export async function reorderRecommendedQuestions(
|
||||
ids: string[],
|
||||
): Promise<RecommendedQuestion[]> {
|
||||
const res = await apiFetch(`${getBackendBaseURL()}/api/recommended-questions-reorder`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ ids }),
|
||||
});
|
||||
if (!res.ok) throw new Error(`Failed to reorder questions: ${res.statusText}`);
|
||||
const data = (await res.json()) as { questions: RecommendedQuestion[] };
|
||||
return data.questions;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
createRecommendedQuestion,
|
||||
deleteRecommendedQuestion,
|
||||
listRecommendedQuestions,
|
||||
reorderRecommendedQuestions,
|
||||
updateRecommendedQuestion,
|
||||
} from "./api";
|
||||
import type { CreateQuestionRequest, UpdateQuestionRequest } from "./index";
|
||||
|
||||
const QK = ["recommended-questions"] as const;
|
||||
|
||||
export function useRecommendedQuestions() {
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: QK,
|
||||
queryFn: listRecommendedQuestions,
|
||||
});
|
||||
return { questions: data ?? [], isLoading, error };
|
||||
}
|
||||
|
||||
export function useCreateRecommendedQuestion() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (body: CreateQuestionRequest) => createRecommendedQuestion(body),
|
||||
onSuccess: () => void qc.invalidateQueries({ queryKey: QK }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateRecommendedQuestion() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, body }: { id: string; body: UpdateQuestionRequest }) =>
|
||||
updateRecommendedQuestion(id, body),
|
||||
onSuccess: () => void qc.invalidateQueries({ queryKey: QK }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteRecommendedQuestion() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => deleteRecommendedQuestion(id),
|
||||
onSuccess: () => void qc.invalidateQueries({ queryKey: QK }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useReorderRecommendedQuestions() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (ids: string[]) => reorderRecommendedQuestions(ids),
|
||||
onSuccess: () => void qc.invalidateQueries({ queryKey: QK }),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
export interface RecommendedQuestion {
|
||||
id: string;
|
||||
title: string;
|
||||
content: string;
|
||||
sort_order: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface CreateQuestionRequest {
|
||||
title: string;
|
||||
content: string;
|
||||
sort_order?: number;
|
||||
}
|
||||
|
||||
export interface UpdateQuestionRequest {
|
||||
title?: string;
|
||||
content?: string;
|
||||
sort_order?: number;
|
||||
}
|
||||
@@ -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