Merge branch 'ji'
This commit is contained in:
commit
82600a3404
25 files changed
+929
-279
No files matched your search
@@ -248,3 +248,38 @@ export interface KnowledgeGraph {
|
||||
export async function getKnowledgeGraph() {
|
||||
return parseResponse<KnowledgeGraph>(await apiFetch(`${baseUrl()}/graph`));
|
||||
}
|
||||
|
||||
// --- graph blacklist ---
|
||||
|
||||
export interface GraphBlacklistItem {
|
||||
id: string;
|
||||
label: string;
|
||||
created_by?: string | null;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
export async function getGraphBlacklist() {
|
||||
const res = await parseResponse<{ items: GraphBlacklistItem[] }>(
|
||||
await apiFetch(`${baseUrl()}/graph/blacklist`),
|
||||
);
|
||||
return res.items;
|
||||
}
|
||||
|
||||
/** Blacklist node labels (entity names / note titles); they disappear from the graph. */
|
||||
export async function addGraphBlacklist(labels: string[]) {
|
||||
return parseResponse<{ added: number; items: GraphBlacklistItem[] }>(
|
||||
await apiFetch(`${baseUrl()}/graph/blacklist`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ labels }),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function removeGraphBlacklist(entryId: string) {
|
||||
return parseResponse<{ ok: boolean }>(
|
||||
await apiFetch(`${baseUrl()}/graph/blacklist/${encodeURIComponent(entryId)}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -6,10 +6,12 @@ import {
|
||||
} from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
addGraphBlacklist,
|
||||
createKnowledgeNote,
|
||||
deleteKnowledgeNote,
|
||||
exportKnowledgeGraph,
|
||||
fetchVaultPage,
|
||||
getGraphBlacklist,
|
||||
getKnowledgeGraph,
|
||||
getKnowledgeNote,
|
||||
ingestKnowledgeFile,
|
||||
@@ -18,6 +20,7 @@ import {
|
||||
listDuplicates,
|
||||
listKnowledgeNotes,
|
||||
mergeKnowledgeNotes,
|
||||
removeGraphBlacklist,
|
||||
resolveNoteWikilinks,
|
||||
searchKnowledge,
|
||||
updateKnowledgeNote,
|
||||
@@ -80,6 +83,32 @@ export function useKnowledgeGraph() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useGraphBlacklist() {
|
||||
return useQuery({
|
||||
queryKey: [...ROOT_KEY, "graph-blacklist"],
|
||||
queryFn: getGraphBlacklist,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useGraphBlacklistActions() {
|
||||
const queryClient = useQueryClient();
|
||||
const invalidate = () => {
|
||||
void queryClient.invalidateQueries({ queryKey: [...ROOT_KEY, "graph"] });
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: [...ROOT_KEY, "graph-blacklist"],
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
add: useMutation({ mutationFn: addGraphBlacklist, onSuccess: invalidate }),
|
||||
remove: useMutation({
|
||||
mutationFn: removeGraphBlacklist,
|
||||
onSuccess: invalidate,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export function useKnowledgeActions() {
|
||||
const queryClient = useQueryClient();
|
||||
const invalidate = () =>
|
||||
|
||||
@@ -12,7 +12,7 @@ import { getAPIClient } from "../api";
|
||||
import { apiFetch } from "../api";
|
||||
import { getStoredAuth } from "../auth";
|
||||
import { rememberAskTime } from "../chat-timestamps";
|
||||
import { getBackendBaseURL } from "../config";
|
||||
import { getBackendBaseURL, getLangGraphBaseURL } from "../config";
|
||||
import { useI18n } from "../i18n/hooks";
|
||||
import type { FileInMessage } from "../messages/utils";
|
||||
import type { LocalSettings } from "../settings";
|
||||
@@ -761,14 +761,86 @@ export function useThreads(
|
||||
offset += response.length;
|
||||
}
|
||||
|
||||
return threads.filter(
|
||||
(t) => (t.metadata as Record<string, unknown> | null)?.thread_type !== "notebook",
|
||||
);
|
||||
// Safety net on top of the backend's system-thread exclusion: drop
|
||||
// machine-created threads (scheduled tasks, roundtable workers,
|
||||
// notebooks) in case an older backend still returns them.
|
||||
return threads.filter((t) => {
|
||||
const metadata = t.metadata as Record<string, unknown> | null;
|
||||
if (metadata?.system) return false;
|
||||
const threadType = metadata?.thread_type;
|
||||
return (
|
||||
threadType !== "notebook" &&
|
||||
threadType !== "scheduler" &&
|
||||
threadType !== "roundtable"
|
||||
);
|
||||
});
|
||||
},
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
export interface ThreadsPageResult {
|
||||
threads: AgentThread[];
|
||||
hasMore: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Server-side paginated conversation list for the chats page. Unlike
|
||||
* `useThreads` (which loads a bounded recent window for the sidebar), this
|
||||
* fetches exactly one page per request so a long history is never pulled in
|
||||
* one go. `search` matches thread titles on the backend; one extra row is
|
||||
* over-fetched only to detect whether a next page exists. The query key stays
|
||||
* under ["threads", "search"] so existing invalidations refresh pages too.
|
||||
*/
|
||||
export function useThreadsPage(options: {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
search?: string;
|
||||
metadata?: Record<string, unknown>;
|
||||
}) {
|
||||
const { page, pageSize, search, metadata } = options;
|
||||
const normalizedSearch = search?.trim() ?? "";
|
||||
return useQuery<ThreadsPageResult>({
|
||||
queryKey: [
|
||||
"threads",
|
||||
"search",
|
||||
"paged",
|
||||
page,
|
||||
pageSize,
|
||||
normalizedSearch,
|
||||
metadata ?? null,
|
||||
],
|
||||
queryFn: async () => {
|
||||
// Direct fetch instead of the LangGraph SDK: the SDK's threads.search
|
||||
// drops fields it doesn't know about, and `query` (title search) is a
|
||||
// gateway extension.
|
||||
const response = await apiFetch(
|
||||
`${getLangGraphBaseURL()}/threads/search`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
limit: pageSize + 1,
|
||||
offset: (page - 1) * pageSize,
|
||||
metadata: metadata ?? {},
|
||||
query: normalizedSearch || undefined,
|
||||
}),
|
||||
},
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to load conversations");
|
||||
}
|
||||
const rows = (await response.json()) as AgentThread[];
|
||||
return {
|
||||
threads: rows.slice(0, pageSize),
|
||||
hasMore: rows.length > pageSize,
|
||||
};
|
||||
},
|
||||
placeholderData: (previous) => previous,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteThread() {
|
||||
const queryClient = useQueryClient();
|
||||
const apiClient = getAPIClient();
|
||||
|
||||
Reference in new issue
Block a user