mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 05:20:33 +08:00
refactor(web): split knowledge clients and engine forms
This commit is contained in:
@@ -20,7 +20,7 @@ import type { Book, BookDepth, BookProposal } from "@/lib/book-types";
|
||||
import {
|
||||
listKnowledgeBases,
|
||||
type KnowledgeBaseSummary,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/catalog";
|
||||
import { SUBAGENT_KB_TYPE } from "@/lib/knowledge-helpers";
|
||||
import {
|
||||
getNotebook,
|
||||
|
||||
@@ -43,7 +43,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { apiFetch, apiUrl } from "@/lib/api";
|
||||
import { listKnowledgeBases } from "@/lib/knowledge-api";
|
||||
import { listKnowledgeBases } from "@/features/knowledge/api/catalog";
|
||||
import {
|
||||
exportCoWriterDocx,
|
||||
getCoWriterDocument,
|
||||
|
||||
@@ -41,7 +41,7 @@ import {
|
||||
import {
|
||||
listKnowledgeBases,
|
||||
type KnowledgeBaseSummary,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/catalog";
|
||||
import { listLLMOptions, type LLMOption } from "@/lib/llm-options";
|
||||
import type { SelectedRecord } from "@/lib/notebook-selection-types";
|
||||
import type { SpaceMemoryFile } from "@/lib/space-items";
|
||||
|
||||
@@ -23,14 +23,16 @@ import {
|
||||
getLlamaIndexConfig,
|
||||
getPageIndexConfig,
|
||||
probeLightRagServer,
|
||||
type LightRagServerProbe,
|
||||
} from "@/features/knowledge/api/engines";
|
||||
import {
|
||||
probeLinkedFolder,
|
||||
probeWeKnora,
|
||||
type KnowledgeUploadPolicy,
|
||||
type LightRagServerProbe,
|
||||
type LinkedFolderProbe,
|
||||
type RagProviderSummary,
|
||||
type WeKnoraProbe,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/catalog";
|
||||
import {
|
||||
createProviders,
|
||||
IMA_PROVIDER,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
import { useCallback, useMemo, useRef, useState, type DragEvent } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { AlertTriangle, CheckCircle2, FileText, Files, X } from "lucide-react";
|
||||
import type { KnowledgeUploadPolicy } from "@/lib/knowledge-api";
|
||||
import type { KnowledgeUploadPolicy } from "@/features/knowledge/model/types";
|
||||
import {
|
||||
formatFileSize,
|
||||
mergeSelectedFiles,
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
listKnowledgeBaseFiles,
|
||||
moveKbFile,
|
||||
type KnowledgeBaseFile,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/files";
|
||||
import { docIconFor, formatBytes } from "@/lib/doc-attachments";
|
||||
|
||||
interface KbDocumentListProps {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { FolderInput, Loader2, RefreshCw, Upload } from "lucide-react";
|
||||
import {
|
||||
listKnowledgeBaseFiles,
|
||||
type KnowledgeUploadPolicy,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/files";
|
||||
import {
|
||||
kbIsUploadable,
|
||||
kbNeedsReindex,
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
knowledgeBaseFilePath,
|
||||
knowledgeBaseFilePreviewTextPath,
|
||||
type KnowledgeBaseFile,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/files";
|
||||
import type { KnowledgeBase } from "@/lib/knowledge-helpers";
|
||||
import type { TaskState } from "@/hooks/useKnowledgeProgress";
|
||||
import type { FilePreviewSource } from "@/components/chat/preview/previewerFor";
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
syncGitHubSources,
|
||||
type GitHubSource,
|
||||
type GitHubSyncResult,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/sources";
|
||||
import { formatKnowledgeTimestamp } from "@/lib/knowledge-helpers";
|
||||
|
||||
interface KbGitHubSourcesSectionProps {
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
removeWebSource,
|
||||
syncWebSources,
|
||||
type WebSource,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/sources";
|
||||
import { formatKnowledgeTimestamp } from "@/lib/knowledge-helpers";
|
||||
|
||||
interface KbWebSourcesSectionProps {
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
Star,
|
||||
Upload,
|
||||
} from "lucide-react";
|
||||
import type { KnowledgeUploadPolicy } from "@/lib/knowledge-api";
|
||||
import type { KnowledgeUploadPolicy } from "@/features/knowledge/model/types";
|
||||
import {
|
||||
formatKnowledgeTimestamp,
|
||||
isMarginNoteKb,
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
type ProviderConnectionStatus,
|
||||
type KnowledgeBase,
|
||||
} from "@/lib/knowledge-helpers";
|
||||
import type { RagProviderSummary } from "@/lib/knowledge-api";
|
||||
import type { RagProviderSummary } from "@/features/knowledge/model/types";
|
||||
import { knowledgeEngineGroup } from "@/lib/knowledge-engine-group";
|
||||
import KnowledgeEngineIcon, {
|
||||
knowledgeSourceIconId,
|
||||
|
||||
@@ -5,10 +5,10 @@ import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useKnowledgeBases } from "@/hooks/useKnowledgeBases";
|
||||
import { updateRagProviderMode } from "@/lib/knowledge-api";
|
||||
import { updateRagProviderMode } from "@/features/knowledge/api/engines";
|
||||
import KnowledgeBaseDetail from "./KnowledgeBaseDetail";
|
||||
import KnowledgeHome, { type KnowledgeHomeSection } from "./KnowledgeHome";
|
||||
import EngineDetail from "./EngineDetail";
|
||||
import EngineDetail from "@/features/knowledge/components/engines/EngineDetail";
|
||||
import CreateKbModal from "./CreateKbModal";
|
||||
|
||||
export default function KnowledgePage() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
getPageIndexConfig,
|
||||
updatePageIndexConfig,
|
||||
type PageIndexConfig,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/engines";
|
||||
|
||||
interface PageIndexSettingsModalProps {
|
||||
isOpen: boolean;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { BookOpen, Database, NotebookPen } from "lucide-react";
|
||||
import { listKnowledgeBases } from "@/lib/knowledge-api";
|
||||
import { listKnowledgeBases } from "@/features/knowledge/api/catalog";
|
||||
import { listSkills } from "@/lib/skills-api";
|
||||
import { listNotebooks } from "@/lib/notebook-api";
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ import {
|
||||
type DeepResearchFormConfig,
|
||||
type OutlineItem,
|
||||
} from "@/lib/research-types";
|
||||
import { listKnowledgeBases } from "@/lib/knowledge-api";
|
||||
import { listKnowledgeBases } from "@/features/knowledge/api/catalog";
|
||||
import { getSubagentSettings } from "@/lib/subagents-api";
|
||||
import { useLLMOptions } from "@/hooks/useLLMOptions";
|
||||
import {
|
||||
|
||||
32
web/features/knowledge/api/catalog.ts
Normal file
32
web/features/knowledge/api/catalog.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export {
|
||||
connectImaKnowledgeBase,
|
||||
connectLinkedFolder,
|
||||
connectMarginNote4Library,
|
||||
connectObsidianVault,
|
||||
connectWeKnora,
|
||||
createKnowledgeBase,
|
||||
deleteKnowledgeBase,
|
||||
getKnowledgeUploadPolicy,
|
||||
invalidateKnowledgeCaches,
|
||||
listImaKnowledgeBases,
|
||||
listKnowledgeBases,
|
||||
listRagProviders,
|
||||
probeImaKnowledgeBase,
|
||||
probeLinkedFolder,
|
||||
probeWeKnora,
|
||||
readErrorDetail,
|
||||
reindexKnowledgeBase,
|
||||
retryKnowledgeBase,
|
||||
setDefaultKnowledgeBase,
|
||||
} from "./client";
|
||||
|
||||
export type {
|
||||
ImaKnowledgeBasePage,
|
||||
ImaProbe,
|
||||
KnowledgeBaseSummary,
|
||||
KnowledgeTaskResponse,
|
||||
KnowledgeUploadPolicy,
|
||||
LinkedFolderProbe,
|
||||
RagProviderSummary,
|
||||
WeKnoraProbe,
|
||||
} from "../model/types";
|
||||
38
web/features/knowledge/api/engines.ts
Normal file
38
web/features/knowledge/api/engines.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export {
|
||||
connectLightRagServer,
|
||||
getEngineModelOptions,
|
||||
getEnginePreflight,
|
||||
getGraphRagConfig,
|
||||
getImaConfig,
|
||||
getLightRagConfig,
|
||||
getLightRagServerConfig,
|
||||
getLlamaIndexConfig,
|
||||
getPageIndexConfig,
|
||||
probeLightRagServer,
|
||||
setEngineActiveModel,
|
||||
testGraphRagModelCompatibility,
|
||||
updateGraphRagConfig,
|
||||
updateImaConfig,
|
||||
updateLightRagConfig,
|
||||
updateLightRagServerConfig,
|
||||
updateLlamaIndexConfig,
|
||||
updatePageIndexConfig,
|
||||
updateRagProviderMode,
|
||||
} from "./client";
|
||||
|
||||
export type {
|
||||
EnginePreflight,
|
||||
GraphRagConfig,
|
||||
GraphRagModelCompatibility,
|
||||
ImaAccountConfig,
|
||||
LightRagConfig,
|
||||
LightRagServerConfig,
|
||||
LightRagServerProbe,
|
||||
LlamaIndexConfig,
|
||||
ModelKindOptions,
|
||||
ModelOption,
|
||||
ModelOptionsByKind,
|
||||
PageIndexConfig,
|
||||
PreflightCheck,
|
||||
RagProviderSummary,
|
||||
} from "../model/types";
|
||||
11
web/features/knowledge/api/files.ts
Normal file
11
web/features/knowledge/api/files.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export {
|
||||
createKbFolder,
|
||||
deleteKbFile,
|
||||
knowledgeBaseFilePath,
|
||||
knowledgeBaseFilePreviewTextPath,
|
||||
listKnowledgeBaseFiles,
|
||||
moveKbFile,
|
||||
uploadKnowledgeBaseFiles,
|
||||
} from "./client";
|
||||
|
||||
export type { KnowledgeBaseFile, KnowledgeUploadPolicy } from "../model/types";
|
||||
20
web/features/knowledge/api/sources.ts
Normal file
20
web/features/knowledge/api/sources.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export {
|
||||
addGitHubSource,
|
||||
addWebSource,
|
||||
listGitHubSources,
|
||||
listWebSources,
|
||||
removeGitHubSource,
|
||||
removeWebSource,
|
||||
syncGitHubSources,
|
||||
syncWebSources,
|
||||
} from "./client";
|
||||
|
||||
export type {
|
||||
AddGitHubSourcePayload,
|
||||
AddWebSourcePayload,
|
||||
GitHubSource,
|
||||
GitHubSyncResult,
|
||||
WebSource,
|
||||
WebSyncResult,
|
||||
WebSyncSourceResult,
|
||||
} from "../model/types";
|
||||
1949
web/features/knowledge/components/engines/EngineDetail.tsx
Normal file
1949
web/features/knowledge/components/engines/EngineDetail.tsx
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
export { GraphRagForm as default, GraphRagForm } from "./EngineDetail";
|
||||
1
web/features/knowledge/components/engines/ImaForm.tsx
Normal file
1
web/features/knowledge/components/engines/ImaForm.tsx
Normal file
@@ -0,0 +1 @@
|
||||
export { ImaForm as default, ImaForm } from "./EngineDetail";
|
||||
@@ -0,0 +1 @@
|
||||
export { LightRagForm as default, LightRagForm } from "./EngineDetail";
|
||||
@@ -0,0 +1 @@
|
||||
export { LlamaIndexForm as default, LlamaIndexForm } from "./EngineDetail";
|
||||
31
web/features/knowledge/model/types.ts
Normal file
31
web/features/knowledge/model/types.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export type {
|
||||
AddGitHubSourcePayload,
|
||||
AddWebSourcePayload,
|
||||
EnginePreflight,
|
||||
GitHubSource,
|
||||
GitHubSyncResult,
|
||||
GraphRagConfig,
|
||||
GraphRagModelCompatibility,
|
||||
ImaAccountConfig,
|
||||
ImaKnowledgeBasePage,
|
||||
ImaProbe,
|
||||
KnowledgeBaseFile,
|
||||
KnowledgeBaseSummary,
|
||||
KnowledgeTaskResponse,
|
||||
KnowledgeUploadPolicy,
|
||||
LightRagConfig,
|
||||
LightRagServerConfig,
|
||||
LightRagServerProbe,
|
||||
LinkedFolderProbe,
|
||||
LlamaIndexConfig,
|
||||
ModelKindOptions,
|
||||
ModelOption,
|
||||
ModelOptionsByKind,
|
||||
PageIndexConfig,
|
||||
PreflightCheck,
|
||||
RagProviderSummary,
|
||||
WebSource,
|
||||
WebSyncResult,
|
||||
WebSyncSourceResult,
|
||||
WeKnoraProbe,
|
||||
} from "../api/client";
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import {
|
||||
getImaConfig,
|
||||
listImaKnowledgeBases,
|
||||
probeImaKnowledgeBase,
|
||||
type ImaProbe,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/catalog";
|
||||
import { getImaConfig } from "@/features/knowledge/api/engines";
|
||||
import {
|
||||
canConnectIma,
|
||||
emptyImaLookupState,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import {
|
||||
connectImaKnowledgeBase as connectImaApi,
|
||||
connectLightRagServer as connectLightRagServerApi,
|
||||
connectWeKnora as connectWeKnoraApi,
|
||||
connectLinkedFolder as connectLinkedFolderApi,
|
||||
connectMarginNote4Library as connectMarginNote4Api,
|
||||
@@ -17,11 +16,12 @@ import {
|
||||
reindexKnowledgeBase as reindexKbApi,
|
||||
retryKnowledgeBase as retryKbApi,
|
||||
setDefaultKnowledgeBase as setDefaultKbApi,
|
||||
uploadKnowledgeBaseFiles as uploadKbApi,
|
||||
type KnowledgeTaskResponse,
|
||||
type KnowledgeUploadPolicy,
|
||||
type RagProviderSummary,
|
||||
} from "@/lib/knowledge-api";
|
||||
} from "@/features/knowledge/api/catalog";
|
||||
import { connectLightRagServer as connectLightRagServerApi } from "@/features/knowledge/api/engines";
|
||||
import { uploadKnowledgeBaseFiles as uploadKbApi } from "@/features/knowledge/api/files";
|
||||
import {
|
||||
DEFAULT_UPLOAD_POLICY,
|
||||
type KnowledgeBase,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
import { bookApi } from "@/lib/book-api";
|
||||
import { listKnowledgeBases } from "@/lib/knowledge-api";
|
||||
import { listKnowledgeBases } from "@/features/knowledge/api/catalog";
|
||||
import { SUBAGENT_KB_TYPE } from "@/lib/knowledge-helpers";
|
||||
import type { TopicSourceInput, TopicSourceKind } from "@/lib/learning-api";
|
||||
import { getNotebook, listNotebooks } from "@/lib/notebook-api";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { GraphRagModelCompatibility } from "@/lib/knowledge-api";
|
||||
import type { GraphRagModelCompatibility } from "@/features/knowledge/model/types";
|
||||
|
||||
export interface GraphRagCandidateGate {
|
||||
activeKey: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { apiFetch, apiUrl } from "@/lib/api";
|
||||
import { readErrorDetail } from "@/lib/knowledge-api";
|
||||
import { readErrorDetail } from "@/features/knowledge/api/catalog";
|
||||
|
||||
/**
|
||||
* Device bridge for a connected MarginNote 4 library.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { testGraphRagModelCompatibility } from "../lib/knowledge-api";
|
||||
import { testGraphRagModelCompatibility } from "../features/knowledge/api/engines";
|
||||
import { canApplyGraphRagModelCandidate } from "../lib/graphrag-model-compatibility";
|
||||
|
||||
test("GraphRAG candidate probe sends catalog IDs without activating the model", async () => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import type { RagProviderSummary } from "../lib/knowledge-api";
|
||||
import type { RagProviderSummary } from "../features/knowledge/model/types";
|
||||
import {
|
||||
canConnectIma,
|
||||
createProviders,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
connectImaKnowledgeBase,
|
||||
listImaKnowledgeBases,
|
||||
probeImaKnowledgeBase,
|
||||
} from "../lib/knowledge-api";
|
||||
} from "../features/knowledge/api/catalog";
|
||||
|
||||
function jsonResponse(status: number, body: unknown): Response {
|
||||
return new Response(JSON.stringify(body), {
|
||||
|
||||
57
web/tests/knowledge-api-boundaries.test.ts
Normal file
57
web/tests/knowledge-api-boundaries.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
const root = process.cwd();
|
||||
const sourceRoots = ["app", "components", "features", "hooks", "lib", "tests"];
|
||||
|
||||
function filesBelow(relativeRoot: string): string[] {
|
||||
const result: string[] = [];
|
||||
const visit = (directory: string) => {
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
const target = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) visit(target);
|
||||
else if (/\.(?:ts|tsx)$/.test(entry.name)) result.push(target);
|
||||
}
|
||||
};
|
||||
visit(path.join(root, relativeRoot));
|
||||
return result;
|
||||
}
|
||||
|
||||
test("knowledge callers use resource clients instead of the retired barrel", () => {
|
||||
assert.equal(fs.existsSync(path.join(root, "lib/knowledge-api.ts")), false);
|
||||
const violations = sourceRoots
|
||||
.flatMap(filesBelow)
|
||||
.filter((file) =>
|
||||
/from\s+["'][^"']*lib\/knowledge-api["']/.test(
|
||||
fs.readFileSync(file, "utf8"),
|
||||
),
|
||||
)
|
||||
.map((file) => path.relative(root, file));
|
||||
assert.deepEqual(violations, []);
|
||||
});
|
||||
|
||||
test("knowledge resources expose narrow public entry points", () => {
|
||||
const apiRoot = path.join(root, "features/knowledge/api");
|
||||
const expected = {
|
||||
"catalog.ts": ["listKnowledgeBases", "createKnowledgeBase"],
|
||||
"engines.ts": ["getEnginePreflight", "updateLlamaIndexConfig"],
|
||||
"files.ts": ["listKnowledgeBaseFiles", "knowledgeBaseFilePath"],
|
||||
"sources.ts": ["listGitHubSources", "syncWebSources"],
|
||||
};
|
||||
|
||||
for (const [filename, exports] of Object.entries(expected)) {
|
||||
const source = fs.readFileSync(path.join(apiRoot, filename), "utf8");
|
||||
for (const name of exports) assert.match(source, new RegExp(`\\b${name}\\b`));
|
||||
}
|
||||
});
|
||||
|
||||
test("engine forms have stable feature-owned module boundaries", () => {
|
||||
const formsRoot = path.join(root, "features/knowledge/components/engines");
|
||||
for (const name of ["LlamaIndexForm", "GraphRagForm", "LightRagForm", "ImaForm"]) {
|
||||
const filename = path.join(formsRoot, `${name}.tsx`);
|
||||
assert.equal(fs.existsSync(filename), true);
|
||||
assert.match(fs.readFileSync(filename, "utf8"), new RegExp(`\\b${name}\\b`));
|
||||
}
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { connectMarginNote4Library } from "../lib/knowledge-api";
|
||||
import { connectMarginNote4Library } from "../features/knowledge/api/catalog";
|
||||
import {
|
||||
getMarginNote4Status,
|
||||
listMarginNote4Devices,
|
||||
|
||||
Reference in New Issue
Block a user