Files
DeepTutor/web/lib/knowledge-api.ts
Bingxi Zhao (Frank) 4b7d24d33e release: v1.2.3 — document attachments, thinking blocks, provider core refactor
- Chat document attachments (PDF/DOCX/XLSX/PPTX) with text extraction
- Reasoning model <think> block display as collapsible cards
- Tri-state send_dimensions toggle for embeddings (#368)
- LLM provider_core module refactor + context_window detection
- Soul template editor (PR #373), Co-Writer save-to-notebook
- Knowledge Base drag-and-drop upload, delete resilience (#370),
  progress persistence, supported-file-types endpoint
- Question generation language fidelity via shared prompt directives
- Settings tour redesign, CLI notebook add-md/replace-md
- Bug fixes: CJK bot name slug, I18nProvider init, Skills default off,
  Moonshot base URL, version badge
- Provider registry: custom_anthropic, thinking_style, alias expansion
- +1900 test lines across 15 new/expanded test files

Made-with: Cursor
2026-04-24 22:36:32 +08:00

98 lines
2.6 KiB
TypeScript

import { apiUrl } from "@/lib/api";
import { invalidateClientCache, withClientCache } from "@/lib/client-cache";
const KNOWLEDGE_CACHE_PREFIX = "knowledge:";
export interface KnowledgeBaseSummary {
name: string;
is_default?: boolean;
status?: string;
path?: string;
metadata?: Record<string, unknown>;
progress?: Record<string, unknown>;
statistics?: Record<string, unknown>;
}
export interface RagProviderSummary {
id: string;
name: string;
description: string;
}
export interface KnowledgeUploadPolicy {
extensions: string[];
accept: string;
max_file_size_bytes: number;
max_pdf_size_bytes: number;
}
export async function listKnowledgeBases(options?: { force?: boolean }) {
return withClientCache<KnowledgeBaseSummary[]>(
`${KNOWLEDGE_CACHE_PREFIX}list`,
async () => {
const response = await fetch(apiUrl("/api/v1/knowledge/list"), {
cache: "no-store",
});
const data = await response.json();
return Array.isArray(data)
? data
: Array.isArray(data?.knowledge_bases)
? data.knowledge_bases
: [];
},
{
force: options?.force,
},
);
}
export async function listRagProviders(options?: { force?: boolean }) {
return withClientCache<RagProviderSummary[]>(
`${KNOWLEDGE_CACHE_PREFIX}providers`,
async () => {
const response = await fetch(apiUrl("/api/v1/knowledge/rag-providers"), {
cache: "no-store",
});
const data = await response.json();
return Array.isArray(data?.providers) ? data.providers : [];
},
{
force: options?.force,
},
);
}
export async function getKnowledgeUploadPolicy(options?: { force?: boolean }) {
return withClientCache<KnowledgeUploadPolicy>(
`${KNOWLEDGE_CACHE_PREFIX}upload-policy`,
async () => {
const response = await fetch(
apiUrl("/api/v1/knowledge/supported-file-types"),
{
cache: "no-store",
},
);
const data = await response.json();
return {
extensions: Array.isArray(data?.extensions) ? data.extensions : [],
accept: typeof data?.accept === "string" ? data.accept : "",
max_file_size_bytes:
typeof data?.max_file_size_bytes === "number"
? data.max_file_size_bytes
: 100 * 1024 * 1024,
max_pdf_size_bytes:
typeof data?.max_pdf_size_bytes === "number"
? data.max_pdf_size_bytes
: 50 * 1024 * 1024,
};
},
{
force: options?.force,
},
);
}
export function invalidateKnowledgeCaches() {
invalidateClientCache(KNOWLEDGE_CACHE_PREFIX);
}