RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Feat: Add a data compilation layer. (#16777)
balibabu0083ad0debc1
diff --git a/.gitignore b/.gitignoreindex 295e08f857..943af38a73 100644--- a/.gitignore+++ b/.gitignore@@ -258,3 +258,4 @@ internal/deepdoc/parser/docx/tool/# test data compare toolinternal/ingestion/task/tool/generate_dataflow_golden.pyinternal/ingestion/task/tool/README.md+internal/cpp/cmake-build-release\ No newline at end of filediff --git a/web/CLAUDE.md b/web/CLAUDE.mdindex 3f8b326055..4a755ac752 100644--- a/web/CLAUDE.md+++ b/web/CLAUDE.md@@ -30,6 +30,10 @@ When fixing CSS/layout issues (especially flex truncation, ellipsis, or element- Before editing, explain: (1) the full flex/container hierarchy from the target element up to the nearest non-flex ancestor, (2) what constraint is actually causing the bug, and (3) how the proposed fix addresses that root cause.+### Color Tokens++When writing or modifying styles, **use the project-defined color tokens from `src/tailwind.css`** (e.g., `bg-bg-base`, `text-text-primary`, `text-text-secondary`, `text-text-disabled`, `border-border-button`, `bg-bg-card`). Do not use arbitrary hex/RGB values or Tailwind's default palette colors (e.g., `emerald-500`, `blue-400`) directly in component class names. These tokens are defined for both light and dark modes and keep the UI consistent with the design system.+### Scope and BoundariesRespect explicit boundaries from the user. If the user says **"only fix the selected line"** or **"do not touch shared types/files"**, follow that instruction exactly. Do not investigate unrelated errors, modify shared schemas (e.g., `LlmSettingFieldSchema`), or refactor other files without confirmation. If a change outside the described scope seems necessary, ask for permission first.@@ -103,10 +107,14 @@ The folder `src/components/ui/` is the project's **shared UI library** — it co### React Patterns and Conventions+- **Avoid inline event handlers.** Do not define arrow functions directly on JSX event props like `onClick={() => ...}` or `onChange={(e) => ...}`. Instead, extract the handler and reference it by name (e.g., `onClick={handleClick}`). Inline handlers are recreated on every render, which can break `React.memo` optimizations and make stack traces harder to read.- **Prefer `requestAnimationFrame` or `useLayoutEffect`** over `setTimeout(..., 0)` for focus or DOM measurement operations.- **Prefer `useTranslation` from `react-i18next`** over project-wrapped utilities like `useTranslate`.- Extract complex logic into hooks or utils; keep components lean.-- Use `PascalCase` for constants and component names.+- Use **PascalCase** for constants and component names.+ - Components: `EditableTextarea`, `RAGFlowFormItem`+ - Constants: `InitialMockData`, `DefaultPlaceholder`+- Avoid camelCase or SCREAMING_SNAKE_CASE for components and top-level constants.- Avoid duplicating component structures in JSX; favor render props or reusable components.### Utility Libraries and Reusediff --git a/web/package-lock.json b/web/package-lock.jsonindex f69342535a..d993e77f10 100644--- a/web/package-lock.json+++ b/web/package-lock.json@@ -10,11 +10,23 @@"@ant-design/icons": "^5.2.6","@antv/g2": "^5.2.10","@antv/g6": "^5.1.0",+ "@antv/layout": "^2.0.0",+ "@antv/x6": "^3.1.7","@extend-ai/react-docx": "^0.6.7","@floating-ui/react": "^0.27.19","@hookform/resolvers": "^3.9.1","@js-preview/excel": "^1.7.14",- "@lexical/react": "^0.23.1",+ "@lexical/code": "^0.45.0",+ "@lexical/hashtag": "^0.45.0",+ "@lexical/history": "^0.45.0",+ "@lexical/link": "^0.45.0",+ "@lexical/list": "^0.45.0",+ "@lexical/markdown": "^0.45.0",+ "@lexical/react": "^0.45.0",+ "@lexical/rich-text": "^0.45.0",+ "@lexical/selection": "^0.45.0",+ "@lexical/table": "^0.45.0",+ "@lexical/utils": "^0.45.0","@mdx-js/rollup": "^3.1.1","@monaco-editor/react": "^4.6.0","@radix-ui/react-accordion": "^1.2.3",@@ -71,9 +83,10 @@"js-base64": "^3.7.5","jsencrypt": "^3.3.2","jsoneditor": "^10.4.2",- "lexical": "^0.23.1",+ "lexical": "^0.45.0","lodash": "^4.18.1","lucide-react": "^1.7.0",+ "mermaid": "^11.15.0","next-themes": "^0.4.6","openai-speech-stream-player": "^1.0.8","papaparse": "^5.5.3",@@ -86,6 +99,7 @@"react-dom": "^18.2.0","react-dropzone": "^14.3.5","react-error-boundary": "^4.0.13",+ "react-force-graph-2d": "^1.29.1","react-hook-form": "^7.56.4","react-i18next": "^14.0.0","react-infinite-scroll-component": "^6.1.0",@@ -244,6 +258,19 @@"integrity": "sha512-vHbT+zJEVzllwP+CM+ul7reTEfBR0vgxFe7+lREAsAA7YGsYpboiq2sQNeQeRvh09GfQgs/GyFEvZpJ9cLXpXA==","license": "MIT"},+ "node_modules/@antfu/install-pkg": {+ "version": "1.1.0",+ "resolved": "https://registry.npmmirror.com/@antfu/install-pkg/-/install-pkg-1.1.0.tgz",+ "integrity": "sha512-MGQsmw10ZyI+EJo45CdSER4zEb+p31LpDAFp2Z3gkSd1yqVZGi0Ebx++YTEMonJy4oChEMLsxZ64j8FH6sSqtQ==",+ "license": "MIT",+ "dependencies": {+ "package-manager-detector": "^1.3.0",+ "tinyexec": "^1.0.1"+ },+ "funding": {+ "url": "https://github.com/sponsors/antfu"+ }+ },"node_modules/@antv/algorithm": {"version": "0.1.26","resolved": "https://registry.npmmirror.com/@antv/algorithm/-/algorithm-0.1.26.tgz",@@ -553,6 +580,21 @@"d3-timer": "^3.0.1"}},+ "node_modules/@antv/x6": {+ "version": "3.1.7",+ "resolved": "https://registry.npmmirror.com/@antv/x6/-/x6-3.1.7.tgz",+ "integrity": "sha512-NLKXtbCK51oLbazfFD0XsD93rMmih08UBW4gAuEyLBpwAqHmHe+vP8VhOZDkl5O9jV1LSv85IJghr9CT5tZjWw==",+ "license": "MIT",+ "dependencies": {+ "dom-align": "^1.12.4",+ "lodash-es": "^4.17.15",+ "mousetrap": "^1.6.5",+ "utility-types": "^3.10.0"+ },+ "engines": {+ "node": ">=20.0.0"+ }+ },"node_modules/@babel/code-frame": {"version": "7.27.1","resolved": "https://registry.npmmirror.com/@babel/code-frame/-/code-frame-7.27.1.tgz",@@ -1278,12 +1320,24 @@"dev": true,"license": "MIT"},+ "node_modules/@braintree/sanitize-url": {+ "version": "7.1.2",+ "resolved": "https://registry.npmmirror.com/@braintree/sanitize-url/-/sanitize-url-7.1.2.tgz",+ "integrity": "sha512-jigsZK+sMF/cuiB7sERuo9V7N9jx+dhmHHnQyDSVdpZwVutaBu7WvNYqMDLSgFgfB30n452TP3vjDAvFC973mA==",+ "license": "MIT"+ },"node_modules/@chenglou/pretext": {"version": "0.0.5","resolved": "https://registry.npmmirror.com/@chenglou/pretext/-/pretext-0.0.5.tgz","integrity": "sha512-A8GZN10REdFGsyuiUgLV8jjPDDFMg5GmgxGWV0I3igxBOnzj+jgz2VMmVD7g+SFyoctfeqHFxbNatKSzVRWtRg==","license": "MIT"},+ "node_modules/@chevrotain/types": {+ "version": "11.1.2",+ "resolved": "https://registry.npmmirror.com/@chevrotain/types/-/types-11.1.2.tgz",+ "integrity": "sha512-U+HFai5+zmJCkK86QsaJtoITlboZHBqrVketcO2ROv865xfCMSFpELQoz1GkX5GzME8pTa+3kbKrZHQtI0gdbw==",+ "license": "Apache-2.0"+ },"node_modules/@cnakazawa/watch": {"version": "1.0.4","resolved": "https://registry.npmmirror.com/@cnakazawa/watch/-/watch-1.0.4.tgz",@@ -2202,6 +2256,23 @@"dev": true,"license": "BSD-3-Clause"},+ "node_modules/@iconify/types": {+ "version": "2.0.0",+ "resolved": "https://registry.npmmirror.com/@iconify/types/-/types-2.0.0.tgz",+ "integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==",+ "license": "MIT"+ },+ "node_modules/@iconify/utils": {+ "version": "3.1.3",+ "resolved": "https://registry.npmmirror.com/@iconify/utils/-/utils-3.1.3.tgz",+ "integrity": "sha512-LPKOXPn/zV+zis1oOfGWogaXVpqUybF3ZS6SCZIsz8vg0ivVp9+fVqyYB7xq0aiST/VhUQYGO1qo6uoYSiEJqw==",+ "license": "MIT",+ "dependencies": {+ "@antfu/install-pkg": "^1.1.0",+ "@iconify/types": "^2.0.0",+ "import-meta-resolve": "^4.2.0"+ }+ },"node_modules/@istanbuljs/load-nyc-config": {"version": "1.1.0","resolved": "https://registry.npmmirror.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",@@ -2727,41 +2798,69 @@"license": "MIT"},"node_modules/@lexical/clipboard": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/clipboard/-/clipboard-0.23.1.tgz",- "integrity": "sha512-MT8IXl1rhTe8VcwnkhgFtWra6sRYNsl/I7nE9aw6QxwvPReKmRDmyBmEIeXwnKSGHRe19OJhu4/A9ciKPyVdMA==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/clipboard/-/clipboard-0.45.0.tgz",+ "integrity": "sha512-9oDu2SNj/EZGjpXJTruz74Ls3VzF2Q41v1QB7JnTq5lh24byvIOdgEpOFHtr/7WVHssfXCbMtgFb5tW8rMaZ2g==","license": "MIT","dependencies": {- "@lexical/html": "0.23.1",- "@lexical/list": "0.23.1",- "@lexical/selection": "0.23.1",- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/extension": "0.45.0",+ "@lexical/html": "0.45.0",+ "@lexical/internal": "0.45.0",+ "@lexical/list": "0.45.0",+ "@lexical/selection": "0.45.0",+ "@lexical/utils": "0.45.0",+ "@types/trusted-types": "^2.0.7",+ "lexical": "0.45.0"}},"node_modules/@lexical/code": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/code/-/code-0.23.1.tgz",- "integrity": "sha512-TOxaFAwoewrX3rHp4Po+u1LJT8oteP/6Kn2z6j9DaynBW62gIqTuSAFcMPysVx/Puq5hhJHPRD/be9RWDteDZw==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/code/-/code-0.45.0.tgz",+ "integrity": "sha512-vtD5IKbJvgIxhKIl96pWKqjlqialzg/WbWNUNbeoyuf9ht0/MQ6WFdEdCNnnXqx4rj7CTzafB3c0jup7h96b6A==","license": "MIT","dependencies": {- "@lexical/utils": "0.23.1",- "lexical": "0.23.1",- "prismjs": "^1.27.0"+ "@lexical/code-core": "0.45.0",+ "@lexical/code-prism": "0.45.0",+ "@lexical/extension": "0.45.0",+ "lexical": "0.45.0"+ }+ },+ "node_modules/@lexical/code-core": {+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/code-core/-/code-core-0.45.0.tgz",+ "integrity": "sha512-zU3noYmfluSK38r0eBz3gHKzsgOksf9eHqoPIwXH6HovKCDo848HoW0i/hCRzRo9oPqydKikx0LIKUvWSaSNIw==",+ "license": "MIT",+ "dependencies": {+ "@lexical/extension": "0.45.0",+ "@lexical/html": "0.45.0",+ "@lexical/internal": "0.45.0",+ "lexical": "0.45.0"+ }+ },+ "node_modules/@lexical/code-prism": {+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/code-prism/-/code-prism-0.45.0.tgz",+ "integrity": "sha512-eevIcapWzWk4Kb2WE6mmMjTXjf+Mfn4pLXAJ92BkRO6gc5RPkYgpn7zsYTzSBWEM/GptKf7ta+XouLcnLXNOSQ==",+ "license": "MIT",+ "dependencies": {+ "@lexical/code-core": "0.45.0",+ "@lexical/extension": "0.45.0",+ "lexical": "0.45.0",+ "prismjs": "^1.30.0"}},"node_modules/@lexical/devtools-core": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/devtools-core/-/devtools-core-0.23.1.tgz",- "integrity": "sha512-QsgcrECy11ZHhWAfyNW/ougXFF1o0EuQnhFybgTdqQmw0rJ2ZgPLpPjD5lws3CE8mP8g5knBV4/cyxvv42fzzg==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/devtools-core/-/devtools-core-0.45.0.tgz",+ "integrity": "sha512-XiVedKif5nWbNj2CeNy30kokfk/iYb7Db+B1Z18bnr/uzp6IzkxpX6I4GeZu4HVbQJhGMCAdq19tFpYwXOx4sw==","license": "MIT","dependencies": {- "@lexical/html": "0.23.1",- "@lexical/link": "0.23.1",- "@lexical/mark": "0.23.1",- "@lexical/table": "0.23.1",- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/html": "0.45.0",+ "@lexical/link": "0.45.0",+ "@lexical/mark": "0.45.0",+ "@lexical/table": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"},"peerDependencies": {"react": ">=17.x",@@ -2769,230 +2868,260 @@}},"node_modules/@lexical/dragon": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/dragon/-/dragon-0.23.1.tgz",- "integrity": "sha512-ZoY9VJDrTpO69sinRhIs3RlPAWviy4mwnC7lqtM77/pVK0Kaknv7z2iDqv+414PKQCgUhyoXp7PfYXu/3yb6LQ==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/dragon/-/dragon-0.45.0.tgz",+ "integrity": "sha512-34k2/QuM8A9WVqVCtNGx1ySBWXxMVKejKH3VBWnXEb1NdrDa/N8jLpu0gOCLcrrDjMdUzs9uVgW0D4FRf1Lixg==","license": "MIT","dependencies": {- "lexical": "0.23.1"+ "@lexical/extension": "0.45.0",+ "lexical": "0.45.0"+ }+ },+ "node_modules/@lexical/extension": {+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/extension/-/extension-0.45.0.tgz",+ "integrity": "sha512-oJs1Zvrsqh32zZmeCkTQi7R2WoVIvaQE265JFZ/VczWlsWRdkkWQbGZ6iOlBZ3AmtiNgHoBeB0gZSoRQtWEQyA==",+ "license": "MIT",+ "dependencies": {+ "@lexical/internal": "0.45.0",+ "@lexical/utils": "0.45.0",+ "@preact/signals-core": "^1.14.1",+ "lexical": "0.45.0"}},"node_modules/@lexical/hashtag": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/hashtag/-/hashtag-0.23.1.tgz",- "integrity": "sha512-EkRCHV/IQwKlggy3VQDF9b4Krc9DKNZEjXe84CkEVrRpQSOwXi0qORzuaAipARyN632WKLSXOZJmNzkUNocJ6A==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/hashtag/-/hashtag-0.45.0.tgz",+ "integrity": "sha512-gFX4n+9RjOFVkNUkEcv3JeQT0LvZ8fiHWHrIkg1m3JbyloG6mKDlsSlO1qnIPUaAB4V62Tbnmfv3I0qp1UvNuw==","license": "MIT","dependencies": {- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/text": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/history": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/history/-/history-0.23.1.tgz",- "integrity": "sha512-5Vro4bIePw37MwffpvPm56WlwPdlY/u+fVkvXsxdhK9bqiFesmLZhBirokDPvJEMP35V59kzmN5mmWXSYfuRpg==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/history/-/history-0.45.0.tgz",+ "integrity": "sha512-KihtI8485Wx7kyFCtKNKk/nO2jSibRa8iL0OiKPZsYWVAQF5vFG3J00epX8EkEpeCx8Zjmj+3eytY05HPNd2nA==","license": "MIT","dependencies": {- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/extension": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/html": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/html/-/html-0.23.1.tgz",- "integrity": "sha512-kNkDUaDe/Awypaw8JZn65BzT1gwNj2bNkaGFcmIkXUrTtiqlvgYvKvJeOKLkoAb/i2xq990ZAbHOsJrJm1jMbw==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/html/-/html-0.45.0.tgz",+ "integrity": "sha512-eK215f25cnAcIzNB1iRltg8hbvkK5wyyXvKQUqhfG/9HaSSVBCPuCyXKZicjZllQNvbFINGHFhTIqSP56drFSw==","license": "MIT","dependencies": {- "@lexical/selection": "0.23.1",- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/extension": "0.45.0",+ "@lexical/internal": "0.45.0",+ "@lexical/selection": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},+ "node_modules/@lexical/internal": {+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/internal/-/internal-0.45.0.tgz",+ "integrity": "sha512-IhyzCdb1/xdpTtvK0xnqUXpaVRsD2KTZ6EMZpavm6dhKaglf1zorpdbH7r6Hjps6SRb4DCn/t7lac+GMdDFbXg==",+ "license": "MIT"+ },"node_modules/@lexical/link": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/link/-/link-0.23.1.tgz",- "integrity": "sha512-HRaOp7prtcbHjbgq8AjJ4O02jYb8pTeS8RrGcgIRhCOq3/EcsSb1dXMwuraqmh9oxbuFyEu/JE31EFksiOW6qA==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/link/-/link-0.45.0.tgz",+ "integrity": "sha512-9xpsRQ06IA4eVnx4OtFV0+Tmp2Etvh0dh9FTFd/LJYaqo2A0ZIuNUggueDZ0i2dhi8wWW8J08O7U0HxLcDWHAg==","license": "MIT","dependencies": {- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/extension": "0.45.0",+ "@lexical/html": "0.45.0",+ "@lexical/internal": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/list": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/list/-/list-0.23.1.tgz",- "integrity": "sha512-TI3WyWk3avv9uaJwaq8V+m9zxLRgnzXDYNS0rREafnW09rDpaFkpVmDuX+PZVR3NqPlwVt+slWVSBuyfguAFbA==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/list/-/list-0.45.0.tgz",+ "integrity": "sha512-Eyff9KVLu5mV4QSid2aw9uYmKDKgDYToAaagI9Sp3VgqTMmvRUQJ0w7sr4zq8/FRKSzrsf4V2FjvLAuQE7eBUQ==","license": "MIT","dependencies": {- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/extension": "0.45.0",+ "@lexical/html": "0.45.0",+ "@lexical/internal": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/mark": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/mark/-/mark-0.23.1.tgz",- "integrity": "sha512-E7cMOBVMrNGMw0LsyWKNFQZ5Io3bUIHCC3aCUdH24z1XWnuTmDFKMqNrphywPniO7pzSgVyGpkQBZIAIN76+YA==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/mark/-/mark-0.45.0.tgz",+ "integrity": "sha512-PMyGmnF6koE5TKCDlGe1k1t1ZOefReyYaKtx6OY3Tf1AyyKII6zRGR+dANrgWzYliYO7j4mpKBK00ykOnuF3zA==","license": "MIT","dependencies": {- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/markdown": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/markdown/-/markdown-0.23.1.tgz",- "integrity": "sha512-TQx8oXenaiVYffBPxD85m4CydbDAuYOonATiABAFG6CHkA6vi898M1TCTgVDS6/iISjtjQpqHo0SW7YjLt14jw==",- "license": "MIT",- "dependencies": {- "@lexical/code": "0.23.1",- "@lexical/link": "0.23.1",- "@lexical/list": "0.23.1",- "@lexical/rich-text": "0.23.1",- "@lexical/text": "0.23.1",- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"- }- },- "node_modules/@lexical/offset": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/offset/-/offset-0.23.1.tgz",- "integrity": "sha512-ylw5egME/lldacVXDoRsdGDXPuk9lGmYgcqx/aITGrSymav+RDjQoAapHbz1HQqGmm/m18+VLaWTdjtkbrIN6g==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/markdown/-/markdown-0.45.0.tgz",+ "integrity": "sha512-fl/UUwudBXGnz44kOS07ZRN0DMfOWNnVl7GSSNyz6zDo1cMD60URt7LjF51bAG2oL8i1eRDX4/GV+7vBcuoGzw==","license": "MIT","dependencies": {- "lexical": "0.23.1"+ "@lexical/code-core": "0.45.0",+ "@lexical/internal": "0.45.0",+ "@lexical/link": "0.45.0",+ "@lexical/list": "0.45.0",+ "@lexical/rich-text": "0.45.0",+ "@lexical/selection": "0.45.0",+ "@lexical/text": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/overflow": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/overflow/-/overflow-0.23.1.tgz",- "integrity": "sha512-WubTqozpxOeyTm/tKIHXinsjuRcgPESacOvu93dS+sC7q3n+xeBIu5FL7lM6bbsk3zNtNJQ9sG0svZngmWRjCw==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/overflow/-/overflow-0.45.0.tgz",+ "integrity": "sha512-iw6Gc85phIGEjAFRDLiGOrnxK/EjyRlEfQHI7BeU0m+qHDCc94cThbeuaPTC7nnxHytFbRdtJIhoQvvcUR+PKA==","license": "MIT","dependencies": {- "lexical": "0.23.1"+ "lexical": "0.45.0"}},"node_modules/@lexical/plain-text": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/plain-text/-/plain-text-0.23.1.tgz",- "integrity": "sha512-tM4DJw+HyT9XV4BKGVECDnejcC//jsFggjFmJgwIMTCxJPiGXEEZLZTXmGqf8QdFZ6cH1I5bhreZPQUWu6dRvg==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/plain-text/-/plain-text-0.45.0.tgz",+ "integrity": "sha512-453bsKVk3oY5/ktp3A2zO2nFdXniU/zfD87eIcN50aXrIwvNm082GkfmBaDeVujk7fLgC2hG980xdcEH4xcG3w==","license": "MIT","dependencies": {- "@lexical/clipboard": "0.23.1",- "@lexical/selection": "0.23.1",- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/clipboard": "0.45.0",+ "@lexical/dragon": "0.45.0",+ "@lexical/extension": "0.45.0",+ "@lexical/selection": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/react": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/react/-/react-0.23.1.tgz",- "integrity": "sha512-g5CQMOiK+Djqp75UaSFUceHZEUQVIXBzWBuVR69pCiptCgNqN3CNAoIxy0hTTaVrLq6S0SCjUOduBDtioN0bLA==",- "license": "MIT",- "dependencies": {- "@lexical/clipboard": "0.23.1",- "@lexical/code": "0.23.1",- "@lexical/devtools-core": "0.23.1",- "@lexical/dragon": "0.23.1",- "@lexical/hashtag": "0.23.1",- "@lexical/history": "0.23.1",- "@lexical/link": "0.23.1",- "@lexical/list": "0.23.1",- "@lexical/mark": "0.23.1",- "@lexical/markdown": "0.23.1",- "@lexical/overflow": "0.23.1",- "@lexical/plain-text": "0.23.1",- "@lexical/rich-text": "0.23.1",- "@lexical/selection": "0.23.1",- "@lexical/table": "0.23.1",- "@lexical/text": "0.23.1",- "@lexical/utils": "0.23.1",- "@lexical/yjs": "0.23.1",- "lexical": "0.23.1",- "react-error-boundary": "^3.1.4"+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/react/-/react-0.45.0.tgz",+ "integrity": "sha512-LAaceAtcQpVMDvldhkrQC1MSawpj7aAm1CfGg6RbyQgTDDp2fKnP1gDhjQIef3lH8W2fYeXRe66EdzaFkoGHKA==",+ "license": "MIT",+ "dependencies": {+ "@floating-ui/react": "^0.27.19",+ "@lexical/devtools-core": "0.45.0",+ "@lexical/dragon": "0.45.0",+ "@lexical/extension": "0.45.0",+ "@lexical/hashtag": "0.45.0",+ "@lexical/history": "0.45.0",+ "@lexical/internal": "0.45.0",+ "@lexical/link": "0.45.0",+ "@lexical/list": "0.45.0",+ "@lexical/mark": "0.45.0",+ "@lexical/markdown": "0.45.0",+ "@lexical/overflow": "0.45.0",+ "@lexical/plain-text": "0.45.0",+ "@lexical/rich-text": "0.45.0",+ "@lexical/table": "0.45.0",+ "@lexical/text": "0.45.0",+ "@lexical/utils": "0.45.0",+ "@lexical/yjs": "0.45.0",+ "lexical": "0.45.0",+ "react-error-boundary": "^6.1.1"},"peerDependencies": {"react": ">=17.x",- "react-dom": ">=17.x"+ "react-dom": ">=17.x",+ "yjs": ">=13.5.22"+ },+ "peerDependenciesMeta": {+ "yjs": {+ "optional": true+ }}},"node_modules/@lexical/react/node_modules/react-error-boundary": {- "version": "3.1.4",- "resolved": "https://registry.npmmirror.com/react-error-boundary/-/react-error-boundary-3.1.4.tgz",- "integrity": "sha512-uM9uPzZJTF6wRQORmSrvOIgt4lJ9MC1sNgEOj2XGsDTRE4kmpWxg7ENK9EWNKJRMAOY9z0MuF4yIfl6gp4sotA==",+ "version": "6.1.2",+ "resolved": "https://registry.npmmirror.com/react-error-boundary/-/react-error-boundary-6.1.2.tgz",+ "integrity": "sha512-3DpCr5HVdZ0caUjYE/kIHBEJN0mNP3ZCgf16c48uJ5TbWjorKVp+YG8W3XqlJ7vJAVNw6wNIImyPXmFydwmyng==","license": "MIT",- "dependencies": {- "@babel/runtime": "^7.12.5"- },- "engines": {- "node": ">=10",- "npm": ">=6"- },"peerDependencies": {- "react": ">=16.13.1"+ "react": "^18.0.0 || ^19.0.0"}},"node_modules/@lexical/rich-text": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/rich-text/-/rich-text-0.23.1.tgz",- "integrity": "sha512-Y77HGxdF5aemjw/H44BXETD5KNeaNdwMRu9P7IrlK7cC1dvvimzL2D6ezbub5i7F1Ef5T0quOXjwK056vrqaKQ==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/rich-text/-/rich-text-0.45.0.tgz",+ "integrity": "sha512-jd+jIsDirqILuUQiNUJAzZWynVZHuN1ekqYcydgDFaUXMFBQgVr3mBUieQzMw2IDAEk98txntu/mZQav4BryQQ==","license": "MIT","dependencies": {- "@lexical/clipboard": "0.23.1",- "@lexical/selection": "0.23.1",- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/clipboard": "0.45.0",+ "@lexical/dragon": "0.45.0",+ "@lexical/extension": "0.45.0",+ "@lexical/html": "0.45.0",+ "@lexical/selection": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/selection": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/selection/-/selection-0.23.1.tgz",- "integrity": "sha512-xoehAURMZJZYf046GHUXiv8FSv5zTobhwDD2dML4fmNHPp9NxugkWHlNUinTK/b+jGgjSYVsqpEKPBmue4ZHdQ==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/selection/-/selection-0.45.0.tgz",+ "integrity": "sha512-V2DYMhl84F1aZ24YpWMMqy9ikO7cVfD3G+GjMwrZnMt0JVnIghjPiYIEBb/OtqqA+mCbBwNhfpdK1RtF9HTbJA==","license": "MIT","dependencies": {- "lexical": "0.23.1"+ "@lexical/internal": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/table": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/table/-/table-0.23.1.tgz",- "integrity": "sha512-Qs+iuwSVkV4OGTt+JdL9hvyl/QO3X9waH70L5Fxu9JmQk/jLl02tIGXbE38ocJkByfpyk4PrphoXt6l7CugJZA==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/table/-/table-0.45.0.tgz",+ "integrity": "sha512-OXbwEg0DqkTdvqnu7z+/u8bgnDz2sjHHXCG3zGRhEzDgHcWoVQ18IciwMdse7dTTNfBIJMuGJcRoWPrHf9UlhQ==","license": "MIT","dependencies": {- "@lexical/clipboard": "0.23.1",- "@lexical/utils": "0.23.1",- "lexical": "0.23.1"+ "@lexical/clipboard": "0.45.0",+ "@lexical/extension": "0.45.0",+ "@lexical/html": "0.45.0",+ "@lexical/internal": "0.45.0",+ "@lexical/utils": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/text": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/text/-/text-0.23.1.tgz",- "integrity": "sha512-aOuuAhmc+l2iSK99uP0x/Zg9LSQswQdNG3IxzGa0rTx844mWUHuEbAUaOqqlgDA1/zZ0WjObyhPfZJL775y63g==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/text/-/text-0.45.0.tgz",+ "integrity": "sha512-ozI8fDsLTYAzEWXaBrGYZ0GnRbbIHi4IL99w5q06UfTQzBMYmF7WaccDP1krOOwwioPYQbiqZM7dh/41jsFELQ==","license": "MIT","dependencies": {- "lexical": "0.23.1"+ "@lexical/internal": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/utils": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/utils/-/utils-0.23.1.tgz",- "integrity": "sha512-yXEkF6fj32+mJblCoP0ZT/vA0S05FA0nRUkVrvGX6sbZ9y+cIzuIbBoHi4z1ytutcWHQrwCK4TsN9hPYBIlb2w==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/utils/-/utils-0.45.0.tgz",+ "integrity": "sha512-Fo5MMErqoPlUyTw1qVMZ9kE33ZjJF957KU683tsCrrlaVisVxpboL7BbAnxWTwCcIpAsfc6AUndJJ70M9NDMGg==","license": "MIT","dependencies": {- "@lexical/list": "0.23.1",- "@lexical/selection": "0.23.1",- "@lexical/table": "0.23.1",- "lexical": "0.23.1"+ "@lexical/internal": "0.45.0",+ "@lexical/selection": "0.45.0",+ "lexical": "0.45.0"}},"node_modules/@lexical/yjs": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/@lexical/yjs/-/yjs-0.23.1.tgz",- "integrity": "sha512-ygodSxmC65srNicMIhqBRIXI2LHhmnHcR1EO9fLO7flZWGCR1HIoeGmwhHo9FLgJoc5LHanV+dE0z1onFo1qqQ==",+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/@lexical/yjs/-/yjs-0.45.0.tgz",+ "integrity": "sha512-HYbOovvOavtF1S7C13l9g21s4MFLLd/o49qdn+/uGj23j4yjG556XBSrF0c3BREXDXSUr+RTbI6uiQ+L5Ofcmw==","license": "MIT","dependencies": {- "@lexical/offset": "0.23.1",- "@lexical/selection": "0.23.1",- "lexical": "0.23.1"+ "@lexical/internal": "0.45.0",+ "@lexical/selection": "0.45.0",+ "lexical": "0.45.0"},"peerDependencies": {"yjs": ">=13.5.22"@@ -3090,6 +3219,15 @@"node": ">= 12"}},+ "node_modules/@mermaid-js/parser": {+ "version": "1.2.0",+ "resolved": "https://registry.npmmirror.com/@mermaid-js/parser/-/parser-1.2.0.tgz",+ "integrity": "sha512-oYPyv8A4As1yH5Bx+04iQEQxXuIQDe0GKCNSRgao6z8AM9jixXIfP0vsppRLvGf+nKIOb9/LdpWA4YuJiVvESA==",+ "license": "MIT",+ "dependencies": {+ "@chevrotain/types": "~11.1.2"+ }+ },"node_modules/@mjackson/node-fetch-server": {"version": "0.2.0","resolved": "https://registry.npmmirror.com/@mjackson/node-fetch-server/-/node-fetch-server-0.2.0.tgz",@@ -3168,6 +3306,16 @@"url": "https://opencollective.com/pkgr"}},+ "node_modules/@preact/signals-core": {+ "version": "1.14.3",+ "resolved": "https://registry.npmmirror.com/@preact/signals-core/-/signals-core-1.14.3.tgz",+ "integrity": "sha512-m0K3vnbSLC5rHs2ZVfeAMvBtT1zIyq4mxx5OlNncSgMj5Iz6W5Rn3kPrDxAC+iIKmiVe0lSl6U37t5ZkEWoVAw==",+ "license": "MIT",+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/preact"+ }+ },"node_modules/@radix-ui/number": {"version": "1.1.1","resolved": "https://registry.npmmirror.com/@radix-ui/number/-/number-1.1.1.tgz",@@ -7938,6 +8086,12 @@"dev": true,"license": "MIT"},+ "node_modules/@tweenjs/tween.js": {+ "version": "25.0.0",+ "resolved": "https://registry.npmmirror.com/@tweenjs/tween.js/-/tween.js-25.0.0.tgz",+ "integrity": "sha512-XKLA6syeBUaPzx4j3qwMqzzq+V4uo72BnlbOjmuljLrRqdsd3qnzvZZoxvMHZ23ndsRS4aufU6JOZYpCbU6T1A==",+ "license": "MIT"+ },"node_modules/@types/aria-query": {"version": "5.0.4","resolved": "https://registry.npmmirror.com/@types/aria-query/-/aria-query-5.0.4.tgz",@@ -8001,18 +8155,96 @@"assertion-error": "^2.0.1"}},+ "node_modules/@types/d3": {+ "version": "7.4.3",+ "resolved": "https://registry.npmmirror.com/@types/d3/-/d3-7.4.3.tgz",+ "integrity": "sha512-lZXZ9ckh5R8uiFVt8ogUNf+pIrK4EsWrx2Np75WvF/eTpJ0FMHNhjXk8CKEx/+gpHbNQyJWehbFaTvqmHWB3ww==",+ "license": "MIT",+ "dependencies": {+ "@types/d3-array": "*",+ "@types/d3-axis": "*",+ "@types/d3-brush": "*",+ "@types/d3-chord": "*",+ "@types/d3-color": "*",+ "@types/d3-contour": "*",+ "@types/d3-delaunay": "*",+ "@types/d3-dispatch": "*",+ "@types/d3-drag": "*",+ "@types/d3-dsv": "*",+ "@types/d3-ease": "*",+ "@types/d3-fetch": "*",+ "@types/d3-force": "*",+ "@types/d3-format": "*",+ "@types/d3-geo": "*",+ "@types/d3-hierarchy": "*",+ "@types/d3-interpolate": "*",+ "@types/d3-path": "*",+ "@types/d3-polygon": "*",+ "@types/d3-quadtree": "*",+ "@types/d3-random": "*",+ "@types/d3-scale": "*",+ "@types/d3-scale-chromatic": "*",+ "@types/d3-selection": "*",+ "@types/d3-shape": "*",+ "@types/d3-time": "*",+ "@types/d3-time-format": "*",+ "@types/d3-timer": "*",+ "@types/d3-transition": "*",+ "@types/d3-zoom": "*"+ }+ },"node_modules/@types/d3-array": {"version": "3.2.2","resolved": "https://registry.npmmirror.com/@types/d3-array/-/d3-array-3.2.2.tgz","integrity": "sha512-hOLWVbm7uRza0BYXpIIW5pxfrKe0W+D5lrFiAEYR+pb6w3N2SwSMaJbXdUfSEv+dT4MfHBLtn5js0LAWaO6otw==","license": "MIT"},+ "node_modules/@types/d3-axis": {+ "version": "3.0.6",+ "resolved": "https://registry.npmmirror.com/@types/d3-axis/-/d3-axis-3.0.6.tgz",+ "integrity": "sha512-pYeijfZuBd87T0hGn0FO1vQ/cgLk6E1ALJjfkC0oJ8cbwkZl3TpgS8bVBLZN+2jjGgg38epgxb2zmoGtSfvgMw==",+ "license": "MIT",+ "dependencies": {+ "@types/d3-selection": "*"+ }+ },+ "node_modules/@types/d3-brush": {+ "version": "3.0.6",+ "resolved": "https://registry.npmmirror.com/@types/d3-brush/-/d3-brush-3.0.6.tgz",+ "integrity": "sha512-nH60IZNNxEcrh6L1ZSMNA28rj27ut/2ZmI3r96Zd+1jrZD++zD3LsMIjWlvg4AYrHn/Pqz4CF3veCxGjtbqt7A==",+ "license": "MIT",+ "dependencies": {+ "@types/d3-selection": "*"+ }+ },+ "node_modules/@types/d3-chord": {+ "version": "3.0.6",+ "resolved": "https://registry.npmmirror.com/@types/d3-chord/-/d3-chord-3.0.6.tgz",+ "integrity": "sha512-LFYWWd8nwfwEmTZG9PfQxd17HbNPksHBiJHaKuY1XeqscXacsS2tyoo6OdRsjf+NQYeB6XrNL3a25E3gH69lcg==",+ "license": "MIT"+ },"node_modules/@types/d3-color": {"version": "3.1.3","resolved": "https://registry.npmmirror.com/@types/d3-color/-/d3-color-3.1.3.tgz","integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==","license": "MIT"},+ "node_modules/@types/d3-contour": {+ "version": "3.0.6",+ "resolved": "https://registry.npmmirror.com/@types/d3-contour/-/d3-contour-3.0.6.tgz",+ "integrity": "sha512-BjzLgXGnCWjUSYGfH1cpdo41/hgdWETu4YxpezoztawmqsvCeep+8QGfiY6YbDvfgHz/DkjeIkkZVJavB4a3rg==",+ "license": "MIT",+ "dependencies": {+ "@types/d3-array": "*",+ "@types/geojson": "*"+ }+ },+ "node_modules/@types/d3-delaunay": {+ "version": "6.0.4",+ "resolved": "https://registry.npmmirror.com/@types/d3-delaunay/-/d3-delaunay-6.0.4.tgz",+ "integrity": "sha512-ZMaSKu4THYCU6sV64Lhg6qjf1orxBthaC161plr5KuPHo3CNm8DTHiLw/5Eq2b6TsNP0W0iJrUOFscY6Q450Hw==",+ "license": "MIT"+ },"node_modules/@types/d3-dispatch": {"version": "3.0.7","resolved": "https://registry.npmmirror.com/@types/d3-dispatch/-/d3-dispatch-3.0.7.tgz",@@ -8091,6 +8323,12 @@"integrity": "sha512-VMZBYyQvbGmWyWVea0EHs/BwLgxc+MKi1zLDCONksozI4YJMcTt8ZEuIR4Sb1MMTE8MMW49v0IwI5+b7RmfWlg==","license": "MIT"},+ "node_modules/@types/d3-polygon": {+ "version": "3.0.2",+ "resolved": "https://registry.npmmirror.com/@types/d3-polygon/-/d3-polygon-3.0.2.tgz",+ "integrity": "sha512-ZuWOtMaHCkN9xoeEMr1ubW2nGWsp4nIql+OPQRstu4ypeZ+zk3YKqQT0CXVe/PYqrKpZAi+J9mTs05TKwjXSRA==",+ "license": "MIT"+ },"node_modules/@types/d3-quadtree": {"version": "3.0.6","resolved": "https://registry.npmmirror.com/@types/d3-quadtree/-/d3-quadtree-3.0.6.tgz",@@ -8139,6 +8377,12 @@"integrity": "sha512-yuzZug1nkAAaBlBBikKZTgzCeA+k1uy4ZFwWANOfKw5z5LRhV0gNA7gNkKm7HoK+HRN0wX3EkxGk0fpbWhmB7g==","license": "MIT"},+ "node_modules/@types/d3-time-format": {+ "version": "4.0.3",+ "resolved": "https://registry.npmmirror.com/@types/d3-time-format/-/d3-time-format-4.0.3.tgz",+ "integrity": "sha512-5xg9rC+wWL8kdDj153qZcsJ0FWiFt0J5RB6LYUNZjwSnesfblqrI/bJ1wBdJ8OQfncgbJG5+2F+qfqnqyzYxyg==",+ "license": "MIT"+ },"node_modules/@types/d3-timer": {"version": "3.0.2","resolved": "https://registry.npmmirror.com/@types/d3-timer/-/d3-timer-3.0.2.tgz",@@ -8528,7 +8772,6 @@"version": "2.0.7","resolved": "https://registry.npmmirror.com/@types/trusted-types/-/trusted-types-2.0.7.tgz","integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==",- "devOptional": true,"license": "MIT"},"node_modules/@types/unist": {@@ -8906,6 +9149,16 @@"integrity": "sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g==","license": "ISC"},+ "node_modules/@upsetjs/venn.js": {+ "version": "2.0.0",+ "resolved": "https://registry.npmmirror.com/@upsetjs/venn.js/-/venn.js-2.0.0.tgz",+ "integrity": "sha512-WbBhLrooyePuQ1VZxrJjtLvTc4NVfpOyKx0sKqioq9bX1C1m7Jgykkn8gLrtwumBioXIqam8DLxp88Adbue6Hw==",+ "license": "MIT",+ "optionalDependencies": {+ "d3-selection": "^3.0.0",+ "d3-transition": "^3.0.1"+ }+ },"node_modules/@vitejs/plugin-react": {"version": "5.1.2","resolved": "https://registry.npmmirror.com/@vitejs/plugin-react/-/plugin-react-5.1.2.tgz",@@ -9397,6 +9650,15 @@"dev": true,"license": "BSD-3-Clause"},+ "node_modules/accessor-fn": {+ "version": "1.5.3",+ "resolved": "https://registry.npmmirror.com/accessor-fn/-/accessor-fn-1.5.3.tgz",+ "integrity": "sha512-rkAofCwe/FvYFUlMB0v0gWmhqtfAtV1IUkdPbfhTUyYniu5LrC0A0UJkTH0Jv3S8SvwkmfuAlY+mQIJATdocMA==",+ "license": "MIT",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/ace-builds": {"version": "1.43.5","resolved": "https://registry.npmmirror.com/ace-builds/-/ace-builds-1.43.5.tgz",@@ -10290,6 +10552,16 @@"node": ">=12.0.0"}},+ "node_modules/bezier-js": {+ "version": "6.1.4",+ "resolved": "https://registry.npmmirror.com/bezier-js/-/bezier-js-6.1.4.tgz",+ "integrity": "sha512-PA0FW9ZpcHbojUCMu28z9Vg/fNkwTj5YhusSAjHHDfHDGLxJ6YUKrAN2vk1fP2MMOxVw4Oko16FMlRGVBGqLKg==",+ "license": "MIT",+ "funding": {+ "type": "individual",+ "url": "https://github.com/Pomax/bezierjs/blob/master/FUNDING.md"+ }+ },"node_modules/binary-extensions": {"version": "2.3.0","resolved": "https://registry.npmmirror.com/binary-extensions/-/binary-extensions-2.3.0.tgz",@@ -10528,6 +10800,18 @@],"license": "CC-BY-4.0"},+ "node_modules/canvas-color-tracker": {+ "version": "1.3.2",+ "resolved": "https://registry.npmmirror.com/canvas-color-tracker/-/canvas-color-tracker-1.3.2.tgz",+ "integrity": "sha512-ryQkDX26yJ3CXzb3hxUVNlg1NKE4REc5crLBq661Nxzr8TNd236SaEf2ffYLXyI5tSABSeguHLqcVq4vf9L3Zg==",+ "license": "MIT",+ "dependencies": {+ "tinycolor2": "^1.6.0"+ },+ "engines": {+ "node": ">=12"+ }+ },"node_modules/capture-exit": {"version": "2.0.0","resolved": "https://registry.npmmirror.com/capture-exit/-/capture-exit-2.0.0.tgz",@@ -11245,6 +11529,15 @@"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==","license": "MIT"},+ "node_modules/cose-base": {+ "version": "1.0.3",+ "resolved": "https://registry.npmmirror.com/cose-base/-/cose-base-1.0.3.tgz",+ "integrity": "sha512-s9whTXInMSgAp/NVXVNuVxVKzGH2qck3aQlVHxDCdAEPgtMKwc4Wq6/QKhgdEdgbLSi9rBTAcPoRa6JpiG4ksg==",+ "license": "MIT",+ "dependencies": {+ "layout-base": "^1.0.0"+ }+ },"node_modules/cosmiconfig": {"version": "7.1.0","resolved": "https://registry.npmmirror.com/cosmiconfig/-/cosmiconfig-7.1.0.tgz",@@ -11540,6 +11833,95 @@"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==","license": "MIT"},+ "node_modules/cytoscape": {+ "version": "3.34.0",+ "resolved": "https://registry.npmmirror.com/cytoscape/-/cytoscape-3.34.0.tgz",+ "integrity": "sha512-62rNSrioXw93uliKFBwjukeQyeWwH2PqDrTac31r2P6464u3AUvTk0xS4LVvT251g7IgkFunrI48ZEZGjywSOg==",+ "license": "MIT",+ "engines": {+ "node": ">=0.10"+ }+ },+ "node_modules/cytoscape-cose-bilkent": {+ "version": "4.1.0",+ "resolved": "https://registry.npmmirror.com/cytoscape-cose-bilkent/-/cytoscape-cose-bilkent-4.1.0.tgz",+ "integrity": "sha512-wgQlVIUJF13Quxiv5e1gstZ08rnZj2XaLHGoFMYXz7SkNfCDOOteKBE6SYRfA9WxxI/iBc3ajfDoc6hb/MRAHQ==",+ "license": "MIT",+ "dependencies": {+ "cose-base": "^1.0.0"+ },+ "peerDependencies": {+ "cytoscape": "^3.2.0"+ }+ },+ "node_modules/cytoscape-fcose": {+ "version": "2.2.0",+ "resolved": "https://registry.npmmirror.com/cytoscape-fcose/-/cytoscape-fcose-2.2.0.tgz",+ "integrity": "sha512-ki1/VuRIHFCzxWNrsshHYPs6L7TvLu3DL+TyIGEsRcvVERmxokbf5Gdk7mFxZnTdiGtnA4cfSmjZJMviqSuZrQ==",+ "license": "MIT",+ "dependencies": {+ "cose-base": "^2.2.0"+ },+ "peerDependencies": {+ "cytoscape": "^3.2.0"+ }+ },+ "node_modules/cytoscape-fcose/node_modules/cose-base": {+ "version": "2.2.0",+ "resolved": "https://registry.npmmirror.com/cose-base/-/cose-base-2.2.0.tgz",+ "integrity": "sha512-AzlgcsCbUMymkADOJtQm3wO9S3ltPfYOFD5033keQn9NJzIbtnZj+UdBJe7DYml/8TdbtHJW3j58SOnKhWY/5g==",+ "license": "MIT",+ "dependencies": {+ "layout-base": "^2.0.0"+ }+ },+ "node_modules/cytoscape-fcose/node_modules/layout-base": {+ "version": "2.0.1",+ "resolved": "https://registry.npmmirror.com/layout-base/-/layout-base-2.0.1.tgz",+ "integrity": "sha512-dp3s92+uNI1hWIpPGH3jK2kxE2lMjdXdr+DH8ynZHpd6PUlH6x6cbuXnoMmiNumznqaNO31xu9e79F0uuZ0JFg==",+ "license": "MIT"+ },+ "node_modules/d3": {+ "version": "7.9.0",+ "resolved": "https://registry.npmmirror.com/d3/-/d3-7.9.0.tgz",+ "integrity": "sha512-e1U46jVP+w7Iut8Jt8ri1YsPOvFpg46k+K8TpCb0P+zjCkjkPnV7WzfDJzMHy1LnA+wj5pLT1wjO901gLXeEhA==",+ "license": "ISC",+ "dependencies": {+ "d3-array": "3",+ "d3-axis": "3",+ "d3-brush": "3",+ "d3-chord": "3",+ "d3-color": "3",+ "d3-contour": "4",+ "d3-delaunay": "6",+ "d3-dispatch": "3",+ "d3-drag": "3",+ "d3-dsv": "3",+ "d3-ease": "3",+ "d3-fetch": "3",+ "d3-force": "3",+ "d3-format": "3",+ "d3-geo": "3",+ "d3-hierarchy": "3",+ "d3-interpolate": "3",+ "d3-path": "3",+ "d3-polygon": "3",+ "d3-quadtree": "3",+ "d3-random": "3",+ "d3-scale": "4",+ "d3-scale-chromatic": "3",+ "d3-selection": "3",+ "d3-shape": "3",+ "d3-time": "3",+ "d3-time-format": "4",+ "d3-timer": "3",+ "d3-transition": "3",+ "d3-zoom": "3"+ },+ "engines": {+ "node": ">=12"+ }+ },"node_modules/d3-array": {"version": "3.2.4","resolved": "https://registry.npmmirror.com/d3-array/-/d3-array-3.2.4.tgz",@@ -11552,12 +11934,49 @@"node": ">=12"}},+ "node_modules/d3-axis": {+ "version": "3.0.0",+ "resolved": "https://registry.npmmirror.com/d3-axis/-/d3-axis-3.0.0.tgz",+ "integrity": "sha512-IH5tgjV4jE/GhHkRV0HiVYPDtvfjHQlQfJHs0usq7M30XcSBvOotpmH1IgkcXsO/5gEQZD43B//fc7SRT5S+xw==",+ "license": "ISC",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/d3-binarytree": {"version": "1.0.2","resolved": "https://registry.npmmirror.com/d3-binarytree/-/d3-binarytree-1.0.2.tgz","integrity": "sha512-cElUNH+sHu95L04m92pG73t2MEJXKu+GeKUN1TJkFsu93E5W8E9Sc3kHEGJKgenGvj19m6upSn2EunvMgMD2Yw==","license": "MIT"},+ "node_modules/d3-brush": {+ "version": "3.0.0",+ "resolved": "https://registry.npmmirror.com/d3-brush/-/d3-brush-3.0.0.tgz",+ "integrity": "sha512-ALnjWlVYkXsVIGlOsuWH1+3udkYFI48Ljihfnh8FZPF2QS9o+PzGLBslO0PjzVoHLZ2KCVgAM8NVkXPJB2aNnQ==",+ "license": "ISC",+ "dependencies": {+ "d3-dispatch": "1 - 3",+ "d3-drag": "2 - 3",+ "d3-interpolate": "1 - 3",+ "d3-selection": "3",+ "d3-transition": "3"+ },+ "engines": {+ "node": ">=12"+ }+ },+ "node_modules/d3-chord": {+ "version": "3.0.1",+ "resolved": "https://registry.npmmirror.com/d3-chord/-/d3-chord-3.0.1.tgz",+ "integrity": "sha512-VE5S6TNa+j8msksl7HwjxMHDM2yNK3XCkusIlpX5kwauBfXuyLAtNg9jCp/iHH61tgI4sb6R/EIMWCqEIdjT/g==",+ "license": "ISC",+ "dependencies": {+ "d3-path": "1 - 3"+ },+ "engines": {+ "node": ">=12"+ }+ },"node_modules/d3-color": {"version": "3.1.0","resolved": "https://registry.npmmirror.com/d3-color/-/d3-color-3.1.0.tgz",@@ -11567,6 +11986,30 @@"node": ">=12"}},+ "node_modules/d3-contour": {+ "version": "4.0.2",+ "resolved": "https://registry.npmmirror.com/d3-contour/-/d3-contour-4.0.2.tgz",+ "integrity": "sha512-4EzFTRIikzs47RGmdxbeUvLWtGedDUNkTcmzoeyg4sP/dvCexO47AaQL7VKy/gul85TOxw+IBgA8US2xwbToNA==",+ "license": "ISC",+ "dependencies": {+ "d3-array": "^3.2.0"+ },+ "engines": {+ "node": ">=12"+ }+ },+ "node_modules/d3-delaunay": {+ "version": "6.0.4",+ "resolved": "https://registry.npmmirror.com/d3-delaunay/-/d3-delaunay-6.0.4.tgz",+ "integrity": "sha512-mdjtIZ1XLAM8bm/hx3WwjfHt6Sggek7qH043O8KEjDXN40xi3vx/6pYSVTwLjEgiXQTbvaouWKynLBiUZ6SK6A==",+ "license": "ISC",+ "dependencies": {+ "delaunator": "5"+ },+ "engines": {+ "node": ">=12"+ }+ },"node_modules/d3-dispatch": {"version": "3.0.1","resolved": "https://registry.npmmirror.com/d3-dispatch/-/d3-dispatch-3.0.1.tgz",@@ -11773,6 +12216,46 @@"integrity": "sha512-PF8GWEL70cHHWpx2jUQXc68r1pyPHIA+St16muk/XRokETzlegj5LriNKg7o4LR0TySug4nHYPJNNRz/W+/Niw==","license": "BSD-3-Clause"},+ "node_modules/d3-sankey": {+ "version": "0.12.3",+ "resolved": "https://registry.npmmirror.com/d3-sankey/-/d3-sankey-0.12.3.tgz",+ "integrity": "sha512-nQhsBRmM19Ax5xEIPLMY9ZmJ/cDvd1BG3UVvt5h3WRxKg5zGRbvnteTyWAbzeSvlh3tW7ZEmq4VwR5mB3tutmQ==",+ "license": "BSD-3-Clause",+ "dependencies": {+ "d3-array": "1 - 2",+ "d3-shape": "^1.2.0"+ }+ },+ "node_modules/d3-sankey/node_modules/d3-array": {+ "version": "2.12.1",+ "resolved": "https://registry.npmmirror.com/d3-array/-/d3-array-2.12.1.tgz",+ "integrity": "sha512-B0ErZK/66mHtEsR1TkPEEkwdy+WDesimkM5gpZr5Dsg54BiTA5RXtYW5qTLIAcekaS9xfZrzBLF/OAkB3Qn1YQ==",+ "license": "BSD-3-Clause",+ "dependencies": {+ "internmap": "^1.0.0"+ }+ },+ "node_modules/d3-sankey/node_modules/d3-path": {+ "version": "1.0.9",+ "resolved": "https://registry.npmmirror.com/d3-path/-/d3-path-1.0.9.tgz",+ "integrity": "sha512-VLaYcn81dtHVTjEHd8B+pbe9yHWpXKZUC87PzoFmsFrJqgFwDe/qxfp5MlfsfM1V5E/iVt0MmEbWQ7FVIXh/bg==",+ "license": "BSD-3-Clause"+ },+ "node_modules/d3-sankey/node_modules/d3-shape": {+ "version": "1.3.7",+ "resolved": "https://registry.npmmirror.com/d3-shape/-/d3-shape-1.3.7.tgz",+ "integrity": "sha512-EUkvKjqPFUAZyOlhY5gzCxCeI0Aep04LwIRpsZ/mLFelJiUfnK56jo5JMDSE7yyP2kLSb6LtF+S5chMk7uqPqw==",+ "license": "BSD-3-Clause",+ "dependencies": {+ "d3-path": "1"+ }+ },+ "node_modules/d3-sankey/node_modules/internmap": {+ "version": "1.0.1",+ "resolved": "https://registry.npmmirror.com/internmap/-/internmap-1.0.1.tgz",+ "integrity": "sha512-lDB5YccMydFBtasVtxnZ3MRBHuaoE8GKsppq+EchKL2U4nK/DmEpPHNH8MZe5HkMtpSiTSOZwfN0tzYjO/lJEw==",+ "license": "ISC"+ },"node_modules/d3-scale": {"version": "4.0.2","resolved": "https://registry.npmmirror.com/d3-scale/-/d3-scale-4.0.2.tgz",@@ -11891,6 +12374,15 @@"node": ">=12"}},+ "node_modules/d3/node_modules/d3-polygon": {+ "version": "3.0.1",+ "resolved": "https://registry.npmmirror.com/d3-polygon/-/d3-polygon-3.0.1.tgz",+ "integrity": "sha512-3vbA7vXYwfe1SYhED++fPUQlWSYTTGmFmQiany/gdbiWgU/iEyQzyymwL9SkJjFFuCS4902BSzewVGsHHmHtXg==",+ "license": "ISC",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/dagre": {"version": "0.8.5","resolved": "https://registry.npmmirror.com/dagre/-/dagre-0.8.5.tgz",@@ -11901,6 +12393,16 @@"lodash": "^4.17.15"}},+ "node_modules/dagre-d3-es": {+ "version": "7.0.14",+ "resolved": "https://registry.npmmirror.com/dagre-d3-es/-/dagre-d3-es-7.0.14.tgz",+ "integrity": "sha512-P4rFMVq9ESWqmOgK+dlXvOtLwYg0i7u0HBGJER0LZDJT2VHIPAMZ/riPxqJceWMStH5+E61QxFra9kIS3AqdMg==",+ "license": "MIT",+ "dependencies": {+ "d3": "^7.9.0",+ "lodash-es": "^4.17.21"+ }+ },"node_modules/data-urls": {"version": "3.0.2","resolved": "https://registry.npmmirror.com/data-urls/-/data-urls-3.0.2.tgz",@@ -11987,9 +12489,9 @@"license": "MIT"},"node_modules/dayjs": {- "version": "1.11.19",- "resolved": "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.19.tgz",- "integrity": "sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==",+ "version": "1.11.21",+ "resolved": "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.21.tgz",+ "integrity": "sha512-98IT+HOahAisibz/yjKbzuOBwYcjJ7BCLPzARyHiyEBmRz4fatF+KPJszEHXsGYjUG234aH/cOjW1wwTbKUZlA==","license": "MIT"},"node_modules/debug": {@@ -12147,6 +12649,15 @@"node": ">=0.10.0"}},+ "node_modules/delaunator": {+ "version": "5.1.0",+ "resolved": "https://registry.npmmirror.com/delaunator/-/delaunator-5.1.0.tgz",+ "integrity": "sha512-AGrQ4QSgssa1NGmWmLPqN5NY2KajF5MqxetNEO+o0n3ZwZZeTmt7bBnvzHWrmkZFxGgr4HdyFgelzgi06otLuQ==",+ "license": "ISC",+ "dependencies": {+ "robust-predicates": "^3.0.2"+ }+ },"node_modules/delayed-stream": {"version": "1.0.0","resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz",@@ -12320,6 +12831,12 @@"dev": true,"license": "MIT"},+ "node_modules/dom-align": {+ "version": "1.12.4",+ "resolved": "https://registry.npmmirror.com/dom-align/-/dom-align-1.12.4.tgz",+ "integrity": "sha512-R8LUSEay/68zE5c8/3BDxiTEvgb4xZTF0RKmAHfiEVN3klfIpXfi2/QCoiWPccVQ0J/ZGdz9OjzL4uJEP/MRAw==",+ "license": "MIT"+ },"node_modules/dom-converter": {"version": "0.2.0","resolved": "https://registry.npmmirror.com/dom-converter/-/dom-converter-0.2.0.tgz",@@ -12862,6 +13379,16 @@"url": "https://github.com/sponsors/ljharb"}},+ "node_modules/es-toolkit": {+ "version": "1.49.0",+ "resolved": "https://registry.npmmirror.com/es-toolkit/-/es-toolkit-1.49.0.tgz",+ "integrity": "sha512-G5iZ6Pc/FNRY/soKZHC+TxGDD83rHUDXxzaWhGCX44vAv/tMs56WMusnm/KMNK+luUPsgA9U28cGr4RDlSzL2g==",+ "license": "MIT",+ "workspaces": [+ "docs",+ "benchmarks"+ ]+ },"node_modules/esast-util-from-estree": {"version": "2.0.0","resolved": "https://registry.npmmirror.com/esast-util-from-estree/-/esast-util-from-estree-2.0.0.tgz",@@ -14266,6 +14793,20 @@"dev": true,"license": "ISC"},+ "node_modules/float-tooltip": {+ "version": "1.7.5",+ "resolved": "https://registry.npmmirror.com/float-tooltip/-/float-tooltip-1.7.5.tgz",+ "integrity": "sha512-/kXzuDnnBqyyWyhDMH7+PfP8J/oXiAavGzcRxASOMRHFuReDtofizLLJsf7nnDLAfEaMW4pVWaXrAjtnglpEkg==",+ "license": "MIT",+ "dependencies": {+ "d3-selection": "2 - 3",+ "kapsule": "^1.16",+ "preact": "10"+ },+ "engines": {+ "node": ">=12"+ }+ },"node_modules/flru": {"version": "1.0.2","resolved": "https://registry.npmmirror.com/flru/-/flru-1.0.2.tgz",@@ -14347,6 +14888,32 @@"node": ">=0.10.0"}},+ "node_modules/force-graph": {+ "version": "1.51.4",+ "resolved": "https://registry.npmmirror.com/force-graph/-/force-graph-1.51.4.tgz",+ "integrity": "sha512-TdJ2KbkoiDQ7NIRx8IPGD0mAXXpLhamS7c+b7W98b0MHG7lphnda1VOQX/98UDTsttIAdH4TcP0l0MauSnLK8w==",+ "license": "MIT",+ "dependencies": {+ "@tweenjs/tween.js": "18 - 25",+ "accessor-fn": "1",+ "bezier-js": "3 - 6",+ "canvas-color-tracker": "^1.3",+ "d3-array": "1 - 3",+ "d3-drag": "2 - 3",+ "d3-force-3d": "2 - 3",+ "d3-scale": "1 - 4",+ "d3-scale-chromatic": "1 - 3",+ "d3-selection": "2 - 3",+ "d3-zoom": "2 - 3",+ "float-tooltip": "^1.7",+ "index-array-by": "1",+ "kapsule": "^1.16",+ "lodash-es": "4"+ },+ "engines": {+ "node": ">=12"+ }+ },"node_modules/fork-ts-checker-webpack-plugin": {"version": "8.0.0","resolved": "https://registry.npmmirror.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-8.0.0.tgz",@@ -14953,6 +15520,12 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "node_modules/hachure-fill": {+ "version": "0.5.2",+ "resolved": "https://registry.npmmirror.com/hachure-fill/-/hachure-fill-0.5.2.tgz",+ "integrity": "sha512-3GKBOn+m2LX9iq+JC1064cSFprJY4jL1jCXTcpnfER5HYE2l/4EfWSGzkPa/ZDBmYI0ZOEj5VHV/eKnPGkHuOg==",+ "license": "MIT"+ },"node_modules/harmony-reflect": {"version": "1.6.2","resolved": "https://registry.npmmirror.com/harmony-reflect/-/harmony-reflect-1.6.2.tgz",@@ -16011,6 +16584,16 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "node_modules/import-meta-resolve": {+ "version": "4.2.0",+ "resolved": "https://registry.npmmirror.com/import-meta-resolve/-/import-meta-resolve-4.2.0.tgz",+ "integrity": "sha512-Iqv2fzaTQN28s/FwZAoFq0ZSs/7hMAHJVX+w8PZl3cY19Pxk6jFFalxQoIfW2826i/fDLXv8IiEZRIT0lDuWcg==",+ "license": "MIT",+ "funding": {+ "type": "github",+ "url": "https://github.com/sponsors/wooorm"+ }+ },"node_modules/imurmurhash": {"version": "0.1.4","resolved": "https://registry.npmmirror.com/imurmurhash/-/imurmurhash-0.1.4.tgz",@@ -16031,6 +16614,15 @@"node": ">=8"}},+ "node_modules/index-array-by": {+ "version": "1.4.2",+ "resolved": "https://registry.npmmirror.com/index-array-by/-/index-array-by-1.4.2.tgz",+ "integrity": "sha512-SP23P27OUKzXWEC/TOyWlwLviofQkCSCKONnc62eItjp69yCZZPqDQtr3Pw5gJDnPeUMqExmKydNZaJO0FU9pw==",+ "license": "MIT",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/inflight": {"version": "1.0.6","resolved": "https://registry.npmmirror.com/inflight/-/inflight-1.0.6.tgz",@@ -17010,6 +17602,15 @@"integrity": "sha512-nO6jcEfZWQXDhOiBtG2KvKyEptz7RVbpGP4vTD2hLBdmNQSsCiicO2Ioinv6UI4y9ukqnBpy+XZ9H6uLNgJTlw==","license": "MIT"},+ "node_modules/jerrypick": {+ "version": "1.1.2",+ "resolved": "https://registry.npmmirror.com/jerrypick/-/jerrypick-1.1.2.tgz",+ "integrity": "sha512-YKnxXEekXKzhpf7CLYA0A+oDP8V0OhICNCr5lv96FvSsDEmrb0GKM776JgQvHTMjr7DTTPEVv/1Ciaw0uEWzBA==",+ "license": "MIT",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/jest": {"version": "29.7.0","resolved": "https://registry.npmmirror.com/jest/-/jest-29.7.0.tgz",@@ -18215,10 +18816,22 @@"setimmediate": "^1.0.5"}},+ "node_modules/kapsule": {+ "version": "1.16.3",+ "resolved": "https://registry.npmmirror.com/kapsule/-/kapsule-1.16.3.tgz",+ "integrity": "sha512-4+5mNNf4vZDSwPhKprKwz3330iisPrb08JyMgbsdFrimBCKNHecua/WBwvVg3n7vwx0C1ARjfhwIpbrbd9n5wg==",+ "license": "MIT",+ "dependencies": {+ "lodash-es": "4"+ },+ "engines": {+ "node": ">=12"+ }+ },"node_modules/katex": {- "version": "0.16.27",- "resolved": "https://registry.npmmirror.com/katex/-/katex-0.16.27.tgz",- "integrity": "sha512-aeQoDkuRWSqQN6nSvVCEFvfXdqo1OQiCmmW1kc9xSdjutPv7BGO7pqY9sQRJpMOGrEdfDgF2TfRXe5eUAD2Waw==",+ "version": "0.16.47",+ "resolved": "https://registry.npmmirror.com/katex/-/katex-0.16.47.tgz",+ "integrity": "sha512-Eeo8Ys1doU1z+x8AZsPpQu+p/QcZBI5PeOo7QGQdy2x2m0MU/hYagBbGOmXwr5KVbEfVuWv9LpnQWeehogurjg==","funding": ["https://opencollective.com/katex","https://github.com/sponsors/katex"@@ -18250,6 +18863,11 @@"json-buffer": "3.0.1"}},+ "node_modules/khroma": {+ "version": "2.1.0",+ "resolved": "https://registry.npmmirror.com/khroma/-/khroma-2.1.0.tgz",+ "integrity": "sha512-Ls993zuzfayK269Svk9hzpeGUKob/sIgZzyHYdjQoAdQetRKpOLj+k/QQQ/6Qi0Yz65mlROrfd+Ev+1+7dz9Kw=="+ },"node_modules/kind-of": {"version": "6.0.3","resolved": "https://registry.npmmirror.com/kind-of/-/kind-of-6.0.3.tgz",@@ -18270,6 +18888,12 @@"node": ">=6"}},+ "node_modules/layout-base": {+ "version": "1.0.2",+ "resolved": "https://registry.npmmirror.com/layout-base/-/layout-base-1.0.2.tgz",+ "integrity": "sha512-8h2oVEZNktL4BH2JCOI90iD1yXwL6iNW7KcCKT2QZgQJR2vbqDsldCTPRU9NifTCqHZci57XvQQ15YTu+sTYPg==",+ "license": "MIT"+ },"node_modules/lefthook": {"version": "1.13.6","resolved": "https://registry.npmmirror.com/lefthook/-/lefthook-1.13.6.tgz",@@ -18534,10 +19158,13 @@}},"node_modules/lexical": {- "version": "0.23.1",- "resolved": "https://registry.npmmirror.com/lexical/-/lexical-0.23.1.tgz",- "integrity": "sha512-iuS72HcAYUemsCRQCm4XZzkGhZb8a9KagW+ee2TFfkkf9f3ZpUYSrobMpjYVZRkgMOx7Zk5VCPMxm1nouJTfnQ==",- "license": "MIT"+ "version": "0.45.0",+ "resolved": "https://registry.npmmirror.com/lexical/-/lexical-0.45.0.tgz",+ "integrity": "sha512-z2M9C2ILPW7SopQE1aKbOFdZJbe3HvsrgWnJKveMDrSEvVjU9Hce4UpKVsAdkwY7TgY9RDuCV3+sfrGu0WkL+w==",+ "license": "MIT",+ "dependencies": {+ "@lexical/internal": "0.45.0"+ }},"node_modules/lib0": {"version": "0.2.117",@@ -18644,6 +19271,12 @@"integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==","license": "MIT"},+ "node_modules/lodash-es": {+ "version": "4.18.1",+ "resolved": "https://registry.npmmirror.com/lodash-es/-/lodash-es-4.18.1.tgz",+ "integrity": "sha512-J8xewKD/Gk22OZbhpOVSwcs60zhd95ESDwezOFuA3/099925PdHJ7OFHNTGtajL3AlZkykD32HykiMo+BIBI8A==",+ "license": "MIT"+ },"node_modules/lodash.debounce": {"version": "4.0.8","resolved": "https://registry.npmmirror.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz",@@ -19227,6 +19860,69 @@"node": ">= 8"}},+ "node_modules/mermaid": {+ "version": "11.16.0",+ "resolved": "https://registry.npmmirror.com/mermaid/-/mermaid-11.16.0.tgz",+ "integrity": "sha512-Zvm3kbstgdpvIJPPItlL7fppIZ3kibvc1oZIGxdvk9t6UFz6flv+Jw7FtRGKwfcI8OckmH04LqG6LlS6X4B1pA==",+ "license": "MIT",+ "dependencies": {+ "@braintree/sanitize-url": "^7.1.2",+ "@iconify/utils": "^3.0.2",+ "@mermaid-js/parser": "^1.2.0",+ "@types/d3": "^7.4.3",+ "@upsetjs/venn.js": "^2.0.0",+ "cytoscape": "^3.33.3",+ "cytoscape-cose-bilkent": "^4.1.0",+ "cytoscape-fcose": "^2.2.0",+ "d3": "^7.9.0",+ "d3-sankey": "^0.12.3",+ "dagre-d3-es": "7.0.14",+ "dayjs": "^1.11.20",+ "dompurify": "^3.3.3",+ "es-toolkit": "^1.45.1",+ "katex": "^0.16.45",+ "khroma": "^2.1.0",+ "marked": "^16.3.0",+ "roughjs": "^4.6.6",+ "stylis": "^4.3.6",+ "ts-dedent": "^2.2.0",+ "uuid": "^11.1.0 || ^12 || ^13 || ^14.0.0"+ }+ },+ "node_modules/mermaid/node_modules/dompurify": {+ "version": "3.4.11",+ "resolved": "https://registry.npmmirror.com/dompurify/-/dompurify-3.4.11.tgz",+ "integrity": "sha512-zhlUV12GsaRzMsf9q5M254YhA4+VuF0fG+QFqu6aYpoGlKtz+w8//jBcGVYBgQkR5GHjUomejY84AV+/uPbWdw==",+ "license": "(MPL-2.0 OR Apache-2.0)",+ "optionalDependencies": {+ "@types/trusted-types": "^2.0.7"+ }+ },+ "node_modules/mermaid/node_modules/marked": {+ "version": "16.4.2",+ "resolved": "https://registry.npmmirror.com/marked/-/marked-16.4.2.tgz",+ "integrity": "sha512-TI3V8YYWvkVf3KJe1dRkpnjs68JUPyEa5vjKrp1XEEJUAOaQc+Qj+L1qWbPd0SJuAdQkFU0h73sXXqwDYxsiDA==",+ "license": "MIT",+ "bin": {+ "marked": "bin/marked.js"+ },+ "engines": {+ "node": ">= 20"+ }+ },+ "node_modules/mermaid/node_modules/uuid": {+ "version": "14.0.1",+ "resolved": "https://registry.npmmirror.com/uuid/-/uuid-14.0.1.tgz",+ "integrity": "sha512-6ZxzVpzDXDa3bJWaHilVayA+BH/1zmxCJoVgvmqJnid/gPoKHxUrS/aC/T6LGQtNHT+XHG9fXPJB4d+IrU30Ew==",+ "funding": [+ "https://github.com/sponsors/broofa",+ "https://github.com/sponsors/ctavan"+ ],+ "license": "MIT",+ "bin": {+ "uuid": "dist-node/bin/uuid"+ }+ },"node_modules/micromark": {"version": "4.0.2","resolved": "https://registry.npmmirror.com/micromark/-/micromark-4.0.2.tgz",@@ -20130,6 +20826,12 @@"marked": "14.0.0"}},+ "node_modules/mousetrap": {+ "version": "1.6.5",+ "resolved": "https://registry.npmmirror.com/mousetrap/-/mousetrap-1.6.5.tgz",+ "integrity": "sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA==",+ "license": "Apache-2.0 WITH LLVM-exception"+ },"node_modules/mri": {"version": "1.2.0","resolved": "https://registry.npmmirror.com/mri/-/mri-1.2.0.tgz",@@ -20764,6 +21466,12 @@"node": ">=6"}},+ "node_modules/package-manager-detector": {+ "version": "1.6.0",+ "resolved": "https://registry.npmmirror.com/package-manager-detector/-/package-manager-detector-1.6.0.tgz",+ "integrity": "sha512-61A5ThoTiDG/C8s8UMZwSorAGwMJ0ERVGj2OjoW5pAalsNOg15+iQiPzrLJ4jhZ1HJzmC2PIHT2oEiH3R5fzNA==",+ "license": "MIT"+ },"node_modules/pako": {"version": "1.0.11","resolved": "https://registry.npmmirror.com/pako/-/pako-1.0.11.tgz",@@ -20905,6 +21613,12 @@"node": ">=0.10.0"}},+ "node_modules/path-data-parser": {+ "version": "0.1.0",+ "resolved": "https://registry.npmmirror.com/path-data-parser/-/path-data-parser-0.1.0.tgz",+ "integrity": "sha512-NOnmBpt5Y2RWbuv0LMzsayp3lVylAHLPUTut412ZA3l+C4uw4ZVkQbjShYCQ8TCpUMdPapr4YjUqLYD6v68j+w==",+ "license": "MIT"+ },"node_modules/path-exists": {"version": "5.0.0","resolved": "https://registry.npmmirror.com/path-exists/-/path-exists-5.0.0.tgz",@@ -21217,6 +21931,22 @@"node": ">=4"}},+ "node_modules/points-on-curve": {+ "version": "0.2.0",+ "resolved": "https://registry.npmmirror.com/points-on-curve/-/points-on-curve-0.2.0.tgz",+ "integrity": "sha512-0mYKnYYe9ZcqMCWhUjItv/oHjvgEsfKvnUTg8sAtnHr3GVy7rGkXCb6d5cSyqrWqL4k81b9CPg3urd+T7aop3A==",+ "license": "MIT"+ },+ "node_modules/points-on-path": {+ "version": "0.2.1",+ "resolved": "https://registry.npmmirror.com/points-on-path/-/points-on-path-0.2.1.tgz",+ "integrity": "sha512-25ClnWWuw7JbWZcgqY/gJ4FQWadKxGWk+3kR/7kD0tCaDtPPMj7oHu2ToLaVhfpnHrZzYby2w6tUA0eOIuUg8g==",+ "license": "MIT",+ "dependencies": {+ "path-data-parser": "0.1.0",+ "points-on-curve": "0.2.0"+ }+ },"node_modules/posix-character-classes": {"version": "0.1.1","resolved": "https://registry.npmmirror.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz",@@ -21513,6 +22243,16 @@"uuid": "dist/bin/uuid"}},+ "node_modules/preact": {+ "version": "10.29.2",+ "resolved": "https://registry.npmmirror.com/preact/-/preact-10.29.2.tgz",+ "integrity": "sha512-7tNmwg/7mzzAoB/8kSg6Hl37JraAZw3Z3A0JSY7VXlZwo82Xn0G7wKbNNs2qoF4ZEEsQGTwDAroNdqKs1ofJxQ==",+ "license": "MIT",+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/preact"+ }+ },"node_modules/prelude-ls": {"version": "1.2.1","resolved": "https://registry.npmmirror.com/prelude-ls/-/prelude-ls-1.2.1.tgz",@@ -22384,6 +23124,23 @@"integrity": "sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==","license": "MIT"},+ "node_modules/react-force-graph-2d": {+ "version": "1.29.1",+ "resolved": "https://registry.npmmirror.com/react-force-graph-2d/-/react-force-graph-2d-1.29.1.tgz",+ "integrity": "sha512-1Rl/1Z3xy2iTHKj6a0jRXGyiI86xUti81K+jBQZ+Oe46csaMikp47L5AjrzA9hY9fNGD63X8ffrqnvaORukCuQ==",+ "license": "MIT",+ "dependencies": {+ "force-graph": "^1.51",+ "prop-types": "15",+ "react-kapsule": "^2.5"+ },+ "engines": {+ "node": ">=12"+ },+ "peerDependencies": {+ "react": "*"+ }+ },"node_modules/react-hook-form": {"version": "7.69.0","resolved": "https://registry.npmmirror.com/react-hook-form/-/react-hook-form-7.69.0.tgz",@@ -22449,6 +23206,21 @@"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==","license": "MIT"},+ "node_modules/react-kapsule": {+ "version": "2.6.0",+ "resolved": "https://registry.npmmirror.com/react-kapsule/-/react-kapsule-2.6.0.tgz",+ "integrity": "sha512-HzLJoYb1n1kfwjXbqFFcRR0EA6oPsJ64tNdDmCSaL/bz2o9wUZRSb0cMe//grLFeF9EVoL4CD/e6ozLyzEv+PQ==",+ "license": "MIT",+ "dependencies": {+ "jerrypick": "^1.1.2"+ },+ "engines": {+ "node": ">=12"+ },+ "peerDependencies": {+ "react": ">=16.13.1"+ }+ },"node_modules/react-markdown": {"version": "9.1.0","resolved": "https://registry.npmmirror.com/react-markdown/-/react-markdown-9.1.0.tgz",@@ -24646,6 +25418,12 @@"url": "https://github.com/sponsors/isaacs"}},+ "node_modules/robust-predicates": {+ "version": "3.0.3",+ "resolved": "https://registry.npmmirror.com/robust-predicates/-/robust-predicates-3.0.3.tgz",+ "integrity": "sha512-NS3levdsRIUOmiJ8FZWCP7LG3QpJyrs/TE0Zpf1yvZu8cAJJ6QMW92H1c7kWpdIHo8RvmLxN/o2JXTKHp74lUA==",+ "license": "Unlicense"+ },"node_modules/rollup": {"version": "4.54.0","resolved": "https://registry.npmmirror.com/rollup/-/rollup-4.54.0.tgz",@@ -24687,6 +25465,18 @@"fsevents": "~2.3.2"}},+ "node_modules/roughjs": {+ "version": "4.6.6",+ "resolved": "https://registry.npmmirror.com/roughjs/-/roughjs-4.6.6.tgz",+ "integrity": "sha512-ZUz/69+SYpFN/g/lUlo2FXcIjRkSu3nDarreVdGGndHEBJ6cXPdKguS8JGxwj5HA5xIbVKSmLgr5b3AWxtRfvQ==",+ "license": "MIT",+ "dependencies": {+ "hachure-fill": "^0.5.2",+ "path-data-parser": "^0.1.0",+ "points-on-curve": "^0.2.0",+ "points-on-path": "^0.2.1"+ }+ },"node_modules/rsvp": {"version": "4.8.5","resolved": "https://registry.npmmirror.com/rsvp/-/rsvp-4.8.5.tgz",@@ -26209,6 +26999,12 @@"integrity": "sha512-RmGftIhY4tqtD1ERwKsVEDlt/M6UyxN/rcr95UmlooWmhtL0RwVUYJkpo1kSx3ppd9/JZzbknhy742zbMAawjQ==","license": "MIT"},+ "node_modules/stylis": {+ "version": "4.4.0",+ "resolved": "https://registry.npmmirror.com/stylis/-/stylis-4.4.0.tgz",+ "integrity": "sha512-5Z9ZpRzfuH6l/UAvCPAPUo3665Nk2wLaZU3x+TLHKVzIz33+sbJqbtrYoC3KD4/uVOr2Zp+L0LySezP9OHV9yA==",+ "license": "MIT"+ },"node_modules/sucrase": {"version": "3.35.1","resolved": "https://registry.npmmirror.com/sucrase/-/sucrase-3.35.1.tgz",@@ -26833,6 +27629,21 @@"integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==","license": "MIT"},+ "node_modules/tinycolor2": {+ "version": "1.6.0",+ "resolved": "https://registry.npmmirror.com/tinycolor2/-/tinycolor2-1.6.0.tgz",+ "integrity": "sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==",+ "license": "MIT"+ },+ "node_modules/tinyexec": {+ "version": "1.2.4",+ "resolved": "https://registry.npmmirror.com/tinyexec/-/tinyexec-1.2.4.tgz",+ "integrity": "sha512-SHf/r48b7vOrjve9PxJo3MN5v5yuyjHvdUcrQffT3WXMUfnGmHDVbC4k3sHJaJTgZCwpUplIaAo5ANtMyp3YHg==",+ "license": "MIT",+ "engines": {+ "node": ">=18"+ }+ },"node_modules/tinyglobby": {"version": "0.2.15","resolved": "https://registry.npmmirror.com/tinyglobby/-/tinyglobby-0.2.15.tgz",@@ -27049,7 +27860,6 @@"version": "2.2.0","resolved": "https://registry.npmmirror.com/ts-dedent/-/ts-dedent-2.2.0.tgz","integrity": "sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==",- "dev": true,"license": "MIT","engines": {"node": ">=6.10"@@ -27750,6 +28560,15 @@"dev": true,"license": "MIT"},+ "node_modules/utility-types": {+ "version": "3.11.0",+ "resolved": "https://registry.npmmirror.com/utility-types/-/utility-types-3.11.0.tgz",+ "integrity": "sha512-6Z7Ma2aVEWisaL6TvBCy7P8rm2LQoPv6dJ7ecIaIixHcwfbJ0x7mWdbcwlIM5IGQxPZSFYeqRCqlOOeKoJYMkw==",+ "license": "MIT",+ "engines": {+ "node": ">= 4"+ }+ },"node_modules/utrie": {"version": "1.0.2","resolved": "https://registry.npmmirror.com/utrie/-/utrie-1.0.2.tgz",@@ -29377,9 +30196,9 @@}},"node_modules/yjs": {- "version": "13.6.29",- "resolved": "https://registry.npmmirror.com/yjs/-/yjs-13.6.29.tgz",- "integrity": "sha512-kHqDPdltoXH+X4w1lVmMtddE3Oeqq48nM40FD5ojTd8xYhQpzIDcfE2keMSU5bAgRPJBe225WTUdyUgj1DtbiQ==",+ "version": "13.6.31",+ "resolved": "https://registry.npmmirror.com/yjs/-/yjs-13.6.31.tgz",+ "integrity": "sha512-Eq+5BRfbeGyqGVrTJL3bEcr8gKkxPuyuoHmAwpk52fDb8kOVMrfVSTRPd6yiGgX5Fskb96qCRjzjbRjrL4YEnw==","license": "MIT","peer": true,"dependencies": {diff --git a/web/package.json b/web/package.jsonindex 435a65546d..6597b0e400 100644--- a/web/package.json+++ b/web/package.json@@ -8,6 +8,8 @@"build": "vite build --mode production","build-storybook": "storybook build","dev": "vite --host",+ "format": "prettier --write \"src/**/*.{ts,tsx}\"",+ "format:check": "prettier --check \"src/**/*.{ts,tsx}\"","lint": "eslint src --ext .ts,.tsx --report-unused-disable-directives","prepare": "cd .. && git rev-parse --git-dir >/dev/null 2>&1 && lefthook install || true","preview": "vite preview",@@ -25,11 +27,23 @@"@ant-design/icons": "^5.2.6","@antv/g2": "^5.2.10","@antv/g6": "^5.1.0",+ "@antv/layout": "^2.0.0",+ "@antv/x6": "^3.1.7","@extend-ai/react-docx": "^0.6.7","@floating-ui/react": "^0.27.19","@hookform/resolvers": "^3.9.1","@js-preview/excel": "^1.7.14",- "@lexical/react": "^0.23.1",+ "@lexical/code": "^0.45.0",+ "@lexical/hashtag": "^0.45.0",+ "@lexical/history": "^0.45.0",+ "@lexical/link": "^0.45.0",+ "@lexical/list": "^0.45.0",+ "@lexical/markdown": "^0.45.0",+ "@lexical/react": "^0.45.0",+ "@lexical/rich-text": "^0.45.0",+ "@lexical/selection": "^0.45.0",+ "@lexical/table": "^0.45.0",+ "@lexical/utils": "^0.45.0","@mdx-js/rollup": "^3.1.1","@monaco-editor/react": "^4.6.0","@radix-ui/react-accordion": "^1.2.3",@@ -86,9 +100,10 @@"js-base64": "^3.7.5","jsencrypt": "^3.3.2","jsoneditor": "^10.4.2",- "lexical": "^0.23.1",+ "lexical": "^0.45.0","lodash": "^4.18.1","lucide-react": "^1.7.0",+ "mermaid": "^11.15.0","next-themes": "^0.4.6","openai-speech-stream-player": "^1.0.8","papaparse": "^5.5.3",@@ -101,6 +116,7 @@"react-dom": "^18.2.0","react-dropzone": "^14.3.5","react-error-boundary": "^4.0.13",+ "react-force-graph-2d": "^1.29.1","react-hook-form": "^7.56.4","react-i18next": "^14.0.0","react-infinite-scroll-component": "^6.1.0",diff --git a/web/src/components/artifact-force-graph/index.tsx b/web/src/components/artifact-force-graph/index.tsxnew file mode 100644index 0000000000..3c0b9d4275--- /dev/null+++ b/web/src/components/artifact-force-graph/index.tsx@@ -0,0 +1,93 @@+import { type IArtifactGraphEntity } from '@/interfaces/database/dataset';+import { cn } from '@/lib/utils';+import isEmpty from 'lodash/isEmpty';+import { memo, useCallback, useEffect, useMemo, useRef } from 'react';+import ForceGraph2D, { type ForceGraphMethods } from 'react-force-graph-2d';+import { type ArtifactForceGraphProps } from './types';+import { useContainerDimensions } from './use-container-dimensions';+import { defaultMapNodeToValue, renderNodeLabel } from './utils';++function ArtifactForceGraph<TNodeValue = IArtifactGraphEntity>({+ data,+ show = true,+ onNodeClick,+ mapNodeToValue = defaultMapNodeToValue as (+ node: IArtifactGraphEntity,+ ) => TNodeValue,+ getNodeId = (node) => node.slug,+}: ArtifactForceGraphProps<TNodeValue>) {+ const containerRef = useRef<HTMLDivElement>(null);+ const fgRef = useRef<ForceGraphMethods<IArtifactGraphEntity> | undefined>(+ undefined,+ );+ const hasFittedRef = useRef(false);+ const dimensions = useContainerDimensions(containerRef, show);++ const graphData = useMemo(() => {+ if (isEmpty(data) || !data) {+ return { nodes: [], links: [] };+ }++ const nodes = (data.entities || []).map((entity) => ({+ ...entity,+ id: getNodeId(entity),+ }));++ const links = (data.relations || []).map((relation) => ({+ source: relation.from,+ target: relation.to,+ }));++ return { nodes, links };+ }, [data, getNodeId]);++ useEffect(() => {+ hasFittedRef.current = false;+ }, [graphData]);++ const handleEngineStop = useCallback(() => {+ if (!hasFittedRef.current && fgRef.current) {+ fgRef.current.zoomToFit(400);+ hasFittedRef.current = true;+ }+ }, []);++ const handleNodeClick = useCallback(+ (node: IArtifactGraphEntity) => {+ onNodeClick?.(mapNodeToValue(node));+ },+ [onNodeClick, mapNodeToValue],+ );++ return (+ <div+ ref={containerRef}+ className={cn('flex-1 min-h-0 h-full', !show && 'hidden')}+ >+ {dimensions.width > 0 && dimensions.height > 0 && (+ <ForceGraph2D+ ref={fgRef}+ width={dimensions.width}+ height={dimensions.height}+ graphData={graphData}+ nodeAutoColorBy="type"+ cooldownTicks={100}+ nodeLabel={''}+ onEngineStop={handleEngineStop}+ onNodeClick={handleNodeClick}+ nodeCanvasObject={renderNodeLabel}+ nodeCanvasObjectMode={() => 'after'}+ />+ )}+ </div>+ );+}++const MemoizedArtifactForceGraph = memo(ArtifactForceGraph) as <+ TNodeValue = IArtifactGraphEntity,+>(+ props: ArtifactForceGraphProps<TNodeValue>,+) => React.ReactElement;++export { MemoizedArtifactForceGraph as ArtifactForceGraph };+export default MemoizedArtifactForceGraph;diff --git a/web/src/components/artifact-force-graph/types.ts b/web/src/components/artifact-force-graph/types.tsnew file mode 100644index 0000000000..783a645894--- /dev/null+++ b/web/src/components/artifact-force-graph/types.ts@@ -0,0 +1,12 @@+import {+ type IArtifactGraph,+ type IArtifactGraphEntity,+} from '@/interfaces/database/dataset';++export interface ArtifactForceGraphProps<TNodeValue = IArtifactGraphEntity> {+ data?: IArtifactGraph;+ show?: boolean;+ onNodeClick?: (node: TNodeValue) => void;+ mapNodeToValue?: (node: IArtifactGraphEntity) => TNodeValue;+ getNodeId?: (node: IArtifactGraphEntity) => string;+}diff --git a/web/src/components/artifact-force-graph/use-container-dimensions.ts b/web/src/components/artifact-force-graph/use-container-dimensions.tsnew file mode 100644index 0000000000..b263dc1b4a--- /dev/null+++ b/web/src/components/artifact-force-graph/use-container-dimensions.ts@@ -0,0 +1,25 @@+import { useEffect, useState, type RefObject } from 'react';++export function useContainerDimensions(+ ref: RefObject<HTMLElement | null>,+ enabled: boolean = true,+) {+ const [dimensions, setDimensions] = useState({ width: 0, height: 0 });++ useEffect(() => {+ if (!ref.current || !enabled) return;++ const observer = new ResizeObserver((entries) => {+ const entry = entries[0];+ if (entry) {+ const { width, height } = entry.contentRect;+ setDimensions({ width, height });+ }+ });++ observer.observe(ref.current);+ return () => observer.disconnect();+ }, [ref, enabled]);++ return dimensions;+}diff --git a/web/src/components/artifact-force-graph/utils.ts b/web/src/components/artifact-force-graph/utils.tsnew file mode 100644index 0000000000..e77f4861f8--- /dev/null+++ b/web/src/components/artifact-force-graph/utils.ts@@ -0,0 +1,26 @@+import { type IArtifactGraphEntity } from '@/interfaces/database/dataset';+import { type ComponentProps } from 'react';+import ForceGraph2D from 'react-force-graph-2d';++export const renderNodeLabel: NonNullable<+ ComponentProps<typeof ForceGraph2D>['nodeCanvasObject']+> = (node, ctx) => {+ const label = node.name;+ const fontSize = 2;+ ctx.font = `${fontSize}px Sans-Serif`;+ ctx.textAlign = 'center';+ ctx.textBaseline = 'top';++ const textSecondary = getComputedStyle(document.documentElement)+ .getPropertyValue('--text-secondary')+ .trim();+ ctx.fillStyle = `rgb(${textSecondary})`;++ if (node.x && node.y) {+ ctx.fillText(label, node.x, node.y + 5);+ }+};++export const defaultMapNodeToValue = <TNode extends IArtifactGraphEntity>(+ node: TNode,+): TNode => node;diff --git a/web/src/components/chunk-method-dialog/index.tsx b/web/src/components/chunk-method-dialog/index.tsxindex 63aaec7503..f9b117e731 100644--- a/web/src/components/chunk-method-dialog/index.tsx+++ b/web/src/components/chunk-method-dialog/index.tsx@@ -37,6 +37,7 @@ import {AutoQuestionsFormField,} from '../auto-keywords-form-field';import { ChildrenDelimiterForm } from '../children-delimiter-form';+import { CompilationTemplateFormField } from '../compilation-template-form-field';import { DataFlowSelect } from '../data-pipeline-select';import { DelimiterFormField } from '../delimiter-form-field';import { EntityTypesFormField } from '../entity-types-form-field';@@ -152,6 +153,7 @@ export function ChunkMethodDialog({).optional(),enable_metadata: z.boolean().optional(),+ compilation_template_group_id: z.array(z.string()).optional(),}),}).superRefine((data, ctx) => {@@ -300,6 +302,10 @@ export function ChunkMethodDialog({<ParseTypeItem />{parseType === ParseType.BuiltIn && <ChunkMethodItem />}+ {parseType === ParseType.BuiltIn && (+ <CompilationTemplateFormField></CompilationTemplateFormField>+ )}+{showPages && parseType === ParseType.BuiltIn && (<DynamicPageRange />)}diff --git a/web/src/components/chunk-method-dialog/use-default-parser-values.ts b/web/src/components/chunk-method-dialog/use-default-parser-values.tsindex b80d80b902..5e0a1d189e 100644--- a/web/src/components/chunk-method-dialog/use-default-parser-values.ts+++ b/web/src/components/chunk-method-dialog/use-default-parser-values.ts@@ -42,6 +42,7 @@ export function useDefaultParserValues() {metadata: [],built_in_metadata: [],enable_metadata: false,+ compilation_template_group_id: [],};return defaultParserValues as IParserConfig;diff --git a/web/src/components/compilation-template-form-field.tsx b/web/src/components/compilation-template-form-field.tsxnew file mode 100644index 0000000000..7407bffcfe--- /dev/null+++ b/web/src/components/compilation-template-form-field.tsx@@ -0,0 +1,117 @@+import { RAGFlowFormItem } from '@/components/ragflow-form';+import {+ MultiSelect,+ MultiSelectOptionType,+} from '@/components/ui/multi-select';+import { useFetchAllCompilationTemplateGroups } from '@/hooks/use-compilation-template-group-request';+import { useMemo } from 'react';+import { useTranslation } from 'react-i18next';++type CompilationTemplateFormFieldProps = {+ horizontal?: boolean;+ name?: string;+};++const ScopeTranslationKeyMap: Record<string, string> = {+ file: 'scopeFile',+ dataset: 'scopeDataset',+};++type CompilationTemplateMultiSelectProps = {+ value?: string[];+ onChange(value: string[]): void;+};++/**+ * Renders a multi-select for compilation template groups.+ *+ * Selection rule:+ * - Each group has a scope: "file" or "dataset".+ * - At most one group per scope can be selected.+ * - The two scopes can be combined (one file group + one dataset group).+ * - Once a scope is selected, remaining options of the same scope are disabled.+ * - The scope is displayed as a suffix after each option label.+ */+function CompilationTemplateMultiSelect({+ value: rawValue = [],+ onChange,+}: CompilationTemplateMultiSelectProps) {+ const { t } = useTranslation();+ const { groups } = useFetchAllCompilationTemplateGroups();++ const value = useMemo(() => {+ // Normalize legacy single-string values into an array during the migration.+ if (Array.isArray(rawValue)) return rawValue;+ if (typeof rawValue === 'string' && rawValue) return [rawValue];+ return [];+ }, [rawValue]);++ // Collect scopes that are already selected by the current value.+ const selectedScopes = useMemo(() => {+ const scopes = new Set<string>();+ value.forEach((id) => {+ const group = groups?.find((g) => g.id === id);+ if (group?.scope) {+ scopes.add(group.scope);+ }+ });+ return scopes;+ }, [value, groups]);++ const options = useMemo<MultiSelectOptionType[]>(() => {+ return (groups ?? []).map((group) => {+ const scopeTranslationKey = group.scope+ ? ScopeTranslationKeyMap[group.scope]+ : undefined;+ // Disable other options that share an already-selected scope.+ const isSameScopeSelected =+ !!group.scope &&+ selectedScopes.has(group.scope) &&+ !value.includes(group.id);++ return {+ label: group.name,+ value: group.id,+ disabled: isSameScopeSelected,+ suffix: scopeTranslationKey ? (+ <span className="text-text-secondary ml-1">+ ({t(`knowledgeConfiguration.${scopeTranslationKey}`)})+ </span>+ ) : undefined,+ };+ });+ }, [groups, selectedScopes, value, t]);++ return (+ <MultiSelect+ options={options}+ onValueChange={onChange}+ defaultValue={value}+ value={value}+ showSelectAll={false}+ />+ );+}++export function CompilationTemplateFormField({+ horizontal,+ name = 'parser_config.compilation_template_group_id',+}: CompilationTemplateFormFieldProps) {+ const { t } = useTranslation();++ return (+ <RAGFlowFormItem+ name={name}+ label={t('knowledgeConfiguration.compilationTemplate')}+ className="pb-4"+ horizontal={horizontal}+ >+ {(field) => (+ <CompilationTemplateMultiSelect+ value={field.value ?? []}+ onChange={field.onChange}+ />+ )}+ </RAGFlowFormItem>+ );+}diff --git a/web/src/components/document-preview/document-header.tsx b/web/src/components/document-preview/document-header.tsxindex aadac8c7e2..22f71ebfb9 100644--- a/web/src/components/document-preview/document-header.tsx+++ b/web/src/components/document-preview/document-header.tsx@@ -1,5 +1,6 @@import { formatDate } from '@/utils/date';import { formatBytes } from '@/utils/file-util';+import { PropsWithChildren } from 'react';import { useTranslation } from 'react-i18next';type Props = {@@ -7,6 +8,7 @@ type Props = {name: string;create_date: string;className?: string;+ wrapperClassName?: string;};export default function DocumentHeader({@@ -14,27 +16,32 @@ export default function DocumentHeader({name,create_date,className,-}: Props) {+ children,+ wrapperClassName,+}: PropsWithChildren<Props>) {const sizeName = formatBytes(size);const dateStr = formatDate(create_date);const { t } = useTranslation();return (- <header className={className}>- <h2 className="text-2xl font-semibold truncate">{name}</h2>- <dl- className="- text-text-secondary text-sm flex- [&_dt]:after:content-[':'] [&_dt]:after:me-[.5ch]- [&_dd]:me-[2ch]"- >- <dt>{t('chunk.size')}</dt>- <dd>{sizeName}</dd>+ <header className={wrapperClassName}>+ <section className={className}>+ <h2 className="text-2xl font-semibold truncate">{name}</h2>+ <dl+ className="+ text-text-secondary text-sm flex truncate+ [&_dt]:after:content-[':'] [&_dt]:after:me-[.5ch]+ [&_dd]:me-[2ch]"+ >+ <dt>{t('chunk.size')}</dt>+ <dd>{sizeName}</dd>- <dt>{t('chunk.uploadedTime')}</dt>- <dd>{dateStr}</dd>- </dl>+ <dt>{t('chunk.uploadedTime')}</dt>+ <dd>{dateStr}</dd>+ </dl>+ </section>+ {children}</header>);}diff --git a/web/src/components/expandable-search-input.tsx b/web/src/components/expandable-search-input.tsxnew file mode 100644index 0000000000..3b2d3990eb--- /dev/null+++ b/web/src/components/expandable-search-input.tsx@@ -0,0 +1,87 @@+import { Button } from '@/components/ui/button';+import { SearchInput } from '@/components/ui/input';+import { cn } from '@/lib/utils';+import { Search, X } from 'lucide-react';+import { useCallback, useState } from 'react';+import { useTranslation } from 'react-i18next';++interface ExpandableSearchInputProps {+ value: string;+ onChange: (value: string) => void;+ placeholder?: string;+ className?: string;+ inputClassName?: string;+ width?: number | string;+}++export function ExpandableSearchInput({+ value,+ onChange,+ placeholder,+ className,+ inputClassName,+ width = 192,+}: ExpandableSearchInputProps) {+ const { t } = useTranslation();+ const [isOpen, setIsOpen] = useState(false);++ const handleToggle = useCallback(() => {+ setIsOpen((prev) => {+ const next = !prev;+ if (!next) {+ onChange('');+ }+ return next;+ });+ }, [onChange]);++ const handleChange = useCallback(+ (e: React.ChangeEvent<HTMLInputElement>) => {+ onChange(e.target.value);+ },+ [onChange],+ );++ return (+ <div className={cn('relative flex items-center gap-2', className)}>+ <div+ className={cn(+ 'transition-all duration-300 ease-in-out',+ isOpen ? 'opacity-100' : 'w-0 overflow-hidden opacity-0',+ )}+ style={{ width: isOpen ? width : 0 }}+ >+ <SearchInput+ value={value}+ onChange={handleChange}+ className={cn('w-full', inputClassName)}+ autoFocus={isOpen}+ placeholder={placeholder}+ suffix={+ isOpen ? (+ <button+ type="button"+ onClick={handleToggle}+ className="p-1 text-text-secondary hover:text-text-primary"+ aria-label={t('common.close', 'Close')}+ >+ <X className="h-4 w-4" />+ </button>+ ) : null+ }+ />+ </div>+ {!isOpen && (+ <Button+ variant="ghost"+ size="icon"+ type="button"+ onClick={handleToggle}+ aria-label={t('chunk.search', 'Search')}+ >+ <Search className="h-5 w-5" />+ </Button>+ )}+ </div>+ );+}diff --git a/web/src/components/json-edit/index.tsx b/web/src/components/json-edit/index.tsxindex 99a4a3bf80..f1185872e6 100644--- a/web/src/components/json-edit/index.tsx+++ b/web/src/components/json-edit/index.tsx@@ -22,6 +22,7 @@ const JsonEditor: React.FC<JsonEditorProps> = ({height = '400px',className = '',options = {},+ defaultExpanded = false,}) => {const containerRef = useRef<HTMLDivElement>(null);const editorRef = useRef<any>(null);@@ -66,6 +67,10 @@ const JsonEditor: React.FC<JsonEditorProps> = ({if (value) {editorRef.current.set(value);++ if (defaultExpanded) {+ editorRef.current.expandAll?.();+ }}setIsLoading(false);@@ -138,6 +143,10 @@ const JsonEditor: React.FC<JsonEditorProps> = ({editorRef.current = new JSONEditor(containerRef.current, newOptions);editorRef.current.set(currentData);++ if (defaultExpanded) {+ editorRef.current.expandAll?.();+ }} catch (error) {console.error('Failed to reload jsoneditor with new language:',@@ -148,7 +157,7 @@ const JsonEditor: React.FC<JsonEditorProps> = ({initEditorWithNewLanguage();}- }, [i18n.language, value, onChange, options]);+ }, [i18n.language, value, onChange, options, defaultExpanded]);useEffect(() => {if (editorRef.current && value !== undefined) {@@ -157,14 +166,22 @@ const JsonEditor: React.FC<JsonEditorProps> = ({const currentJson = editorRef.current.get();if (JSON.stringify(currentJson) !== JSON.stringify(value)) {editorRef.current.set(value);++ if (defaultExpanded) {+ editorRef.current.expandAll?.();+ }}} catch (err) {console.error(err);// Skip update if there is a syntax error in the current editoreditorRef.current.set(value);++ if (defaultExpanded) {+ editorRef.current.expandAll?.();+ }}}- }, [value]);+ }, [value, defaultExpanded]);return (<divdiff --git a/web/src/components/json-edit/interface.ts b/web/src/components/json-edit/interface.tsindex 897a110311..100c6f03fa 100644--- a/web/src/components/json-edit/interface.ts+++ b/web/src/components/json-edit/interface.ts@@ -336,4 +336,7 @@ export interface JsonEditorProps {// Configuration options for the JSONEditoroptions?: JsonEditorOptions;++ // Whether to expand all nodes by default in tree/view/form modes+ defaultExpanded?: boolean;}diff --git a/web/src/components/llm-select/llm-label.tsx b/web/src/components/llm-select/llm-label.tsxindex 8c02a7ee06..0dffcd75a4 100644--- a/web/src/components/llm-select/llm-label.tsx+++ b/web/src/components/llm-select/llm-label.tsx@@ -24,7 +24,7 @@ export const LLMLabel = ({ value }: IProps) => {/><span className="font-medium truncate">{modelName}</span>{instanceName && (- <span className="text-slate-400 truncate flex-shrink-0">+ <span className="text-text-secondary truncate flex-shrink-0">{instanceName}</span>)}diff --git a/web/src/components/markdown-editor.tsx b/web/src/components/markdown-editor.tsxnew file mode 100644index 0000000000..643e49fcbe--- /dev/null+++ b/web/src/components/markdown-editor.tsx@@ -0,0 +1,97 @@+import { useCallback, useEffect, useRef, useState } from 'react';++import LexicalEditor from '@/lib/editor/lexical-editor';+import RawMarkdownEditor from '@/lib/editor/raw-markdown-editor';++interface MarkdownEditorProps {+ content: string;+ onChange?: (content: string) => void;+ readOnly?: boolean;+}++export default function MarkdownEditor({+ content,+ onChange,+ readOnly = false,+}: MarkdownEditorProps) {+ const [showSource, setShowSource] = useState(false);+ const [rawContent, setRawContent] = useState(content);+ const contentRef = useRef(content);++ useEffect(() => {+ contentRef.current = content;+ if (showSource) setRawContent(content);+ }, [showSource, content]);++ const handleWysiwygChange = useCallback(+ (md: string) => {+ if (readOnly) return;+ contentRef.current = md;+ onChange?.(md);+ },+ [onChange, readOnly],+ );++ const handleRawChange = useCallback(+ (value: string) => {+ if (readOnly) return;+ setRawContent(value);+ contentRef.current = value;+ onChange?.(value);+ },+ [onChange, readOnly],+ );++ const toggleSource = useCallback(() => {+ if (!showSource) setRawContent(contentRef.current);+ setShowSource((prev) => !prev);+ }, [showSource]);++ return (+ <div className="flex flex-1 flex-col min-h-0">+ <div className="nim-editor-container">+ <div+ className="flex flex-1 flex-col min-h-0"+ style={{ display: showSource ? 'none' : 'flex' }}+ >+ <LexicalEditor+ content={content}+ onChange={handleWysiwygChange}+ readOnly={readOnly}+ placeholder={readOnly ? '' : 'Start writing...'}+ onToggleSource={toggleSource}+ showSource={showSource}+ />+ </div>+ <div+ className="flex flex-1 flex-col min-h-0"+ style={{ display: showSource ? 'flex' : 'none' }}+ >+ {readOnly ? (+ <div className="flex-1 overflow-auto whitespace-pre-wrap break-words px-5 py-4 text-[13px] leading-relaxed font-mono bg-bg-card text-text-primary">+ <div className="flex items-center gap-1.5 px-3 py-1 border-b border-border bg-bg-base shrink-0 -mx-5 -mt-4 mb-3">+ <button+ type="button"+ onClick={toggleSource}+ className="px-2.5 py-1 text-xs font-medium border border-accent-primary rounded bg-accent-primary-10 text-accent-primary hover:bg-accent-primary-20 transition-colors"+ >+ WYSIWYG+ </button>+ </div>+ <pre className="m-0 font-inherit text-inherit leading-inherit whitespace-pre-wrap">+ {rawContent}+ </pre>+ </div>+ ) : (+ <RawMarkdownEditor+ content={rawContent}+ onChange={handleRawChange}+ readOnly={readOnly}+ onToggleSource={toggleSource}+ />+ )}+ </div>+ </div>+ </div>+ );+}diff --git a/web/src/components/model-tree-select.tsx b/web/src/components/model-tree-select.tsxindex b8f6c1c5aa..b7f4aa5b1f 100644--- a/web/src/components/model-tree-select.tsx+++ b/web/src/components/model-tree-select.tsx@@ -197,12 +197,14 @@ export interface ModelTreeSelectFormFieldProps extends ModelTreeSelectProps {name?: string;label?: string;tooltip?: string;+ required?: boolean;}export function ModelTreeSelectFormField({name = 'llm_id',label,tooltip,+ required,...rest}: ModelTreeSelectFormFieldProps) {const form = useFormContext();@@ -214,7 +216,11 @@ export function ModelTreeSelectFormField({name={name}render={({ field }) => (<FormItem>- {label && <FormLabel tooltip={tooltip}>{label}</FormLabel>}+ {label && (+ <FormLabel required={required} tooltip={tooltip}>+ {label}+ </FormLabel>+ )}<FormControl><ModelTreeSelect{...rest}diff --git a/web/src/components/originui/select-with-search.tsx b/web/src/components/originui/select-with-search.tsxindex 79b8ceb44a..02b9a5ab0f 100644--- a/web/src/components/originui/select-with-search.tsx+++ b/web/src/components/originui/select-with-search.tsx@@ -36,6 +36,7 @@ export type SelectWithSearchFlagOptionType = {value?: string;disabled?: boolean;options?: RAGFlowSelectOptionType[];+ keywords?: string[];};export type SelectWithSearchFlagProps = {@@ -289,7 +290,8 @@ export const SelectWithSearch = forwardRef<value={group.value}disabled={group.disabled}keywords={- typeof group.label === 'string' ? [group.label] : []+ group.keywords ??+ (typeof group.label === 'string' ? [group.label] : [])}onSelect={handleSelect}data-testid={diff --git a/web/src/components/parse-configuration/graph-rag-form-fields.tsx b/web/src/components/parse-configuration/graph-rag-form-fields.tsxindex ec5b6a6c22..c19409b245 100644--- a/web/src/components/parse-configuration/graph-rag-form-fields.tsx+++ b/web/src/components/parse-configuration/graph-rag-form-fields.tsx@@ -4,11 +4,11 @@ import { useTranslate } from '@/hooks/common-hooks';import { cn } from '@/lib/utils';import { useKnowledgeBaseContext } from '@/pages/dataset/contexts/knowledge-base-context';import { LLMModelItem } from '@/pages/dataset/dataset-setting/configuration/common-item';+import { GenerateType } from '@/pages/dataset/dataset/generate-button/constants';import {GenerateLogButton,- GenerateType,IGenerateLogButtonProps,-} from '@/pages/dataset/dataset/generate-button/generate';+} from '@/pages/dataset/dataset/generate-button/generate-log-button';import { upperFirst } from 'lodash';import { useCallback, useMemo } from 'react';import { useFormContext, useWatch } from 'react-hook-form';@@ -111,12 +111,12 @@ export function UseGraphRagFormField({}// The three types "table", "resume" and "one" do not display this configuration.-const GraphRagItems = ({+const GraphRagItems = function GraphRagItems({marginBottom = false,className = 'p-10',data,onDelete,-}: GraphRagItemsProps) => {+}: GraphRagItemsProps) {const { t } = useTranslate('knowledgeConfiguration');const form = useFormContext();diff --git a/web/src/components/parse-configuration/raptor-form-fields.tsx b/web/src/components/parse-configuration/raptor-form-fields.tsxindex e66ef54534..c0eb41d225 100644--- a/web/src/components/parse-configuration/raptor-form-fields.tsx+++ b/web/src/components/parse-configuration/raptor-form-fields.tsx@@ -1,11 +1,11 @@import { FormLayout } from '@/constants/form';import { DocumentParserType } from '@/constants/knowledge';import { useTranslate } from '@/hooks/common-hooks';+import { GenerateType } from '@/pages/dataset/dataset/generate-button/constants';import {GenerateLogButton,- GenerateType,IGenerateLogButtonProps,-} from '@/pages/dataset/dataset/generate-button/generate';+} from '@/pages/dataset/dataset/generate-button/generate-log-button';import random from 'lodash/random';import { Shuffle } from 'lucide-react';import { useCallback, useEffect, useMemo } from 'react';diff --git a/web/src/components/ui/tree-view.tsx b/web/src/components/ui/tree-view.tsxindex 6327370ef6..04568725b7 100644--- a/web/src/components/ui/tree-view.tsx+++ b/web/src/components/ui/tree-view.tsx@@ -1,3 +1,5 @@+// https://github.com/MrLightful/shadcn-tree-view+'use client';import { cn } from '@/lib/utils';diff --git a/web/src/constants/agent.tsx b/web/src/constants/agent.tsxindex baf98484d1..e5e5d16e5a 100644--- a/web/src/constants/agent.tsx+++ b/web/src/constants/agent.tsx@@ -66,16 +66,6 @@ export enum AgentQuery {Category = 'category',}-export enum DataflowOperator {- Begin = 'File',- Note = 'Note',- Parser = 'Parser',- Tokenizer = 'Tokenizer',- TokenChunker = 'TokenChunker',- TitleChunker = 'TitleChunker',- Extractor = 'Extractor',-}-export enum Operator {Begin = 'Begin',Retrieval = 'Retrieval',@@ -124,6 +114,7 @@ export enum Operator {TokenChunker = 'TokenChunker',TitleChunker = 'TitleChunker',Extractor = 'Extractor',+ Compilation = 'Compiler',Loop = 'Loop',LoopStart = 'LoopItem',ExitLoop = 'ExitLoop',diff --git a/web/src/constants/compilation.ts b/web/src/constants/compilation.tsnew file mode 100644index 0000000000..362092c1ce--- /dev/null+++ b/web/src/constants/compilation.ts@@ -0,0 +1,14 @@+export const enum CompilationTemplateKind {+ Artifacts = 'artifacts',+ KnowledgeGraph = 'knowledge_graph',+ Timeline = 'timeline',+ PageIndex = 'page_index',+ Tree = 'tree',+ Empty = 'empty',+ MindMap = 'mind_map',+}++export const enum CompilationTemplateScope {+ File = 'file',+ Dataset = 'dataset',+}diff --git a/web/src/hooks/logic-hooks.ts b/web/src/hooks/logic-hooks.tsindex 1174cbe97d..a8b926e771 100644--- a/web/src/hooks/logic-hooks.ts+++ b/web/src/hooks/logic-hooks.ts@@ -126,8 +126,11 @@ export const useHandleSearchChange = () => {return { handleInputChange, searchString, pagination, setPagination };};-export const useGetPagination = () => {- const [pagination, setPagination] = useState({ page: 1, pageSize: 10 });+export const useGetPagination = (options?: { pageSize?: number }) => {+ const [pagination, setPagination] = useState({+ page: 1,+ pageSize: options?.pageSize ?? 10,+ });const { t } = useTranslate('common');const onPageChange: Pagination['onChange'] = useCallback(@@ -152,6 +155,7 @@ export const useGetPagination = () => {return {pagination: currentPagination,+ setPagination,};};diff --git a/web/src/hooks/logic-hooks/navigate-hooks.ts b/web/src/hooks/logic-hooks/navigate-hooks.tsindex b8bca526f9..e9f0a79c70 100644--- a/web/src/hooks/logic-hooks/navigate-hooks.ts+++ b/web/src/hooks/logic-hooks/navigate-hooks.ts@@ -57,6 +57,13 @@ export const useNavigatePage = () => {[navigate],);+ const navigateToCompilation = useCallback(+ (id: string) => () => {+ navigate(`${Routes.DatasetBase}${Routes.Compilation}/${id}`);+ },+ [navigate],+ );+const navigateToHome = useCallback(() => {navigate(Routes.Root);}, [navigate]);@@ -201,6 +208,21 @@ export const useNavigatePage = () => {navigate(`${Routes.UserSetting}${Routes.Model}`);}, [navigate]);+ const navigateToCompilationTemplates = useCallback(() => {+ navigate(`${Routes.UserSetting}${Routes.CompilationTemplates}`);+ }, [navigate]);++ const navigateToCompilationTemplate = useCallback(+ (id?: string) => () => {+ if (id && id !== 'create') {+ navigate(`${Routes.CompilationTemplatesCreateNext}/${id}`);+ } else {+ navigate(Routes.CompilationTemplatesCreateNext);+ }+ },+ [navigate],+ );+return {navigateToDatasetList,navigateToDataset,@@ -224,9 +246,12 @@ export const useNavigatePage = () => {navigateToOldProfile,navigateToDataflowResult,navigateToDataFile,+ navigateToCompilation,navigateToDataSourceDetail,navigateToMemory,navigateToMemoryList,navigateToModelSetting,+ navigateToCompilationTemplates,+ navigateToCompilationTemplate,};};diff --git a/web/src/hooks/use-chunk-request.ts b/web/src/hooks/use-chunk-request.tsindex ac1b11c630..b8698dbd8d 100644--- a/web/src/hooks/use-chunk-request.ts+++ b/web/src/hooks/use-chunk-request.ts@@ -122,12 +122,14 @@ export const useFetchChunk = (export const useFetchNextChunkList = (enabled = true,+ options?: { chunkIds?: string[] },): ResponseGetType<{data: IChunk[];total: number;documentInfo: IKnowledgeFile;}> &IChunkListResult => {+ const chunkIds = options?.chunkIds;const { pagination, setPagination } = useGetPaginationWithRouter();const { documentId, knowledgeId } = useGetKnowledgeSearchParams();const { searchString, handleInputChange } = useHandleSearchChange();@@ -147,6 +149,7 @@ export const useFetchNextChunkList = (pagination.pageSize,debouncedSearchString,available,+ chunkIds,],placeholderData: (previousData: any) =>previousData ?? { data: [], total: 0, documentInfo: {} }, // https://github.com/TanStack/query/issues/8183@@ -156,10 +159,13 @@ export const useFetchNextChunkList = (const { data } = await kbService.chunkList({kb_id: knowledgeId,doc_id: documentId,- page: pagination.current,- size: pagination.pageSize,+ page: chunkIds?.length ? 1 : pagination.current,+ size: chunkIds?.length+ ? Math.max(chunkIds.length, 100)+ : pagination.pageSize,available_int: available,keywords: searchString,+ chunk_ids: chunkIds,});if (data.code === 0) {const res = data.data;diff --git a/web/src/hooks/use-compilation-template-group-request.ts b/web/src/hooks/use-compilation-template-group-request.tsnew file mode 100644index 0000000000..b07068e4b9--- /dev/null+++ b/web/src/hooks/use-compilation-template-group-request.ts@@ -0,0 +1,255 @@+import message from '@/components/ui/message';+import { ICompilationTemplateGroup } from '@/interfaces/database/compilation-template';+import {+ ICreateCompilationTemplateGroupRequestBody,+ IUpdateCompilationTemplateGroupRequestBody,+} from '@/interfaces/request/compilation-template';+import i18n from '@/locales/config';+import {+ compilationTemplateGroupService,+ createCompilationTemplateGroup,+ deleteCompilationTemplateGroup,+ getCompilationTemplateGroup,+ updateCompilationTemplateGroup,+} from '@/services/compilation-template-group-service';+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';+import { useDebounce } from 'ahooks';+import { useCallback, useMemo } from 'react';++import {+ useGetPaginationWithRouter,+ useHandleSearchChange,+} from './logic-hooks';++export const enum CompilationTemplateGroupApiAction {+ FetchCompilationTemplateGroups = 'fetchCompilationTemplateGroups',+ FetchCompilationTemplateGroup = 'fetchCompilationTemplateGroup',+ CreateCompilationTemplateGroup = 'createCompilationTemplateGroup',+ UpdateCompilationTemplateGroup = 'updateCompilationTemplateGroup',+ DeleteCompilationTemplateGroup = 'deleteCompilationTemplateGroup',+}++export const CompilationTemplateGroupKeys = {+ list: (keywords?: string, page?: number, pageSize?: number) =>+ [+ CompilationTemplateGroupApiAction.FetchCompilationTemplateGroups,+ { keywords, page, pageSize },+ ] as const,+ detail: (id?: string) =>+ [+ CompilationTemplateGroupApiAction.FetchCompilationTemplateGroup,+ id,+ ] as const,+ all: () =>+ [CompilationTemplateGroupApiAction.FetchCompilationTemplateGroups] as const,+};++export const useFetchCompilationTemplateGroupsByPage = () => {+ const { searchString, handleInputChange } = useHandleSearchChange();+ const { pagination, setPagination } = useGetPaginationWithRouter();+ const debouncedSearchString = useDebounce(searchString, { wait: 500 });++ const { data, isFetching: loading } = useQuery<{+ groups: ICompilationTemplateGroup[];+ total: number;+ }>({+ queryKey: CompilationTemplateGroupKeys.list(+ debouncedSearchString,+ pagination.current,+ pagination.pageSize,+ ),+ initialData: {+ groups: [],+ total: 0,+ },+ gcTime: 0,+ queryFn: async () => {+ const { data } = await compilationTemplateGroupService.listGroups(+ {+ params: {+ keywords: debouncedSearchString,+ page: pagination.current,+ page_size: pagination.pageSize,+ },+ },+ true,+ );++ return {+ groups: (data?.data?.groups ?? []) as ICompilationTemplateGroup[],+ total: data?.data?.total ?? 0,+ };+ },+ });++ const currentPagination = useMemo(+ () => ({ ...pagination, total: data?.total ?? 0 }),+ [pagination, data?.total],+ );++ return {+ groups: data?.groups ?? [],+ total: data?.total ?? 0,+ searchString,+ handleInputChange,+ pagination: currentPagination,+ setPagination,+ loading,+ };+};++export const useFetchCompilationTemplateGroup = (id?: string) => {+ const { data, isFetching: loading } = useQuery<+ ICompilationTemplateGroup | undefined+ >({+ queryKey: CompilationTemplateGroupKeys.detail(id),+ enabled: !!id && id !== 'create',+ gcTime: 0,+ queryFn: async () => {+ if (!id || id === 'create') return undefined;+ const { data } = await getCompilationTemplateGroup(id);+ return data?.data as ICompilationTemplateGroup | undefined;+ },+ });++ return { data, loading };+};++export const useCreateCompilationTemplateGroup = () => {+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation({+ mutationKey: [+ CompilationTemplateGroupApiAction.CreateCompilationTemplateGroup,+ ],+ mutationFn: async (params: ICreateCompilationTemplateGroupRequestBody) => {+ const { data } = await createCompilationTemplateGroup(params);+ return data;+ },+ onSuccess: () => {+ queryClient.invalidateQueries({+ queryKey: [+ CompilationTemplateGroupApiAction.FetchCompilationTemplateGroups,+ ],+ });+ },+ });++ const createGroup = useCallback(+ async (params: ICreateCompilationTemplateGroupRequestBody) => {+ const result = await mutateAsync(params);+ if (result.code === 0) {+ message.success(i18n.t('message.created'));+ }+ return result;+ },+ [mutateAsync],+ );++ return { data, loading, createGroup };+};++export const useUpdateCompilationTemplateGroup = () => {+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation({+ mutationKey: [+ CompilationTemplateGroupApiAction.UpdateCompilationTemplateGroup,+ ],+ mutationFn: async ({+ id,+ params,+ }: {+ id: string;+ params: IUpdateCompilationTemplateGroupRequestBody;+ }) => {+ const { data } = await updateCompilationTemplateGroup(id, params);+ return data;+ },+ onSuccess: (_, variables) => {+ queryClient.invalidateQueries({+ queryKey: [+ CompilationTemplateGroupApiAction.FetchCompilationTemplateGroups,+ ],+ });+ queryClient.invalidateQueries({+ queryKey: CompilationTemplateGroupKeys.detail(variables.id),+ });+ },+ });++ const updateGroup = useCallback(+ async (id: string, params: IUpdateCompilationTemplateGroupRequestBody) => {+ const result = await mutateAsync({ id, params });+ if (result.code === 0) {+ message.success(i18n.t('message.modified'));+ }+ return result;+ },+ [mutateAsync],+ );++ return { data, loading, updateGroup };+};++export const useDeleteCompilationTemplateGroup = () => {+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation({+ mutationKey: [+ CompilationTemplateGroupApiAction.DeleteCompilationTemplateGroup,+ ],+ mutationFn: async (id: string) => {+ const { data } = await deleteCompilationTemplateGroup(id);+ if (data.code === 0) {+ message.success(i18n.t('message.deleted'));+ queryClient.invalidateQueries({+ queryKey: [+ CompilationTemplateGroupApiAction.FetchCompilationTemplateGroups,+ ],+ });+ }+ return data?.data ?? true;+ },+ });++ const deleteGroup = useCallback(+ async (id: string) => {+ await mutateAsync(id);+ },+ [mutateAsync],+ );++ return { data, loading, deleteGroup };+};++export const useFetchAllCompilationTemplateGroups = () => {+ const { data, isFetching: loading } = useQuery<ICompilationTemplateGroup[]>({+ queryKey: CompilationTemplateGroupKeys.all(),+ initialData: [],+ gcTime: 0,+ queryFn: async () => {+ const { data } = await compilationTemplateGroupService.listGroups(+ {+ params: { keywords: '', page: 1, page_size: 100 },+ },+ true,+ );+ return (data?.data?.groups ?? []) as ICompilationTemplateGroup[];+ },+ });++ return { groups: data ?? [], loading };+};diff --git a/web/src/hooks/use-compilation-template-request.ts b/web/src/hooks/use-compilation-template-request.tsnew file mode 100644index 0000000000..438e5c5bc9--- /dev/null+++ b/web/src/hooks/use-compilation-template-request.ts@@ -0,0 +1,304 @@+import message from '@/components/ui/message';+import {+ ICompilationTemplate,+ ICompilationTemplateBuiltin,+ ICompilationTemplateListResult,+ ICompilationTemplateSection,+ IWikiPreset,+} from '@/interfaces/database/compilation-template';+import {+ ICreateCompilationTemplateRequestBody,+ IUpdateCompilationTemplateRequestBody,+} from '@/interfaces/request/compilation-template';+import i18n from '@/locales/config';+import compilationTemplateService, {+ createCompilationTemplate,+ deleteCompilationTemplate,+ getCompilationTemplate,+ listBuiltinCompilationTemplates,+ listWikiPresets,+ updateCompilationTemplate,+} from '@/services/compilation-template-service';+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';+import { useDebounce } from 'ahooks';+import { useCallback, useMemo } from 'react';++import {+ useGetPaginationWithRouter,+ useHandleSearchChange,+} from './logic-hooks';++export const enum CompilationTemplateApiAction {+ FetchCompilationTemplates = 'fetchCompilationTemplates',+ FetchCompilationTemplate = 'fetchCompilationTemplate',+ FetchBuiltinCompilationTemplates = 'fetchBuiltinCompilationTemplates',+ CreateCompilationTemplate = 'createCompilationTemplate',+ UpdateCompilationTemplate = 'updateCompilationTemplate',+ DeleteCompilationTemplate = 'deleteCompilationTemplate',+ FetchWikiPresets = 'fetchWikiPresets',+}++export const CompilationTemplateKeys = {+ list: (keywords?: string, page?: number, pageSize?: number) =>+ [+ CompilationTemplateApiAction.FetchCompilationTemplates,+ { keywords, page, pageSize },+ ] as const,+ detail: (id?: string) =>+ [CompilationTemplateApiAction.FetchCompilationTemplate, id] as const,+ builtins: () =>+ [CompilationTemplateApiAction.FetchBuiltinCompilationTemplates] as const,+ all: () => [CompilationTemplateApiAction.FetchCompilationTemplates] as const,+ wikiPresets: () => [CompilationTemplateApiAction.FetchWikiPresets] as const,+};++export const useFetchCompilationTemplatesByPage = () => {+ const { searchString, handleInputChange } = useHandleSearchChange();+ const { pagination, setPagination } = useGetPaginationWithRouter();+ const debouncedSearchString = useDebounce(searchString, { wait: 500 });++ const { data, isFetching: loading } =+ useQuery<ICompilationTemplateListResult>({+ queryKey: CompilationTemplateKeys.list(+ debouncedSearchString,+ pagination.current,+ pagination.pageSize,+ ),+ initialData: {+ templates: [],+ total: 0,+ },+ gcTime: 0,+ queryFn: async () => {+ const { data } = await compilationTemplateService.listTemplates(+ {+ params: {+ keywords: debouncedSearchString,+ page: pagination.current,+ page_size: pagination.pageSize,+ },+ },+ true,+ );++ return {+ templates: (data?.data?.templates ?? []) as ICompilationTemplate[],+ total: data?.data?.total ?? 0,+ };+ },+ });++ const currentPagination = useMemo(+ () => ({ ...pagination, total: data?.total ?? 0 }),+ [pagination, data?.total],+ );++ return {+ templates: data?.templates ?? [],+ total: data?.total ?? 0,+ searchString,+ handleInputChange,+ pagination: currentPagination,+ setPagination,+ loading,+ };+};++export const useFetchCompilationTemplate = (id?: string) => {+ const { data, isFetching: loading } = useQuery<+ ICompilationTemplate | undefined+ >({+ queryKey: CompilationTemplateKeys.detail(id),+ enabled: !!id && id !== 'create',+ gcTime: 0,+ queryFn: async () => {+ if (!id || id === 'create') return undefined;+ const { data } = await getCompilationTemplate(id);+ return data?.data as ICompilationTemplate | undefined;+ },+ });++ return { data, loading };+};++export const useFetchBuiltinCompilationTemplates = () => {+ const { data, isFetching: loading } = useQuery<ICompilationTemplateBuiltin[]>(+ {+ queryKey: CompilationTemplateKeys.builtins(),+ initialData: [],+ gcTime: 0,+ queryFn: async () => {+ const { data } = await listBuiltinCompilationTemplates();+ return (data?.data ?? []) as ICompilationTemplateBuiltin[];+ },+ },+ );++ const kindOptions = useMemo(() => {+ const kindSet = new Set<string>();+ (data ?? []).forEach((template) => {+ if (template?.kind) kindSet.add(template.kind);+ });+ return Array.from(kindSet)+ .sort()+ .map((value) => ({ label: value, value }));+ }, [data]);++ const typeOptions = useMemo(() => {+ const typeSet = new Set<string>();+ (data ?? []).forEach((template) => {+ Object.entries(template?.config ?? {}).forEach(([key, section]) => {+ if (['kind', 'llm_id', 'global_rules'].includes(key)) return;+ (section as ICompilationTemplateSection)?.fields?.forEach((field) => {+ if (field?.type) typeSet.add(field.type);+ });+ });+ });+ return Array.from(typeSet)+ .sort()+ .map((value) => ({ label: value, value }));+ }, [data]);++ return { data, typeOptions, kindOptions, loading };+};++export const useCreateCompilationTemplate = () => {+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation({+ mutationKey: [CompilationTemplateApiAction.CreateCompilationTemplate],+ mutationFn: async (params: ICreateCompilationTemplateRequestBody) => {+ const { data } = await createCompilationTemplate(params);+ return data;+ },+ onSuccess: () => {+ queryClient.invalidateQueries({+ queryKey: [CompilationTemplateApiAction.FetchCompilationTemplates],+ });+ },+ });++ const createTemplate = useCallback(+ async (params: ICreateCompilationTemplateRequestBody) => {+ const result = await mutateAsync(params);+ if (result.code === 0) {+ message.success(i18n.t('message.created'));+ }+ return result;+ },+ [mutateAsync],+ );++ return { data, loading, createTemplate };+};++export const useUpdateCompilationTemplate = () => {+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation({+ mutationKey: [CompilationTemplateApiAction.UpdateCompilationTemplate],+ mutationFn: async ({+ id,+ params,+ }: {+ id: string;+ params: IUpdateCompilationTemplateRequestBody;+ }) => {+ const { data } = await updateCompilationTemplate(id, params);+ return data;+ },+ onSuccess: (_, variables) => {+ queryClient.invalidateQueries({+ queryKey: [CompilationTemplateApiAction.FetchCompilationTemplates],+ });+ queryClient.invalidateQueries({+ queryKey: CompilationTemplateKeys.detail(variables.id),+ });+ },+ });++ const updateTemplate = useCallback(+ async (id: string, params: IUpdateCompilationTemplateRequestBody) => {+ const result = await mutateAsync({ id, params });+ if (result.code === 0) {+ message.success(i18n.t('message.modified'));+ }+ return result;+ },+ [mutateAsync],+ );++ return { data, loading, updateTemplate };+};++export const useDeleteCompilationTemplate = () => {+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation({+ mutationKey: [CompilationTemplateApiAction.DeleteCompilationTemplate],+ mutationFn: async (id: string) => {+ const { data } = await deleteCompilationTemplate(id);+ if (data.code === 0) {+ message.success(i18n.t('message.deleted'));+ queryClient.invalidateQueries({+ queryKey: [CompilationTemplateApiAction.FetchCompilationTemplates],+ });+ }+ return data?.data ?? true;+ },+ });++ const deleteTemplate = useCallback(+ async (id: string) => {+ await mutateAsync(id);+ },+ [mutateAsync],+ );++ return { data, loading, deleteTemplate };+};++export const useFetchAllCompilationTemplates = () => {+ const { data, isFetching: loading } = useQuery<ICompilationTemplate[]>({+ queryKey: CompilationTemplateKeys.all(),+ initialData: [],+ gcTime: 0,+ queryFn: async () => {+ const { data } = await compilationTemplateService.listTemplates(+ {+ params: { keywords: '', page: 1, page_size: 100 },+ },+ true,+ );+ return (data?.data?.templates ?? []) as ICompilationTemplate[];+ },+ });++ return { templates: data ?? [], loading };+};++export const useFetchWikiPresets = () => {+ const { data, isFetching: loading } = useQuery<IWikiPreset[]>({+ queryKey: CompilationTemplateKeys.wikiPresets(),+ initialData: [],+ gcTime: 0,+ queryFn: async () => {+ const { data } = await listWikiPresets();+ return (data?.data ?? []) as IWikiPreset[];+ },+ });++ return { data: data ?? [], loading };+};diff --git a/web/src/hooks/use-dataset-skill-request.ts b/web/src/hooks/use-dataset-skill-request.tsnew file mode 100644index 0000000000..b6ac07cb7c--- /dev/null+++ b/web/src/hooks/use-dataset-skill-request.ts@@ -0,0 +1,53 @@+import {+ DatasetSkillPage,+ DatasetSkillTree,+} from '@/interfaces/database/dataset-skill';+import datasetSkillService from '@/services/dataset-skill-service';+import { useQuery } from '@tanstack/react-query';++import { useKnowledgeBaseId } from './use-knowledge-request';++export const DatasetSkillKeys = {+ all: (kbId: string) => ['dataset_skill', kbId] as const,+ tree: (kbId: string) => ['dataset_skill', kbId, 'tree'] as const,+ page: (kbId: string, skillKwd: string) =>+ ['dataset_skill', kbId, 'page', skillKwd] as const,+};++export function useFetchDatasetSkillTree() {+ const kbId = useKnowledgeBaseId();++ const { data, isFetching: loading } = useQuery<DatasetSkillTree | null>({+ queryKey: DatasetSkillKeys.tree(kbId),+ initialData: null,+ enabled: !!kbId,+ gcTime: 0,+ queryFn: async () => {+ const { data } = await datasetSkillService.getTree({ datasetId: kbId });+ return data?.data ?? null;+ },+ });++ return { data, loading };+}++export function useFetchDatasetSkillPage(skillKwd: string | null | undefined) {+ const kbId = useKnowledgeBaseId();+ const enabled = !!kbId && !!skillKwd;++ const { data, isFetching: loading } = useQuery<DatasetSkillPage | null>({+ queryKey: DatasetSkillKeys.page(kbId, skillKwd ?? ''),+ initialData: null,+ enabled,+ gcTime: 0,+ queryFn: async () => {+ const { data } = await datasetSkillService.getPage({+ datasetId: kbId,+ skillKwd: skillKwd!,+ });+ return data?.data ?? null;+ },+ });++ return { data, loading };+}diff --git a/web/src/hooks/use-document-request.ts b/web/src/hooks/use-document-request.tsindex 81daad4aa3..70ed0943b4 100644--- a/web/src/hooks/use-document-request.ts+++ b/web/src/hooks/use-document-request.ts@@ -9,12 +9,14 @@ import {IDocumentInfo,IDocumentInfoFilter,} from '@/interfaces/database/document';+import { IStructureGraphResponse } from '@/interfaces/database/document-structure';import {IChangeParserConfigRequestBody,IDocumentMetaRequestBody,} from '@/interfaces/request/document';import i18n from '@/locales/config';import { EMPTY_METADATA_FIELD } from '@/pages/dataset/dataset/use-select-filters';+import documentStructureService from '@/services/document-structure-service';import kbService, {changeDocumentParser,changeDocumentsStatus,@@ -59,6 +61,25 @@ export const enum DocumentApiAction {ParseDocument = 'parseDocument',}+export const enum DocumentStructureApiAction {+ FetchDocumentStructureGraph = 'fetchDocumentStructureGraph',+ DeleteDocumentStructureGraph = 'deleteDocumentStructureGraph',+}++const DocumentKeys = {+ byIds: (ids: string[]) =>+ [DocumentApiAction.FetchDocumentList, 'byIds', ids] as const,+};++export const DocumentStructureKeys = {+ graph: (datasetId: string, documentId: string) =>+ [+ DocumentStructureApiAction.FetchDocumentStructureGraph,+ datasetId,+ documentId,+ ] as const,+};+export const useUploadDocument = () => {const queryClient = useQueryClient();const { id } = useParams();@@ -214,6 +235,37 @@ export const useFetchDocumentList = (loop = true) => {};};+export const useFetchDocumentsByIds = (ids: string[]) => {+ const { id: datasetId } = useParams();++ const { data, isFetching: loading } = useQuery<{+ docs: IDocumentInfo[];+ total: number;+ }>({+ queryKey: DocumentKeys.byIds(ids),+ enabled: ids.length > 0 && !!datasetId,+ initialData: { docs: [], total: 0 },+ queryFn: async () => {+ const ret = await listDocument(+ {+ id: datasetId,+ page: 1,+ page_size: ids.length,+ },+ {+ ids,+ },+ );+ if (ret.data.code === 0) {+ return ret.data.data;+ }+ return { docs: [], total: 0 };+ },+ });++ return { documents: data.docs, loading };+};+// get document filterexport const useGetDocumentFilter = (): {filter: IDocumentInfoFilter;@@ -566,3 +618,56 @@ export const useFetchDocumentThumbnailsByIds = () => {return { data, setDocumentIds };};++export function useFetchDocumentStructureGraph() {+ const { knowledgeId: datasetId, documentId } = useGetKnowledgeSearchParams();+ const enabled = !!datasetId && !!documentId;++ const { data, isFetching: loading } =+ useQuery<IStructureGraphResponse | null>({+ queryKey: DocumentStructureKeys.graph(datasetId, documentId),+ enabled,+ initialData: null,+ gcTime: 0,+ queryFn: async () => {+ const { data } =+ await documentStructureService.getDocumentStructureGraph(+ datasetId,+ documentId,+ );+ return data?.data ?? null;+ },+ });++ return { data, loading };+}++export function useDeleteDocumentStructureGraph() {+ const { knowledgeId: datasetId, documentId } = useGetKnowledgeSearchParams();+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation({+ mutationKey: [DocumentStructureApiAction.DeleteDocumentStructureGraph],+ mutationFn: async (templateId: string) => {+ const { data } =+ await documentStructureService.deleteDocumentStructureGraph(+ datasetId,+ documentId,+ templateId,+ );+ if (data.code === 0) {+ message.success(i18n.t('message.deleted'));+ queryClient.invalidateQueries({+ queryKey: DocumentStructureKeys.graph(datasetId, documentId),+ });+ }+ return data;+ },+ });++ return { deleteDocumentStructureGraph: mutateAsync, loading, data };+}diff --git a/web/src/hooks/use-knowledge-request.ts b/web/src/hooks/use-knowledge-request.tsindex c218d391d0..09e03bef91 100644--- a/web/src/hooks/use-knowledge-request.ts+++ b/web/src/hooks/use-knowledge-request.ts@@ -1,28 +1,48 @@import { useHandleFilterSubmit } from '@/components/list-filter-bar/use-handle-filter-submit';import message from '@/components/ui/message';import { ParseType } from '@/constants/knowledge';-import { ResponsePostType } from '@/interfaces/database/base';+import { ResponsePostType, ResponseType } from '@/interfaces/database/base';import {+ IArtifact,+ IArtifactGraph,+ IArtifactPage,+ IArtifactTopic,IDataset,IDatasetListResult,IKnowledgeGraph,INextTestingResult,IRenameTag,ITestingResult,+ IWikiCommit,+ IWikiCommitDetail,+ IWikiCommitListResponse,} from '@/interfaces/database/dataset';-import { ITestRetrievalRequestBody } from '@/interfaces/request/knowledge';+import {+ IFetchArtifactGraphRequestParams,+ ITestRetrievalRequestBody,+ IUpdateArtifactPageRequestParams,+} from '@/interfaces/request/knowledge';import i18n from '@/locales/config';import kbService, {+ clearWiki,deleteKnowledgeGraph,+ getArtifactGraph,+ getArtifactPage,getKbDetail,getKnowledgeGraph,+ getWikiCommit,+ listArtifactTopics,+ listArtifacts,listDataset,listTag,+ listWikiCommits,removeTag,renameTag,+ updateArtifactPage,updateKb,} from '@/services/knowledge-service';import {+ useInfiniteQuery,useIsMutating,useMutation,useMutationState,@@ -47,10 +67,18 @@ export const enum KnowledgeApiAction {SaveKnowledge = 'saveKnowledge',FetchKnowledgeDetail = 'fetchKnowledgeDetail',FetchKnowledgeGraph = 'fetchKnowledgeGraph',+ FetchArtifactList = 'fetchArtifactList',+ FetchArtifactTopicList = 'fetchArtifactTopicList',+ FetchArtifactPage = 'fetchArtifactPage',+ FetchArtifactGraph = 'fetchArtifactGraph',+ UpdateArtifactPage = 'updateArtifactPage',+ FetchWikiCommits = 'fetchWikiCommits',+ FetchWikiCommit = 'fetchWikiCommit',FetchMetadata = 'fetchMetadata',FetchMetadataKeys = 'fetchMetadataKeys',FetchKnowledgeList = 'fetchKnowledgeList',RemoveKnowledgeGraph = 'removeKnowledgeGraph',+ ClearWiki = 'clearWiki',}export const useKnowledgeBaseId = (): string => {@@ -324,6 +352,301 @@ export const useFetchKnowledgeBaseConfiguration = (props?: {return { data, loading };};+export const ArtifactKeys = {+ list: (+ datasetId: string,+ keywords: string,+ topic?: string,+ pageType?: string,+ ) =>+ [+ KnowledgeApiAction.FetchArtifactList,+ datasetId,+ keywords,+ topic,+ pageType,+ ] as const,+ listByDataset: (datasetId: string) =>+ [KnowledgeApiAction.FetchArtifactList, datasetId] as const,+ detail: (datasetId: string, pageType: string, slug: string) =>+ [KnowledgeApiAction.FetchArtifactPage, datasetId, pageType, slug] as const,+};++export const ArtifactTopicKeys = {+ list: (datasetId: string, keywords: string) =>+ [KnowledgeApiAction.FetchArtifactTopicList, datasetId, keywords] as const,+ listByDataset: (datasetId: string) =>+ [KnowledgeApiAction.FetchArtifactTopicList, datasetId] as const,+};++const wikiCommitKeys = {+ list: (datasetId: string, pageType: string, slug: string) =>+ [KnowledgeApiAction.FetchWikiCommits, datasetId, pageType, slug] as const,+ detail: (datasetId: string, commitId: string) =>+ [KnowledgeApiAction.FetchWikiCommit, datasetId, commitId] as const,+};++export const useFetchWikiCommits = (+ artifact: IArtifact | null,+ enabled = true,+) => {+ const knowledgeBaseId = useKnowledgeBaseId();+ const pageType = artifact?.page_type ?? '';+ const slug = artifact?.slug ?? '';++ const { data, isFetching: loading } =+ useQuery<IWikiCommitListResponse | null>({+ queryKey: wikiCommitKeys.list(knowledgeBaseId, pageType, slug),+ enabled:+ !!knowledgeBaseId && !!artifact && !!pageType && !!slug && enabled,+ gcTime: 0,+ queryFn: async () => {+ const { data } = await listWikiCommits(knowledgeBaseId, pageType, slug);+ // The merged file-commit endpoint returns {total, page, page_size, commits},+ // while the existing components expect {total, items}. Normalize here.+ const raw = (data?.data ?? {}) as {+ total?: number;+ items?: IWikiCommit[];+ commits?: IWikiCommit[];+ };+ return {+ total: raw.total ?? 0,+ items: raw.items ?? raw.commits ?? [],+ };+ },+ });++ return {+ commits: data?.items ?? [],+ total: data?.total ?? 0,+ loading,+ };+};++export function useFetchWikiCommit(commitId: string | null) {+ const knowledgeBaseId = useKnowledgeBaseId();++ const { data, isFetching: loading } = useQuery<IWikiCommitDetail | null>({+ queryKey: wikiCommitKeys.detail(knowledgeBaseId, commitId ?? ''),+ enabled: !!knowledgeBaseId && !!commitId,+ gcTime: 0,+ queryFn: async () => {+ const { data } = await getWikiCommit(knowledgeBaseId, commitId!);+ return data?.data ?? null;+ },+ });++ return { data, loading };+}++type UseFetchArtifactListOptions = {+ keywords?: string;+ topic?: string;+ pageType?: string;+ enabled?: boolean;+};++export const useFetchArtifactList = (+ options: UseFetchArtifactListOptions = {},+) => {+ const { keywords = '', topic, pageType, enabled = true } = options;+ const knowledgeBaseId = useKnowledgeBaseId();++ const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =+ useInfiniteQuery<{+ artifacts: IArtifact[];+ total: number;+ }>({+ queryKey: ArtifactKeys.list(knowledgeBaseId, keywords, topic, pageType),+ enabled: !!knowledgeBaseId && enabled && !!topic,+ gcTime: 0,+ initialPageParam: 1,+ queryFn: async ({ pageParam }) => {+ const page = pageParam as number;+ const { data } = await listArtifacts(knowledgeBaseId, {+ page,+ page_size: 30,+ keywords,+ topic,+ page_type: pageType,+ });++ const responseData = data?.data;++ return {+ artifacts: responseData?.items ?? [],+ total: responseData?.total ?? 0,+ };+ },+ getNextPageParam: (lastPage, allPages) => {+ const loadedCount = allPages.reduce(+ (sum, page) => sum + page.artifacts.length,+ 0,+ );+ return loadedCount < lastPage.total ? allPages.length + 1 : undefined;+ },+ });++ const artifacts = useMemo(+ () => data?.pages.flatMap((page) => page.artifacts) ?? [],+ [data],+ );++ const loading = isFetching || isFetchingNextPage;++ const handleScroll = useCallback(+ (e: React.UIEvent<HTMLDivElement>) => {+ const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;+ const threshold = 50;+ if (+ scrollHeight - scrollTop - clientHeight <= threshold &&+ hasNextPage &&+ !isFetchingNextPage+ ) {+ fetchNextPage();+ }+ },+ [fetchNextPage, hasNextPage, isFetchingNextPage],+ );++ return {+ artifacts,+ loading,+ handleScroll,+ hasMore: !!hasNextPage,+ };+};++type UseFetchArtifactTopicListOptions = {+ keywords?: string;+ enabled?: boolean;+};++export const useFetchArtifactTopicList = (+ options: UseFetchArtifactTopicListOptions = {},+) => {+ const { keywords = '', enabled = true } = options;+ const knowledgeBaseId = useKnowledgeBaseId();++ const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =+ useInfiniteQuery<{+ topics: IArtifactTopic[];+ total: number;+ }>({+ queryKey: ArtifactTopicKeys.list(knowledgeBaseId, keywords),+ enabled: !!knowledgeBaseId && enabled,+ gcTime: 0,+ initialPageParam: 1,+ queryFn: async ({ pageParam }) => {+ const page = pageParam as number;+ const { data } = await listArtifactTopics(knowledgeBaseId, {+ page,+ page_size: 30,+ keywords,+ });++ const responseData = data?.data;++ return {+ topics: responseData?.items ?? [],+ total: responseData?.total ?? 0,+ };+ },+ getNextPageParam: (lastPage, allPages) => {+ const loadedCount = allPages.reduce(+ (sum, page) => sum + page.topics.length,+ 0,+ );+ return loadedCount < lastPage.total ? allPages.length + 1 : undefined;+ },+ });++ const topics = useMemo(+ () => data?.pages.flatMap((page) => page.topics) ?? [],+ [data],+ );++ const loading = isFetching || isFetchingNextPage;++ const handleScroll = useCallback(+ (e: React.UIEvent<HTMLDivElement>) => {+ const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;+ const threshold = 50;+ if (+ scrollHeight - scrollTop - clientHeight <= threshold &&+ hasNextPage &&+ !isFetchingNextPage+ ) {+ fetchNextPage();+ }+ },+ [fetchNextPage, hasNextPage, isFetchingNextPage],+ );++ return {+ topics,+ loading,+ handleScroll,+ hasMore: !!hasNextPage,+ };+};++export function useFetchArtifactPage(artifact: IArtifact | null) {+ const knowledgeBaseId = useKnowledgeBaseId();+ const pageType = artifact?.page_type ?? '';+ const slug = artifact?.slug ?? '';++ const { data, isFetching: loading } = useQuery<IArtifactPage | null>({+ queryKey: ArtifactKeys.detail(knowledgeBaseId, pageType, slug),+ enabled: !!knowledgeBaseId && !!artifact && !!pageType && !!slug,+ gcTime: 0,+ queryFn: async () => {+ const { data } = await getArtifactPage(knowledgeBaseId, pageType, slug);+ return data?.data ?? null;+ },+ });++ return { data, loading };+}++export const useUpdateArtifactPage = () => {+ const knowledgeBaseId = useKnowledgeBaseId();+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation<+ ResponseType<IArtifactPage>,+ Error,+ IUpdateArtifactPageRequestParams+ >({+ mutationKey: [KnowledgeApiAction.UpdateArtifactPage],+ mutationFn: async (params) => {+ const { data = {} } = await updateArtifactPage(+ knowledgeBaseId,+ params.pageType,+ params.slug,+ params.body,+ );+ if (data.code === 0) {+ message.success(i18n.t(`message.updated`));+ queryClient.invalidateQueries({+ queryKey: ArtifactKeys.detail(+ knowledgeBaseId,+ params.pageType,+ params.slug,+ ),+ });+ }+ return data;+ },+ });++ return { data, loading, updateArtifactPage: mutateAsync };+};+export function useFetchKnowledgeGraph() {const knowledgeBaseId = useKnowledgeBaseId();@@ -341,6 +664,31 @@ export function useFetchKnowledgeGraph() {return { data, loading };}+export const artifactGraphKeys = {+ graph: (datasetId: string, params?: IFetchArtifactGraphRequestParams) =>+ [KnowledgeApiAction.FetchArtifactGraph, datasetId, params?.node] as const,+};++export function useFetchArtifactGraph(+ params?: IFetchArtifactGraphRequestParams,+ options?: { enabled?: boolean },+) {+ const knowledgeBaseId = useKnowledgeBaseId();++ const { data, isFetching: loading } = useQuery<IArtifactGraph>({+ queryKey: artifactGraphKeys.graph(knowledgeBaseId, params),+ initialData: { entities: [], relations: [] } as IArtifactGraph,+ enabled: !!knowledgeBaseId && (options?.enabled ?? true),+ gcTime: 0,+ queryFn: async () => {+ const { data } = await getArtifactGraph(knowledgeBaseId, params);+ return data?.data ?? { entities: [], relations: [] };+ },+ });++ return { data, loading };+}+export function useFetchKnowledgeMetadata(kbIds: string[] = []) {const { data, isFetching: loading } = useQuery<Record<string, Record<string, string[]>>@@ -403,6 +751,37 @@ export const useRemoveKnowledgeGraph = () => {return { data, loading, removeKnowledgeGraph: mutateAsync };};+export const useClearWiki = () => {+ const knowledgeBaseId = useKnowledgeBaseId();+ const queryClient = useQueryClient();++ const {+ data,+ isPending: loading,+ mutateAsync,+ } = useMutation({+ mutationKey: [KnowledgeApiAction.ClearWiki],+ mutationFn: async () => {+ const { data } = await clearWiki(knowledgeBaseId);+ if (data?.code === 0) {+ message.success(i18n.t('message.deleted'));+ queryClient.invalidateQueries({+ queryKey: ArtifactKeys.listByDataset(knowledgeBaseId),+ });+ queryClient.invalidateQueries({+ queryKey: ArtifactTopicKeys.listByDataset(knowledgeBaseId),+ });+ queryClient.invalidateQueries({+ queryKey: artifactGraphKeys.graph(knowledgeBaseId),+ });+ }+ return data;+ },+ });++ return { data, loading, clearWiki: mutateAsync };+};+export const useFetchKnowledgeList = (shouldFilterListWithoutDocument: boolean = false,keywords = '',diff --git a/web/src/interfaces/database/compilation-template.ts b/web/src/interfaces/database/compilation-template.tsnew file mode 100644index 0000000000..d68461a1f2--- /dev/null+++ b/web/src/interfaces/database/compilation-template.ts@@ -0,0 +1,74 @@+export interface ICompilationTemplateField {+ type?: string;+ description?: string;+ rule?: string;+ [key: string]: string | undefined;+}++export interface ICompilationTemplateSection {+ description?: string;+ fields: ICompilationTemplateField[];+}++export interface ICompilationTemplateRaptorConfig {+ prompt?: string;+ max_token?: number;+ threshold?: number;+ rechunk?: boolean;+}++export interface ICompilationTemplateConfig {+ kind?: string;+ llm_id?: string;+ entity?: ICompilationTemplateSection;+ relation?: ICompilationTemplateSection;+ raptor?: ICompilationTemplateRaptorConfig;+ global_rules?: string;+ [section: string]:+ | ICompilationTemplateSection+ | ICompilationTemplateRaptorConfig+ | string+ | boolean+ | undefined;+}++export interface ICompilationTemplate {+ id: string;+ name: string;+ description: string;+ kind: string;+ config: ICompilationTemplateConfig;+ create_time?: number;+ update_time?: number;+}++export interface ICompilationTemplateListResult {+ templates: ICompilationTemplate[];+ total: number;+}++export interface ICompilationTemplateBuiltin {+ id: string;+ kind: string;+ display_name: string;+ description: string;+ config: ICompilationTemplateConfig;+}++export interface ICompilationTemplateGroup {+ id: string;+ name: string;+ description?: string;+ scope?: string;+ avatar?: string;+ create_time?: number;+ update_time?: number;+ templates: ICompilationTemplate[];+}++export interface IWikiPreset {+ id: string;+ topic: string;+ instruction: string;+ page_example: string;+}diff --git a/web/src/interfaces/database/dataset-skill.ts b/web/src/interfaces/database/dataset-skill.tsnew file mode 100644index 0000000000..f1574a5769--- /dev/null+++ b/web/src/interfaces/database/dataset-skill.ts@@ -0,0 +1,29 @@+export interface DatasetSkillTreeNode {+ skill_kwd: string;+ md_with_weight?: string;+ children_kwd?: DatasetSkillTreeNode[];+}++export interface DatasetSkillTree {+ id: string;+ kb_id: string;+ doc_id: string;+ compile_kwd: 'skill_all';+ skill_with_weight: DatasetSkillTreeNode[];+}++export interface DatasetSkillPage {+ id?: string;+ kb_id?: string;+ doc_id?: string;+ compile_kwd?: 'skill';+ skill_kwd: string;+ depth_int?: number;+ children_kwd?: string[];+ source_doc_ids?: string[];+ md_with_weight: string;+}++export interface HasAnySkillResponse {+ has: boolean;+}diff --git a/web/src/interfaces/database/dataset.ts b/web/src/interfaces/database/dataset.tsindex b199bcefa6..4eae9de8b5 100644--- a/web/src/interfaces/database/dataset.ts+++ b/web/src/interfaces/database/dataset.ts@@ -222,3 +222,69 @@ export interface IKnowledgeGraph {graph: Record<string, any>;mind_map: import('@antv/g6/lib/types').TreeData;}++export interface IArtifact {+ slug: string;+ title: string;+ page_type?: string;+ summary?: string;+}++export interface IArtifactTopic {+ topic: string;+ title: string;+ slug: string;+}++export interface IArtifactPage {+ slug: string;+ title: string;+ page_type: string;+ content_md_rendered: string;+ summary: string;+ entity_names: string[];+ outlinks: string[];+ related_kb_pages: string[];+ source_chunk_ids: string[];+ source_doc_ids: string[];+}++export interface IWikiCommit {+ id: string;+ title: string;+ comments: string;+ user_id: string;+ create_time: number;+ create_date: string;+ user_nickname: string;+}++export interface IWikiCommitDetail extends IWikiCommit {+ diff: string;+ content_after: string;+}++export interface IWikiCommitListResponse {+ total: number;+ items: IWikiCommit[];+}++export interface IArtifactGraphEntity {+ slug: string;+ name: string;+ aliases: string[];+ description: string;+ type: string;+ weight: number;+ source_chunk_ids?: string[];+}++export interface IArtifactGraphRelation {+ from: string;+ to: string;+}++export interface IArtifactGraph {+ entities: IArtifactGraphEntity[];+ relations: IArtifactGraphRelation[];+}diff --git a/web/src/interfaces/database/document-structure.ts b/web/src/interfaces/database/document-structure.tsnew file mode 100644index 0000000000..6ba6e70363--- /dev/null+++ b/web/src/interfaces/database/document-structure.ts@@ -0,0 +1,32 @@+import { CompilationTemplateKind } from '@/constants/compilation';++export type StructureTemplateKind = CompilationTemplateKind | 'raptor';++export interface IStructureGraphEntity {+ id?: string;+ name?: string;+ aliases?: string[];+ description?: string;+ discription?: string;+ mention_count?: number;+ source_chunk_ids?: string[];+ type?: string;+}++export interface IStructureGraphRelation {+ from: string;+ to: string;+ type?: string;+}++export interface IStructureGraphTemplate {+ kind: StructureTemplateKind;+ template_id: string;+ template_name: string;+ entities: IStructureGraphEntity[];+ relations: IStructureGraphRelation[];+}++export interface IStructureGraphResponse {+ templates: IStructureGraphTemplate[];+}diff --git a/web/src/interfaces/database/document.ts b/web/src/interfaces/database/document.tsindex 3f676970dc..9e985fc94d 100644--- a/web/src/interfaces/database/document.ts+++ b/web/src/interfaces/database/document.ts@@ -60,6 +60,7 @@ export interface IParserConfig {enum?: string[];}>;enable_metadata?: boolean;+ compilation_template_group_id?: string[];}interface Raptor {diff --git a/web/src/interfaces/request/compilation-template.ts b/web/src/interfaces/request/compilation-template.tsnew file mode 100644index 0000000000..fde2677aa9--- /dev/null+++ b/web/src/interfaces/request/compilation-template.ts@@ -0,0 +1,58 @@+export interface IFetchCompilationTemplatesRequestParams {+ keywords?: string;+ page?: number;+ page_size?: number;+ kind?: string;+}++export interface ICompilationTemplateSectionRequest {+ description?: string;+ fields: Array<Record<string, string>>;+}++export interface ICompilationTemplateRaptorConfigRequest {+ prompt?: string;+ max_token?: number;+ threshold?: number;+ rechunk?: boolean;+}++export interface ICompilationTemplateConfigRequest {+ kind?: string;+ llm_id?: string;+ entity?: ICompilationTemplateSectionRequest;+ relation?: ICompilationTemplateSectionRequest;+ raptor?: ICompilationTemplateRaptorConfigRequest;+ global_rules?: string;+ [section: string]:+ | ICompilationTemplateSectionRequest+ | ICompilationTemplateRaptorConfigRequest+ | string+ | boolean+ | undefined;+}++export interface ICreateCompilationTemplateRequestBody {+ name: string;+ description?: string;+ kind: string;+ config: ICompilationTemplateConfigRequest;+}++export type IUpdateCompilationTemplateRequestBody =+ Partial<ICreateCompilationTemplateRequestBody>;++export interface ICreateCompilationTemplateGroupRequestBody {+ name: string;+ description?: string;+ avatar?: string;+ templates: Array<{+ name?: string;+ description?: string;+ kind: string;+ config: ICompilationTemplateConfigRequest;+ }>;+}++export type IUpdateCompilationTemplateGroupRequestBody =+ Partial<ICreateCompilationTemplateGroupRequestBody>;diff --git a/web/src/interfaces/request/document.ts b/web/src/interfaces/request/document.tsindex 05693ca356..a6f97be152 100644--- a/web/src/interfaces/request/document.ts+++ b/web/src/interfaces/request/document.ts@@ -22,6 +22,7 @@ export interface IChangeParserConfigRequestBody {clustering_method?: 'gmm' | 'ahc';tree_builder?: 'raptor' | 'psi';};+ compilation_template_group_id?: string[];// Metadata fieldsmetadata?: Array<{key?: string;diff --git a/web/src/interfaces/request/knowledge.ts b/web/src/interfaces/request/knowledge.tsindex f93c5dd932..92edc54c07 100644--- a/web/src/interfaces/request/knowledge.ts+++ b/web/src/interfaces/request/knowledge.ts@@ -39,4 +39,35 @@ export interface IFetchDocumentListRequestBody {run_status?: string[];return_empty_metadata?: boolean;metadata?: Record<string, string[]>;+ ids?: string[];+}++export interface IFetchArtifactListRequestParams {+ page?: number;+ page_size?: number;+ keywords?: string;+ page_type?: string;+ topic?: string;+}++export interface IFetchArtifactTopicListRequestParams {+ page?: number;+ page_size?: number;+ keywords?: string;+}++export interface IFetchArtifactGraphRequestParams {+ node?: string;+}++export interface IUpdateArtifactPageRequestBody {+ content_md: string;+ comments: string;+ title?: string;+}++export interface IUpdateArtifactPageRequestParams {+ pageType: string;+ slug: string;+ body: IUpdateArtifactPageRequestBody;}diff --git a/web/src/lib/editor/content-editable.tsx b/web/src/lib/editor/content-editable.tsxnew file mode 100644index 0000000000..a60339ff5a--- /dev/null+++ b/web/src/lib/editor/content-editable.tsx@@ -0,0 +1,30 @@+/**+ * ContentEditable wrapper — thin wrapper around Lexical's contenteditable.+ */++import { ContentEditable } from '@lexical/react/LexicalContentEditable';+import type { JSX } from 'react';++interface Props {+ className?: string;+ placeholderClassName?: string;+ placeholder: string;+}++export default function LexicalContentEditable({+ className,+ placeholder,+ placeholderClassName,+}: Props): JSX.Element {+ return (+ <ContentEditable+ className={className ?? 'nim-content-editable'}+ aria-placeholder={placeholder}+ placeholder={+ <div className={placeholderClassName ?? 'nim-placeholder'}>+ {placeholder}+ </div>+ }+ />+ );+}diff --git a/web/src/lib/editor/editor-theme.css b/web/src/lib/editor/editor-theme.cssnew file mode 100644index 0000000000..e41f446d8b--- /dev/null+++ b/web/src/lib/editor/editor-theme.css@@ -0,0 +1,668 @@+/**+ * Nimbalyst Editor Theme — direct port of NimbalystEditorTheme.css+ *+ * CSS variables defined on BOTH :root (global fallback) and+ * .nimbalyst-editor (scoped override) for maximum reliability.+ */++/* ===== THEME-AWARE VARIABLES — mapped to project design tokens ===== */+:root {+ --nim-bg: var(--bg-base);+ --nim-bg-secondary: var(--bg-card);+ --nim-bg-tertiary: var(--bg-component);+ --nim-bg-hover: rgba(var(--text-primary), 0.05);+ --nim-bg-selected: rgba(var(--accent-primary), 0.15);+ --nim-bg-active: var(--bg-component);+ --nim-text: rgb(var(--text-primary));+ --nim-text-muted: rgb(var(--text-secondary));+ --nim-text-faint: var(--text-disabled);+ --nim-text-disabled: var(--text-disabled);+ --nim-border: var(--border-default);+ --nim-border-focus: rgb(var(--accent-primary));+ --nim-primary: rgb(var(--accent-primary));+ --nim-primary-hover: rgb(var(--accent-primary));+ --nim-link: rgb(var(--accent-primary));+ --nim-link-hover: rgba(var(--accent-primary), 0.8);+ --nim-accent-subtle: rgba(var(--accent-primary), 0.1);+ --nim-success: rgb(var(--state-success));+ --nim-warning: rgb(var(--state-warning));+ --nim-error: rgb(var(--state-error));+ --nim-info: rgb(var(--accent-primary));+ --nim-purple: var(--colors-outline-sentiment-primary);+ --nim-code-bg: var(--bg-component);+ --nim-code-text: rgb(var(--text-primary));+ --nim-code-border: var(--border-default);+ --nim-code-gutter: var(--bg-card);+ --nim-table-border: var(--border-default);+ --nim-table-header: var(--bg-card);+ --nim-table-cell: var(--bg-base);+ --nim-table-stripe: var(--bg-card);+ --nim-toolbar-bg: var(--bg-card);+ --nim-toolbar-border: var(--border-default);+ --nim-toolbar-hover: var(--bg-component);+ --nim-toolbar-active: rgba(var(--accent-primary), 0.2);+ --nim-highlight-bg: rgba(var(--state-warning), 0.2);+ --nim-highlight-border: rgba(var(--state-warning), 0.4);+ --nim-quote-text: rgb(var(--text-secondary));+ --nim-quote-border: var(--border-default);+ --nim-scrollbar-thumb: var(--border-default);+ --nim-scrollbar-thumb-hover: var(--border-button);+ --nim-scrollbar-track: transparent;+ --nim-diff-add-bg: rgba(var(--state-success), 0.15);+ --nim-diff-add-border: rgba(var(--state-success), 0.4);+ --nim-diff-remove-bg: rgba(var(--state-error), 0.15);+ --nim-diff-remove-border: rgba(var(--state-error), 0.4);+ --nim-code-comment: #6a9955;+ --nim-code-punctuation: #cccccc;+ --nim-code-property: #9cdcfe;+ --nim-code-selector: #d7ba7d;+ --nim-code-operator: #d4d4d4;+ --nim-code-attr: #92c5f8;+ --nim-code-variable: #4fc1ff;+ --nim-code-function: #dcdcaa;+ --max-text-width: 800px;+}++/* ===== Editor container base styles (inherits --nim-* from :root/html inline) ===== */+.nimbalyst-editor {+ font-family:+ system-ui,+ -apple-system,+ BlinkMacSystemFont,+ '.SFNSText-Regular',+ sans-serif;+ -webkit-font-smoothing: antialiased;+ -moz-osx-font-smoothing: grayscale;+ background: var(--nim-bg);+ color: var(--nim-text);+ display: flex;+ flex-direction: column;+ flex: 1;+ min-height: 0;+}++/* ===== BASE — with #root prefix for max specificity ===== */+#root .nim-ltr {+ text-align: left;+}+#root .nim-rtl {+ text-align: right;+}+#root .nim-paragraph {+ margin: 0;+ position: relative;+}++#root .nim-content-editable {+ outline: none;+ min-height: 200px;+ padding: 16px 24px;+ font-size: 15px;+ line-height: 1.8;+ max-width: var(--max-text-width);+ flex: 1;+}++#root .nim-placeholder {+ color: var(--nim-text-faint);+ overflow: hidden;+ position: absolute;+ text-overflow: ellipsis;+ top: 16px;+ left: 24px;+ font-size: 15px;+ user-select: none;+ display: inline-block;+ pointer-events: none;+}++/* ===== HEADINGS ===== */+#root .nim-h1 {+ font-size: 28px;+ color: var(--nim-text);+ font-weight: 500;+ margin: 0;+}+#root .nim-h2 {+ font-size: 20px;+ color: var(--nim-text-muted);+ font-weight: 600;+ margin: 0;+}+#root .nim-h3 {+ font-size: 16px;+ color: var(--nim-text-muted);+ margin: 0;+}+#root .nim-h4 {+ font-size: 14px;+ color: var(--nim-text-muted);+ margin: 0;+}+#root .nim-h5 {+ font-size: 12px;+ color: var(--nim-text-muted);+ margin: 0;+}+#root .nim-h6 {+ font-size: 10px;+ color: var(--nim-text-muted);+ margin: 0;+}++/* ===== TEXT FORMATTING ===== */+#root .nim-text-bold {+ font-weight: bold;+}+#root .nim-text-italic {+ font-style: italic;+}+#root .nim-text-underline {+ text-decoration: underline;+}+#root .nim-text-strikethrough {+ text-decoration: line-through;+}+#root .nim-text-underline-strikethrough {+ text-decoration: underline line-through;+}+#root .nim-text-subscript {+ font-size: 0.8em;+ vertical-align: sub !important;+}+#root .nim-text-superscript {+ font-size: 0.8em;+ vertical-align: super;+}+#root .nim-text-code {+ background-color: var(--nim-code-bg);+ padding: 1px 0.25rem;+ font-family: Menlo, Consolas, Monaco, monospace;+ font-size: 94%;+}+#root .nim-text-highlight {+ background: var(--nim-highlight-bg);+ border-bottom: 2px solid var(--nim-highlight-border);+}++/* ===== QUOTE ===== */+#root .nim-quote {+ margin: 0;+ margin-left: 20px;+ margin-bottom: 10px;+ font-size: 15px;+ color: var(--nim-quote-text);+ border-left-color: var(--nim-quote-border);+ border-left-width: 4px;+ border-left-style: solid;+ padding-left: 16px;+}++/* ===== LINK ===== */+#root .nim-link {+ color: var(--nim-link);+ text-decoration: none;+}+#root .nim-link:hover {+ text-decoration: underline;+ cursor: pointer;+}++/* ===== CODE BLOCKS ===== */+#root .nim-code {+ background-color: var(--nim-code-bg);+ font-family: Menlo, Consolas, Monaco, monospace;+ display: block;+ padding: 8px 8px 8px 52px;+ line-height: 1.53;+ font-size: 13px;+ margin: 0;+ margin-top: 8px;+ margin-bottom: 8px;+ overflow-x: auto;+ position: relative;+ tab-size: 2;+ border: 1px solid var(--nim-code-border);+ border-radius: 8px;+}+#root .nim-code:before {+ content: attr(data-gutter);+ position: absolute;+ background-color: var(--nim-code-gutter);+ left: 0;+ top: 0;+ border-right: 1px solid var(--nim-code-border);+ padding: 8px;+ color: var(--nim-text-faint);+ white-space: pre-wrap;+ text-align: right;+ min-width: 25px;+}++/* ===== SYNTAX HIGHLIGHTING ===== */+#root .nim-token-comment {+ color: var(--nim-code-comment);+ font-style: italic;+}+#root .nim-token-punctuation {+ color: var(--nim-code-punctuation);+}+#root .nim-token-property {+ color: var(--nim-code-property);+}+#root .nim-token-selector {+ color: var(--nim-code-selector);+}+#root .nim-token-operator {+ color: var(--nim-code-operator);+}+#root .nim-token-attr {+ color: var(--nim-code-attr);+}+#root .nim-token-variable {+ color: var(--nim-code-variable);+}+#root .nim-token-function {+ color: var(--nim-code-function);+}+#root .nim-token-inserted {+ color: #9ccc65;+}+#root .nim-token-deleted {+ color: #ef5350;+}++/* ===== LISTS ===== */+#root .nim-ol1 {+ padding: 0;+ margin: 0;+ list-style: decimal inside;+}+#root .nim-ol2 {+ padding: 0;+ margin: 0;+ list-style: upper-alpha inside;+}+#root .nim-ol3 {+ padding: 0;+ margin: 0;+ list-style: lower-alpha inside;+}+#root .nim-ol4 {+ padding: 0;+ margin: 0;+ list-style: upper-roman inside;+}+#root .nim-ol5 {+ padding: 0;+ margin: 0;+ list-style: lower-roman inside;+}+#root .nim-ul {+ padding: 0;+ margin: 0;+ list-style: disc inside;+ max-width: var(--max-text-width);+}+#root .nim-list-item {+ margin: 0 24px;+}+#root .nim-list-item::marker {+ color: var(--nim-text);+}++#root .nim-list-item-checked,+#root .nim-list-item-unchecked {+ position: relative;+ margin-left: 8px;+ margin-right: 8px;+ padding-left: 24px;+ padding-right: 24px;+ list-style-type: none;+ outline: none;+}+#root .nim-list-item-checked {+ text-decoration: line-through;+}+#root .nim-list-item-unchecked:before,+#root .nim-list-item-checked:before {+ content: '';+ width: 16px;+ height: 16px;+ top: 2px;+ left: 0;+ cursor: pointer;+ display: block;+ background-size: cover;+ position: absolute;+}+#root .nim-list-item-unchecked:before {+ border: 1px solid var(--nim-text-muted);+ border-radius: 2px;+}+#root .nim-list-item-checked:before {+ border: 1px solid var(--nim-primary);+ border-radius: 2px;+ background-color: var(--nim-primary);+}+#root .nim-list-item-checked:after {+ content: '';+ cursor: pointer;+ border-color: #fff;+ border-style: solid;+ position: absolute;+ top: 6px;+ width: 3px;+ left: 7px;+ right: 7px;+ height: 6px;+ transform: rotate(45deg);+ border-width: 0 2px 2px 0;+}+#root .nim-nested-list-item {+ list-style-type: none;+}+#root .nim-nested-list-item:before,+#root .nim-nested-list-item:after {+ display: none;+}++/* ===== HORIZONTAL RULE ===== */+#root .nim-hr {+ padding: 2px 2px;+ border: none;+ margin: 1em 0;+ cursor: pointer;+}+#root .nim-hr:after {+ content: '';+ display: block;+ height: 2px;+ background-color: var(--nim-border);+ line-height: 2px;+}+#root .nim-hr.nim-hr-selected {+ outline: 2px solid var(--nim-primary);+ user-select: none;+}++/* ===== HASHTAG ===== */+#root .nim-hashtag {+ background-color: color-mix(in srgb, var(--nim-primary) 15%, transparent);+ border-radius: 4px;+ padding-left: 3px;+ padding-right: 3px;+ display: inline-block;+}++/* ===== MERMAID ===== */+.mermaid-container {+ margin: 8px 0;+}+.mermaid-block {+ margin: 12px 0;+ text-align: center;+}+.mermaid-render-container {+ overflow-x: auto;+}+.mermaid-render-container svg {+ max-width: 100%;+ height: auto;+}++/* Mermaid dark theme */+.mermaid-render-container svg .node rect,+.mermaid-render-container svg .node circle,+.mermaid-render-container svg .node ellipse,+.mermaid-render-container svg .node polygon,+.mermaid-render-container svg .node path {+ fill: var(--nim-bg-tertiary) !important;+ stroke: var(--nim-border) !important;+}+.mermaid-render-container svg text,+.mermaid-render-container svg .nodeLabel,+.mermaid-render-container svg .label,+.mermaid-render-container svg .edgeLabel {+ fill: var(--nim-text) !important;+ color: var(--nim-text) !important;+}+.mermaid-render-container svg .edge path,+.mermaid-render-container svg .flowchart-link {+ stroke: var(--nim-text-muted) !important;+}+.mermaid-render-container svg marker path {+ fill: var(--nim-text-muted) !important;+ stroke: var(--nim-text-muted) !important;+}+.mermaid-render-container svg .edgeLabel rect,+.mermaid-render-container svg .edgeLabel span {+ background-color: var(--nim-bg) !important;+ fill: var(--nim-bg) !important;+ color: var(--nim-text) !important;+}+.mermaid-render-container svg .cluster rect {+ fill: var(--nim-bg-secondary) !important;+ stroke: var(--nim-border) !important;+}++/* ===== EDITOR CONTAINER ===== */+#root .nim-editor-container {+ flex: 1;+ display: flex;+ flex-direction: column;+ min-height: 0;+}+#root .nim-editor-scroller {+ flex: 1;+ overflow-y: auto;+ position: relative;+ display: flex;+ flex-direction: column;+}+#root .nim-editor {+ flex: 1;+ position: relative;+}++/* ===== MODE SWITCH ===== */+#root .nim-mode-bar {+ display: flex;+ align-items: center;+ gap: 4px;+ padding: 4px 12px;+ border-bottom: 1px solid var(--nim-border);+ background: var(--nim-bg-secondary);+ flex-shrink: 0;+}+#root .nim-mode-btn {+ padding: 4px 10px;+ border: 1px solid transparent;+ border-radius: 4px;+ cursor: pointer;+ font-size: 12px;+ font-weight: 500;+ background: transparent;+ color: var(--nim-text-muted);+ font-family: inherit;+ transition: 0.1s;+}+#root .nim-mode-btn:hover {+ background: var(--nim-bg-hover);+ color: var(--nim-text);+}+#root .nim-mode-btn.active {+ background: var(--nim-bg-selected);+ border-color: var(--nim-primary);+ color: var(--nim-primary);+}++/* ===== Lexical plugin containers ===== */+#root .nimbalyst-editor .editor-shell {+ flex: 1;+ min-height: 0;+ display: flex;+ flex-direction: column;+}+#root .nimbalyst-editor .editor-container {+ flex: 1;+ display: flex;+ flex-direction: column;+ position: relative;+ min-height: 0;+}++/* ===== TABLES ===== */+#root .nim-table-scrollable-wrapper {+ overflow-x: auto;+ margin: 0px 25px 30px 0px;+}++#root .nim-table-scrollable-wrapper > .nim-table {+ margin-top: 0;+ margin-bottom: 0;+}++#root .nim-table-alignment-center {+ margin-left: auto;+ margin-right: auto;+}++#root .nim-table-alignment-right {+ margin-left: auto;+}++#root .nim-table {+ border-collapse: collapse;+ border-spacing: 0;+ overflow-y: scroll;+ overflow-x: scroll;+ table-layout: fixed;+ margin-top: 25px;+ margin-bottom: 30px;+}++#root .nim-table-scrollable-wrapper.nim-table-frozen-row {+ overflow-x: clip;+}++#root .nim-table-frozen-row tr:nth-of-type(1) > td {+ overflow: clip;+ background-color: var(--nim-table-cell);+ position: sticky;+ z-index: 2;+ top: 44px;+}++#root .nim-table-frozen-row tr:nth-of-type(1) > th {+ overflow: clip;+ background-color: var(--nim-table-header);+ position: sticky;+ z-index: 2;+ top: 44px;+}++#root .nim-table-frozen-row tr:nth-of-type(1) > th:after,+#root .nim-table-frozen-row tr:nth-of-type(1) > td:after {+ content: '';+ position: absolute;+ left: 0;+ bottom: 0;+ width: 100%;+ border-bottom: 1px solid var(--nim-table-border);+}++#root .nim-table-frozen-column tr > td:first-child {+ background-color: var(--nim-table-cell);+ position: sticky;+ z-index: 2;+ left: 0;+}++#root .nim-table-frozen-column tr > th:first-child {+ background-color: var(--nim-table-header);+ position: sticky;+ z-index: 2;+ left: 0;+}++#root .nim-table-frozen-column tr > :first-child::after {+ content: '';+ position: absolute;+ left: 0;+ top: 0;+ right: 0;+ height: 100%;+ border-right: 1px solid var(--nim-table-border);+}++#root .nim-table-row-striping tr:nth-child(even),+#root+ .nim-table-frozen-column+ .nim-table.nim-table-row-striping+ tr:nth-child(even)+ > td:first-child {+ background-color: var(--nim-table-stripe);+}++#root .nim-table-selection *::selection {+ background-color: transparent;+}++#root .nim-table-selected {+ outline: 2px solid var(--nim-primary);+}++#root .nim-table-cell {+ border: 1px solid var(--nim-table-border);+ color: var(--nim-text);+ vertical-align: top;+ text-align: start;+ padding: 6px 8px;+ position: relative;+ outline: none;+ overflow: auto;+ min-width: 50px;+}++#root .nim-table-cell > * {+ overflow: inherit;+}++#root .nim-table-cell-resizer {+ position: absolute;+ right: -4px;+ height: 100%;+ width: 8px;+ cursor: ew-resize;+ z-index: 10;+ top: 0;+}++#root .nim-table-cell-header {+ background-color: var(--nim-table-header);+ color: var(--nim-text);+ text-align: start;+}++#root .nim-table-cell-selected {+ caret-color: transparent;+}++#root .nim-table-cell-selected::after {+ position: absolute;+ left: 0;+ right: 0;+ bottom: 0;+ top: 0;+ background-color: highlight;+ mix-blend-mode: multiply;+ content: '';+ pointer-events: none;+}++/* Table add buttons (simplified) */+#root .nim-table-add-columns,+#root .nim-table-add-rows {+ display: none; /* Hide by default - shown only during table editing */+}diff --git a/web/src/lib/editor/editor-theme.ts b/web/src/lib/editor/editor-theme.tsnew file mode 100644index 0000000000..160e32d3f8--- /dev/null+++ b/web/src/lib/editor/editor-theme.ts@@ -0,0 +1,93 @@+/**+ * Lexical editor theme — maps node types to `nim-*` CSS class names.+ * Direct port from Nimbalyst's NimbalystEditorTheme.ts.+ */++import type { EditorThemeClasses } from 'lexical';++const theme: EditorThemeClasses = {+ autocomplete: 'nim-autocomplete',+ blockCursor: 'nim-block-cursor',+ characterLimit: 'nim-character-limit',+ code: 'nim-code',+ codeHighlight: {+ atrule: 'nim-token-attr',+ attr: 'nim-token-attr',+ boolean: 'nim-token-property',+ builtin: 'nim-token-selector',+ cdata: 'nim-token-comment',+ char: 'nim-token-selector',+ class: 'nim-token-function',+ 'class-name': 'nim-token-function',+ comment: 'nim-token-comment',+ constant: 'nim-token-property',+ deleted: 'nim-token-deleted',+ doctype: 'nim-token-comment',+ entity: 'nim-token-operator',+ function: 'nim-token-function',+ important: 'nim-token-variable',+ inserted: 'nim-token-inserted',+ keyword: 'nim-token-attr',+ namespace: 'nim-token-variable',+ number: 'nim-token-property',+ operator: 'nim-token-operator',+ prolog: 'nim-token-comment',+ property: 'nim-token-property',+ punctuation: 'nim-token-punctuation',+ regex: 'nim-token-variable',+ selector: 'nim-token-selector',+ string: 'nim-token-selector',+ symbol: 'nim-token-property',+ tag: 'nim-token-property',+ unchanged: 'nim-token-unchanged',+ url: 'nim-token-operator',+ variable: 'nim-token-variable',+ },+ embedBlock: { base: 'nim-embed-block', focus: 'nim-embed-block-focus' },+ hashtag: 'nim-hashtag',+ heading: {+ h1: 'nim-h1',+ h2: 'nim-h2',+ h3: 'nim-h3',+ h4: 'nim-h4',+ h5: 'nim-h5',+ h6: 'nim-h6',+ },+ hr: 'nim-hr',+ hrSelected: 'nim-hr-selected',+ image: 'editor-image',+ indent: 'nim-indent',+ link: 'nim-link',+ list: {+ checklist: 'nim-checklist',+ listitem: 'nim-list-item',+ listitemChecked: 'nim-list-item-checked',+ listitemUnchecked: 'nim-list-item-unchecked',+ nested: { listitem: 'nim-nested-list-item' },+ olDepth: ['nim-ol1', 'nim-ol2', 'nim-ol3', 'nim-ol4', 'nim-ol5'],+ ul: 'nim-ul',+ },+ ltr: 'nim-ltr',+ mark: 'nim-mark',+ markOverlap: 'nim-mark-overlap',+ paragraph: 'nim-paragraph',+ quote: 'nim-quote',+ rtl: 'nim-rtl',+ tab: 'nim-tab-node',+ table: 'nim-table',+ tableCell: 'nim-table-cell',+ tableCellHeader: 'nim-table-cell-header',+ text: {+ bold: 'nim-text-bold',+ code: 'nim-text-code',+ highlight: 'nim-text-highlight',+ italic: 'nim-text-italic',+ strikethrough: 'nim-text-strikethrough',+ subscript: 'nim-text-subscript',+ superscript: 'nim-text-superscript',+ underline: 'nim-text-underline',+ underlineStrikethrough: 'nim-text-underline-strikethrough',+ },+};++export default theme;diff --git a/web/src/lib/editor/index.ts b/web/src/lib/editor/index.tsnew file mode 100644index 0000000000..12b57609b9--- /dev/null+++ b/web/src/lib/editor/index.ts@@ -0,0 +1,23 @@+/**+ * Editor module public API.+ */++export { default as theme } from './editor-theme';+export { default as LexicalEditor } from './lexical-editor';+export { default as nodes } from './nodes';+export { default as RawMarkdownEditor } from './raw-markdown-editor';++export {+ $convertFromEnhancedMarkdownString,+ $convertToEnhancedMarkdownString,+ CORE_TRANSFORMERS,+} from './markdown';++export {+ $createMermaidNode,+ $isMermaidNode,+ MermaidNode,+} from './mermaid-node';+export type { MermaidPayload } from './mermaid-node';++export { MERMAID_TRANSFORMER } from './mermaid-transformer';diff --git a/web/src/lib/editor/lexical-editor.tsx b/web/src/lib/editor/lexical-editor.tsxnew file mode 100644index 0000000000..f314827916--- /dev/null+++ b/web/src/lib/editor/lexical-editor.tsx@@ -0,0 +1,198 @@+/**+ * LexicalEditor — WYSIWYG markdown editor using Meta's Lexical framework.+ *+ * Ported from Nimbalyst's NimbalystEditor + Editor.tsx.+ * Markdown import on init, markdown export on change.+ * Wraps content in nimbalyst-editor container for theming.+ */++import { LexicalComposer } from '@lexical/react/LexicalComposer';+import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';+import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';+import { HashtagPlugin } from '@lexical/react/LexicalHashtagPlugin';+import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';+import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';+import { ListPlugin } from '@lexical/react/LexicalListPlugin';+import { MarkdownShortcutPlugin } from '@lexical/react/LexicalMarkdownShortcutPlugin';+import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';+import { TablePlugin } from '@lexical/react/LexicalTablePlugin';+import { $createParagraphNode, $getRoot } from 'lexical';+import type { JSX } from 'react';+import { useEffect, useMemo, useRef } from 'react';++import ContentEditable from './content-editable';+import theme from './editor-theme';+import {+ $convertFromEnhancedMarkdownString,+ $convertToEnhancedMarkdownString,+ CORE_TRANSFORMERS,+ type Transformer,+} from './markdown';+import nodes from './nodes';++// Direct CSS import (more reliable than @import in App.css)+import './editor-theme.css';++interface Props {+ content: string;+ onChange?: (markdown: string) => void;+ readOnly?: boolean;+ placeholder?: string;+ onToggleSource?: () => void;+ showSource?: boolean;+}++function InitialContentPlugin({+ content,+ transformers,+}: {+ content: string;+ transformers: Transformer[];+}) {+ const [editor] = useLexicalComposerContext();+ const seeded = useRef(false);++ useEffect(() => {+ // Seed ONCE on mount. Subsequent external content changes are handled by ContentSyncPlugin.+ if (seeded.current) return;+ seeded.current = true;++ editor.update(() => {+ const root = $getRoot();+ root.clear();+ if (content && content.trim()) {+ $convertFromEnhancedMarkdownString(content, transformers);+ } else {+ root.append($createParagraphNode());+ }+ });+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [editor]);++ return null;+}++function ContentSyncPlugin({+ content,+ transformers,+}: {+ content: string;+ transformers: Transformer[];+}) {+ const [editor] = useLexicalComposerContext();++ useEffect(() => {+ editor.update(() => {+ const currentMarkdown = $convertToEnhancedMarkdownString(transformers);+ if (currentMarkdown === content) return;++ const root = $getRoot();+ root.clear();+ if (content && content.trim()) {+ $convertFromEnhancedMarkdownString(content, transformers);+ } else {+ root.append($createParagraphNode());+ }+ });+ }, [content, editor, transformers]);++ return null;+}++function ChangeListener({+ onChange,+ transformers,+}: {+ onChange?: (md: string) => void;+ transformers: Transformer[];+}) {+ const [editor] = useLexicalComposerContext();+ const initRef = useRef(false);++ useEffect(() => {+ if (!onChange) return;+ const removeListener = editor.registerUpdateListener(+ ({ dirtyElements, dirtyLeaves }) => {+ if (!initRef.current) {+ initRef.current = true;+ return;+ }+ if (dirtyElements.size === 0 && dirtyLeaves.size === 0) return;+ const markdown = editor.read(() =>+ $convertToEnhancedMarkdownString(transformers),+ );+ onChange(markdown);+ },+ );+ return removeListener;+ }, [editor, onChange, transformers]);++ return null;+}++import FloatingSelectionToolbar from './plugins/floating-selection-toolbar';+import TableActionsPlugin from './plugins/table-actions-plugin';+import ToolbarPlugin from './plugins/toolbar-plugin';++export default function LexicalEditor({+ content,+ onChange,+ readOnly = false,+ placeholder = 'Start writing...',+ onToggleSource,+ showSource = false,+}: Props): JSX.Element {+ const transformers = useMemo(() => CORE_TRANSFORMERS, []);++ const initialConfig = useMemo(+ () => ({+ namespace: 'LlmWikiEditor',+ nodes: [...nodes],+ theme,+ editable: !readOnly,+ onError: (error: Error) => {+ console.error('[LexicalEditor] Error:', error);+ },+ }),+ [readOnly],+ );++ return (+ <div className="nimbalyst-editor">+ <div className="editor-shell">+ <LexicalComposer initialConfig={initialConfig}>+ <div className="editor-container">+ <ToolbarPlugin+ onToggleSource={onToggleSource || (() => {})}+ showSource={showSource}+ />+ <InitialContentPlugin+ content={content}+ transformers={transformers}+ />+ <ContentSyncPlugin content={content} transformers={transformers} />+ <ChangeListener onChange={onChange} transformers={transformers} />+ <FloatingSelectionToolbar />+ <RichTextPlugin+ contentEditable={+ <div className="nim-editor-scroller">+ <div className="nim-editor">+ <ContentEditable placeholder={placeholder} />+ </div>+ </div>+ }+ ErrorBoundary={LexicalErrorBoundary}+ />+ <HistoryPlugin />+ <MarkdownShortcutPlugin transformers={transformers} />+ <ListPlugin />+ <LinkPlugin />+ <HashtagPlugin />+ <TablePlugin />+ <TableActionsPlugin />+ </div>+ </LexicalComposer>+ </div>+ </div>+ );+}diff --git a/web/src/lib/editor/markdown/enhanced-markdown-export.ts b/web/src/lib/editor/markdown/enhanced-markdown-export.tsnew file mode 100644index 0000000000..6fe923b5fb--- /dev/null+++ b/web/src/lib/editor/markdown/enhanced-markdown-export.ts@@ -0,0 +1,481 @@+/**+ * Enhanced markdown export supporting individual node export and+ * proper handling of all node types.+ * Ported from Nimbalyst — simplified: no frontmatter, no diff/reject mode.+ */++import type {+ ElementTransformer,+ MultilineElementTransformer,+ TextFormatTransformer,+ TextMatchTransformer,+} from '@lexical/markdown';+import {+ $getRoot,+ $isDecoratorNode,+ $isElementNode,+ $isLineBreakNode,+ $isRootOrShadowRoot,+ $isTextNode,+ type ElementNode,+ type LexicalNode,+ type TextFormatType,+ type TextNode,+} from 'lexical';+export type LexicalTransformer =+ | ElementTransformer+ | MultilineElementTransformer+ | TextFormatTransformer+ | TextMatchTransformer;++type UnclosedFormatTag = { format: TextFormatType; tag: string };++export interface EnhancedExportOptions {+ shouldPreserveNewLines?: boolean;+}++export function $convertToEnhancedMarkdownString(+ transformers: LexicalTransformer[],+ options: EnhancedExportOptions = {},+): string {+ const { shouldPreserveNewLines = true } = options;++ return $exportNodeToMarkdown(+ transformers,+ $getRoot(),+ shouldPreserveNewLines,+ );+}++export function $convertNodeToEnhancedMarkdownString(+ transformers: LexicalTransformer[],+ node?: ElementNode | null,+ shouldPreserveNewLines: boolean = true,+): string {+ return $exportNodeToMarkdown(transformers, node, shouldPreserveNewLines);+}++function $exportNodeToMarkdown(+ transformers: LexicalTransformer[],+ node?: ElementNode | null,+ shouldPreserveNewLines: boolean = true,+): string {+ const byType = transformersByType(transformers);+ const isNewlineDelimited = !byType.multilineElement.length;++ const textFormatTransformers = byType.textFormat+ .filter((t) => t.format.length === 1)+ .sort(+ (a, b) =>+ Number(a.format.includes('code')) - Number(b.format.includes('code')),+ );++ const textMatchTransformers = byType.textMatch;+ const elementTransformers = [...byType.element, ...byType.multilineElement];++ const output: string[] = [];+ const target = node || $getRoot();++ if (+ target &&+ (!$isRootOrShadowRoot(target) || target.getType() === 'table')+ ) {+ const result = exportTopLevelElements(+ target,+ elementTransformers,+ textFormatTransformers,+ textMatchTransformers,+ shouldPreserveNewLines,+ );+ if (result !== null) output.push(result);+ } else {+ const children = target.getChildren();+ for (let i = 0; i < children.length; i++) {+ const child = children[i];+ const result = exportTopLevelElements(+ child,+ elementTransformers,+ textFormatTransformers,+ textMatchTransformers,+ shouldPreserveNewLines,+ );+ if (result !== null) {+ output.push(+ isNewlineDelimited &&+ i > 0 &&+ !isEmptyParagraph(child) &&+ !isEmptyParagraph(children[i - 1])+ ? '\n' + result+ : result,+ );+ }+ }+ }++ return output.join(shouldPreserveNewLines ? '\n' : '\n\n');+}++function exportTopLevelElements(+ node: LexicalNode,+ elementTransformers: Array<ElementTransformer | MultilineElementTransformer>,+ textFormatTransformers: Array<TextFormatTransformer>,+ textMatchTransformers: Array<TextMatchTransformer>,+ shouldPreserveNewLines: boolean = false,+): string | null {+ for (const transformer of elementTransformers) {+ if (!transformer.export) continue;+ const result = transformer.export(node, (_node) =>+ exportChildren(+ _node,+ textFormatTransformers,+ textMatchTransformers,+ undefined,+ undefined,+ shouldPreserveNewLines,+ elementTransformers,+ ),+ );+ if (result != null) return result;+ }++ if ($isElementNode(node)) {+ return exportChildren(+ node,+ textFormatTransformers,+ textMatchTransformers,+ undefined,+ undefined,+ shouldPreserveNewLines,+ elementTransformers,+ );+ } else if ($isDecoratorNode(node)) {+ return node.getTextContent();+ }+ return null;+}++function exportChildren(+ node: ElementNode,+ textFormatTransformers: Array<TextFormatTransformer>,+ textMatchTransformers: Array<TextMatchTransformer>,+ textContent?: string,+ textTransformer?: TextFormatTransformer | null,+ shouldPreserveNewLines: boolean = false,+ elementTransformers?: Array<ElementTransformer | MultilineElementTransformer>,+ unclosedTags?: Array<UnclosedFormatTag>,+ unclosableTags?: Array<UnclosedFormatTag>,+): string {+ const output: string[] = [];+ const children = node.getChildren();+ const activeUnclosedTags = unclosedTags ?? [];+ const activeUnclosableTags = unclosableTags ?? [];++ for (const child of children) {+ if ($isLineBreakNode(child)) {+ if (shouldPreserveNewLines) output.push('\n');+ } else if ($isTextNode(child)) {+ const textContentForTransform = textContent || child.getTextContent();++ if (textTransformer) {+ output.push(textContentForTransform);+ } else {+ const hasFormatting = child.getFormat() !== 0;+ let handled = false;++ if (hasFormatting) {+ output.push(+ exportTextFormat(+ child,+ textContentForTransform,+ textFormatTransformers,+ activeUnclosedTags,+ activeUnclosableTags,+ shouldPreserveNewLines,+ ),+ );+ handled = true;+ } else {+ for (const transformer of textMatchTransformers) {+ if (!transformer.export) continue;+ const result = transformer.export(+ child,+ (_node: ElementNode, textContent?: string) =>+ exportChildren(+ _node,+ textFormatTransformers,+ textMatchTransformers,+ textContent,+ textTransformer,+ shouldPreserveNewLines,+ elementTransformers,+ activeUnclosedTags,+ [...activeUnclosableTags, ...activeUnclosedTags],+ ),+ (node: TextNode, textContent: string) =>+ exportTextFormat(+ node,+ textContent,+ textFormatTransformers,+ activeUnclosedTags,+ activeUnclosableTags,+ shouldPreserveNewLines,+ ),+ );+ if (result != null) {+ output.push(result);+ handled = true;+ break;+ }+ }+ }++ if (!handled) output.push(textContentForTransform);+ }+ } else if ($isElementNode(child)) {+ let handled = false;+ for (const transformer of textMatchTransformers) {+ if (!transformer.export) continue;+ const result = transformer.export(+ child,+ (_node: ElementNode) =>+ exportChildren(+ _node,+ textFormatTransformers,+ textMatchTransformers,+ undefined,+ undefined,+ shouldPreserveNewLines,+ elementTransformers,+ activeUnclosedTags,+ [...activeUnclosableTags, ...activeUnclosedTags],+ ),+ (node: TextNode, textContent: string) =>+ exportTextFormat(+ node,+ textContent,+ textFormatTransformers,+ activeUnclosedTags,+ activeUnclosableTags,+ shouldPreserveNewLines,+ ),+ );+ if (result != null) {+ output.push(result);+ handled = true;+ break;+ }+ }+ if (!handled) {+ const result = exportTopLevelElements(+ child,+ elementTransformers || [],+ textFormatTransformers,+ textMatchTransformers,+ shouldPreserveNewLines,+ );+ if (result != null) output.push(result);+ }+ } else if ($isDecoratorNode(child)) {+ let handled = false;+ for (const transformer of textMatchTransformers) {+ if (!transformer.export) continue;+ const result = transformer.export(+ child,+ (_node: ElementNode) =>+ exportChildren(+ _node,+ textFormatTransformers,+ textMatchTransformers,+ undefined,+ undefined,+ shouldPreserveNewLines,+ elementTransformers,+ activeUnclosedTags,+ [...activeUnclosableTags, ...activeUnclosedTags],+ ),+ (node: TextNode, textContent: string) =>+ exportTextFormat(+ node,+ textContent,+ textFormatTransformers,+ activeUnclosedTags,+ activeUnclosableTags,+ shouldPreserveNewLines,+ ),+ );+ if (result != null) {+ output.push(result);+ handled = true;+ break;+ }+ }+ if (!handled && elementTransformers) {+ for (const transformer of elementTransformers) {+ const result = transformer.export?.(child, () => '');+ if (result != null) {+ output.push(result);+ handled = true;+ break;+ }+ }+ }+ if (!handled) output.push(child.getTextContent());+ }+ }+ return output.join('');+}++function exportTextFormat(+ node: TextNode,+ textContent: string,+ textTransformers: Array<TextFormatTransformer>,+ unclosedTags: Array<UnclosedFormatTag>,+ unclosableTags: Array<UnclosedFormatTag>,+ shouldPreserveNewLines: boolean = false,+): string {+ let output = textContent;++ if (!node.hasFormat('code')) {+ if (shouldPreserveNewLines) {+ // Use HTML NCR for * and _ instead of backslash escapes (round-trip safe)+ output = output+ .replace(/\*/g, '*')+ .replace(/_/g, '_')+ .replace(/([`~])/g, '\\$1');+ } else {+ output = output.replace(/([*_`~\\])/g, '\\$1');+ }+ }++ const match = output.match(/^(\s*)(.*?)(\s*)$/s) || ['', '', output, ''];+ const leadingSpace = match[1];+ const trimmedOutput = match[2];+ const trailingSpace = match[3];+ const isWhitespaceOnly = trimmedOutput === '';++ let openingTags = '';+ let closingTagsBefore = '';+ let closingTagsAfter = '';+ const previousTextNode = getTextSibling(node, true);+ const nextTextNode = getTextSibling(node, false);+ const appliedFormats = new Set<TextFormatType>();++ for (const transformer of textTransformers) {+ const format = transformer.format[0];+ const tag = transformer.tag;+ if (hasTextFormat(node, format) && !appliedFormats.has(format)) {+ appliedFormats.add(format);+ if (+ !hasTextFormat(previousTextNode, format) ||+ !unclosedTags.find((entry) => entry.tag === tag)+ ) {+ unclosedTags.push({ format, tag });+ openingTags += tag;+ }+ }+ }++ for (let i = 0; i < unclosedTags.length; i++) {+ const currentTag = unclosedTags[i];+ const nodeHasFormat = hasTextFormat(node, currentTag.format);+ const nextNodeHasFormat = hasTextFormat(nextTextNode, currentTag.format);++ if (nodeHasFormat && nextNodeHasFormat) continue;++ const remainingTags = [...unclosedTags];+ while (remainingTags.length > i) {+ const tagToClose = remainingTags.pop();+ if (+ tagToClose &&+ unclosableTags.find((entry) => entry.tag === tagToClose.tag)+ )+ continue;+ if (tagToClose) {+ if (!nodeHasFormat) closingTagsBefore += tagToClose.tag;+ else if (!nextNodeHasFormat) closingTagsAfter += tagToClose.tag;+ }+ unclosedTags.pop();+ }+ break;+ }++ if (isWhitespaceOnly && !node.hasFormat('code')) {+ return closingTagsBefore + output;+ }++ return (+ closingTagsBefore ++ leadingSpace ++ openingTags ++ trimmedOutput ++ closingTagsAfter ++ trailingSpace+ );+}++function isEmptyParagraph(node: LexicalNode): boolean {+ if (!$isElementNode(node)) return false;+ const children = node.getChildren();+ if (children.length === 0) return true;+ if (children.length === 1) {+ const child = children[0];+ if ($isTextNode(child) && child.getTextContent().trim() === '') return true;+ }+ return false;+}++function transformersByType(transformers: LexicalTransformer[]) {+ const byType: {+ element: Array<ElementTransformer>;+ multilineElement: Array<MultilineElementTransformer>;+ textFormat: Array<TextFormatTransformer>;+ textMatch: Array<TextMatchTransformer>;+ } = { element: [], multilineElement: [], textFormat: [], textMatch: [] };++ for (const transformer of transformers) {+ const type = transformer.type;+ if (type === 'element')+ byType.element.push(transformer as ElementTransformer);+ else if (type === 'multiline-element')+ byType.multilineElement.push(transformer as MultilineElementTransformer);+ else if (type === 'text-format')+ byType.textFormat.push(transformer as TextFormatTransformer);+ else if (type === 'text-match')+ byType.textMatch.push(transformer as TextMatchTransformer);+ }+ return byType;+}++function getTextSibling(node: TextNode, backward: boolean): TextNode | null {+ let sibling = backward ? node.getPreviousSibling() : node.getNextSibling();+ if (!sibling) {+ const parent = node.getParent();+ if (parent?.isInline())+ sibling = backward+ ? parent.getPreviousSibling()+ : parent.getNextSibling();+ }+ while (sibling) {+ if ($isElementNode(sibling)) {+ if (!sibling.isInline()) break;+ const descendant = backward+ ? sibling.getLastDescendant()+ : sibling.getFirstDescendant();+ if ($isTextNode(descendant)) return descendant;+ sibling = backward+ ? sibling.getPreviousSibling()+ : sibling.getNextSibling();+ continue;+ }+ if ($isTextNode(sibling)) return sibling;+ break;+ }+ return null;+}++function hasTextFormat(+ node: LexicalNode | null | undefined,+ format: TextFormatType,+): boolean {+ return $isTextNode(node) && node.hasFormat(format);+}diff --git a/web/src/lib/editor/markdown/enhanced-markdown-import.ts b/web/src/lib/editor/markdown/enhanced-markdown-import.tsnew file mode 100644index 0000000000..5e20247915--- /dev/null+++ b/web/src/lib/editor/markdown/enhanced-markdown-import.ts@@ -0,0 +1,166 @@+/**+ * Enhanced markdown import with CRLF normalization and tab collapse.+ * Ported from Nimbalyst.+ *+ * Uses placeholder-based approach for mermaid blocks:+ * 1. Replace ```mermaid blocks with unique placeholders in the raw text+ * 2. Standard Lexical import (placeholders become TextNodes)+ * 3. Walk tree, replace placeholder TextNodes with MermaidNode+ *+ * This preserves the original position of mermaid diagrams in the document.+ */++import { $isCodeNode } from '@lexical/code';+import type {+ ElementTransformer,+ MultilineElementTransformer,+ TextFormatTransformer,+ TextMatchTransformer,+} from '@lexical/markdown';+import { $convertFromMarkdownString } from '@lexical/markdown';+import {+ $createParagraphNode,+ $createTextNode,+ $getRoot,+ $isElementNode,+ $isTabNode,+ $isTextNode,+ type ElementNode,+ type LexicalNode,+} from 'lexical';+import { $createMermaidNode } from '../mermaid-node';+type LexicalTransformer =+ | ElementTransformer+ | MultilineElementTransformer+ | TextFormatTransformer+ | TextMatchTransformer;++export interface EnhancedImportOptions {+ preserveNewLines?: boolean;+}++// Unique placeholder prefix — must not appear in normal markdown text+const PREFIX = '%%MERMAID_PLACEHOLDER_';+const SUFFIX = '%%';++export function $convertFromEnhancedMarkdownString(+ markdown: string,+ transformers?: LexicalTransformer[],+ node?: ElementNode,+ preserveNewLines: boolean = true,+): void {+ if (!markdown) {+ const root = node ?? $getRoot();+ root.append($createParagraphNode());+ return;+ }++ const root = node ?? $getRoot();++ // Step 1: Normalize line endings+ const normalizedMarkdown = markdown+ .replace(/\r\n/g, '\n')+ .replace(/\r/g, '\n');++ // Step 2: Replace ```mermaid ... ``` blocks with unique placeholders+ // Matches both ```mermaid and ``` mermaid (with optional space after backticks)+ const MERMAID_REGEX = /```\s*mermaid\s*\n([\s\S]*?)```/g;+ const mermaidContent: string[] = [];+ let placeholderIdx = 0;+ const markdownWithPlaceholders = normalizedMarkdown.replace(+ MERMAID_REGEX,+ (_match, content) => {+ mermaidContent.push(content.trim());+ const ph = `${PREFIX}${placeholderIdx}${SUFFIX}`;+ placeholderIdx++;+ return ph;+ },+ );++ // Step 3: Standard Lexical import (placeholders are just text)+ $convertFromMarkdownString(+ markdownWithPlaceholders,+ transformers || [],+ root,+ preserveNewLines,+ );++ // Step 4: Walk tree and replace placeholder TextNodes with MermaidNode+ $replacePlaceholders(root, mermaidContent);++ // Step 5: Fallback — also handle CodeNode(language='mermaid') if any+ $replaceMermaidCodeNodes(root);++ // Step 6: Collapse TabNodes+ $collapseTabNodes(root);+}++/**+ * Walks the subtree and replaces TextNodes containing %%MERMAID_PLACEHOLDER_N%%+ * with MermaidNode containing the corresponding content.+ */+function $replacePlaceholders(+ root: ElementNode,+ mermaidContent: string[],+): void {+ const visit = (node: LexicalNode): void => {+ if ($isTextNode(node)) {+ const text = node.getTextContent();+ if (text.startsWith(PREFIX)) {+ const idxStr = text.slice(PREFIX.length, -SUFFIX.length);+ const idx = parseInt(idxStr, 10);+ if (!isNaN(idx) && idx >= 0 && idx < mermaidContent.length) {+ const content = mermaidContent[idx];+ if (content) {+ const mermaidNode = $createMermaidNode({ content });+ node.replace(mermaidNode);+ return;+ }+ }+ }+ }+ if ($isElementNode(node)) {+ // Walk children in reverse to maintain indices during mutation+ const children = node.getChildren();+ for (let i = children.length - 1; i >= 0; i--) {+ visit(children[i]);+ }+ }+ };+ visit(root);+}++/**+ * Fallback: replaces CodeNode(language='mermaid') with MermaidNode.+ */+function $replaceMermaidCodeNodes(root: ElementNode): void {+ const visit = (node: LexicalNode): void => {+ if ($isCodeNode(node) && node.getLanguage() === 'mermaid') {+ const text = node.getTextContent();+ const mermaidNode = $createMermaidNode({ content: text });+ node.replace(mermaidNode);+ return;+ }+ if ($isElementNode(node)) {+ for (const child of node.getChildren()) {+ visit(child);+ }+ }+ };+ visit(root);+}++function $collapseTabNodes(root: ElementNode): void {+ const visit = (node: LexicalNode): void => {+ if ($isTabNode(node)) {+ node.replace($createTextNode('\t'));+ return;+ }+ if ($isElementNode(node)) {+ for (const child of node.getChildren()) {+ visit(child);+ }+ }+ };+ visit(root);+}diff --git a/web/src/lib/editor/markdown/horizontal-rule-node.ts b/web/src/lib/editor/markdown/horizontal-rule-node.tsnew file mode 100644index 0000000000..1975ccd74e--- /dev/null+++ b/web/src/lib/editor/markdown/horizontal-rule-node.ts@@ -0,0 +1,85 @@+/**+ * Custom HorizontalRuleNode for Lexical.+ * Uses ElementNode (no decorative rendering needed).+ */++import {+ $applyNodeReplacement,+ ElementNode,+ type EditorConfig,+ type ElementFormatType,+ type LexicalNode,+ type SerializedLexicalNode,+ type Spread,+} from 'lexical';++export type SerializedHorizontalRuleNode = Spread<+ {+ children: [];+ direction: 'ltr' | 'rtl' | null;+ format: ElementFormatType;+ indent: number;+ },+ SerializedLexicalNode+>;++export class HorizontalRuleNode extends ElementNode {+ static getType(): string {+ return 'horizontalrule';+ }++ static clone(node: HorizontalRuleNode): HorizontalRuleNode {+ return new HorizontalRuleNode(node.__key);+ }++ /* eslint-disable @typescript-eslint/no-unused-vars */+ static importJSON(+ _serializedNode: SerializedHorizontalRuleNode,+ ): HorizontalRuleNode {+ return $createHorizontalRuleNode();+ }+ /* eslint-enable @typescript-eslint/no-unused-vars */++ exportJSON(): SerializedHorizontalRuleNode {+ return {+ children: [],+ direction: 'ltr',+ format: '',+ indent: 0,+ type: 'horizontalrule',+ version: 1,+ };+ }++ // eslint-disable-next-line @typescript-eslint/no-unused-vars+ createDOM(_config: EditorConfig, _editor: any): HTMLElement {+ const element = document.createElement('hr');+ return element;+ }++ updateDOM(): boolean {+ return false;+ }++ getTextContent(): string {+ return '\n';+ }++ isInline(): boolean {+ return false;+ }++ canBeEmpty(): boolean {+ return true;+ }+}++export function $createHorizontalRuleNode(): HorizontalRuleNode {+ return $applyNodeReplacement(new HorizontalRuleNode());+}++export function $isHorizontalRuleNode(+ node: LexicalNode | null | undefined,+): node is HorizontalRuleNode {+ return node instanceof HorizontalRuleNode;+}diff --git a/web/src/lib/editor/markdown/horizontal-rule-transformer.ts b/web/src/lib/editor/markdown/horizontal-rule-transformer.tsnew file mode 100644index 0000000000..9971371d41--- /dev/null+++ b/web/src/lib/editor/markdown/horizontal-rule-transformer.ts@@ -0,0 +1,31 @@+/**+ * Horizontal Rule transformer for markdown import/export+ * Uses a custom inline node type to represent horizontal rules in Lexical.+ */++import { type ElementTransformer } from '@lexical/markdown';+import { type LexicalNode } from 'lexical';++import {+ $createHorizontalRuleNode,+ $isHorizontalRuleNode,+ HorizontalRuleNode,+} from './horizontal-rule-node';++export const HR_TRANSFORMER: ElementTransformer = {+ dependencies: [HorizontalRuleNode],+ export: (node: LexicalNode) => {+ return $isHorizontalRuleNode(node) ? '---' : null;+ },+ regExp: /^(---|\*\*\*|___)\s?$/,+ replace: (parentNode, _1, _2, isImport) => {+ const line = $createHorizontalRuleNode();+ if (isImport || parentNode.getNextSibling() != null) {+ parentNode.replace(line);+ } else {+ parentNode.insertBefore(line);+ }+ line.selectNext();+ },+ type: 'element',+};diff --git a/web/src/lib/editor/markdown/index.ts b/web/src/lib/editor/markdown/index.tsnew file mode 100644index 0000000000..ec8a73acdd--- /dev/null+++ b/web/src/lib/editor/markdown/index.ts@@ -0,0 +1,75 @@+/**+ * Public API for the markdown pipeline.+ */++import { CORE_TRANSFORMERS } from './markdown-transformers';++import type { LexicalTransformer } from './enhanced-markdown-export';++export { $convertFromEnhancedMarkdownString } from './enhanced-markdown-import';+export type { EnhancedImportOptions } from './enhanced-markdown-import';++export {+ $convertNodeToEnhancedMarkdownString,+ $convertToEnhancedMarkdownString,+} from './enhanced-markdown-export';+export type {+ EnhancedExportOptions,+ LexicalTransformer,+} from './enhanced-markdown-export';++export {+ BOLD_ITALIC_STAR,+ BOLD_ITALIC_UNDERSCORE,+ BOLD_STAR,+ BOLD_UNDERSCORE,+ CHECK_LIST,+ CODE,+ CORE_TRANSFORMERS,+ ELEMENT_TRANSFORMERS,+ getListConfig,+ getMarkdownConfig,+ HEADING,+ HIGHLIGHT,+ INLINE_CODE,+ ITALIC_STAR,+ ITALIC_UNDERSCORE,+ LINK,+ MERMAID_TRANSFORMER,+ MULTILINE_ELEMENT_TRANSFORMERS,+ ORDERED_LIST,+ QUOTE,+ setListConfig,+ setMarkdownConfig,+ STRIKETHROUGH,+ TABLE_TRANSFORMER,+ TEXT_FORMAT_TRANSFORMERS,+ TEXT_MATCH_TRANSFORMERS,+ UNORDERED_LIST,+} from './markdown-transformers';+export type { ListConfig, MarkdownConfig } from './markdown-transformers';++// Re-export types from @lexical/markdown+export type {+ ElementTransformer,+ MultilineElementTransformer,+ TextFormatTransformer,+ TextMatchTransformer,+ Transformer,+} from '@lexical/markdown';++export {+ $createHorizontalRuleNode,+ $isHorizontalRuleNode,+ HorizontalRuleNode,+} from './horizontal-rule-node';+export type { SerializedHorizontalRuleNode } from './horizontal-rule-node';++/**+ * Returns the core set of transformers used for markdown import/export.+ * This function is used by plugins (e.g., TableTransformer) that need to+ * perform markdown conversion inside their own logic.+ */+export function getEditorTransformers(): LexicalTransformer[] {+ return CORE_TRANSFORMERS as LexicalTransformer[];+}diff --git a/web/src/lib/editor/markdown/list-transformers.ts b/web/src/lib/editor/markdown/list-transformers.tsnew file mode 100644index 0000000000..139607719e--- /dev/null+++ b/web/src/lib/editor/markdown/list-transformers.ts@@ -0,0 +1,175 @@+/**+ * List transformers for markdown import/export.+ * Ported from Nimbalyst with minimal dependencies.+ */++import type { ListType } from '@lexical/list';+import {+ $createListItemNode,+ $createListNode,+ $isListItemNode,+ $isListNode,+ ListItemNode,+ ListNode,+} from '@lexical/list';+import type { ElementTransformer } from '@lexical/markdown';+import type { ElementNode, LexicalNode } from 'lexical';++export const ORDERED_LIST_REGEX = /^(\s*)(\d{1,})\.\s/;+export const UNORDERED_LIST_REGEX = /^(\s*)[-*+]\s/;+export const CHECK_LIST_REGEX = /^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i;++export interface ListConfig {+ exportIndentSize?: number;+ importMinIndentSize?: number;+ importMaxIndentSize?: number;+ autoDetectIndent?: boolean;+}++const DEFAULT_LIST_CONFIG: ListConfig = {+ exportIndentSize: 2,+ importMinIndentSize: 2,+ importMaxIndentSize: 4,+ autoDetectIndent: true,+};++let globalListConfig: ListConfig = { ...DEFAULT_LIST_CONFIG };++export function setListConfig(config: Partial<ListConfig>): void {+ globalListConfig = { ...DEFAULT_LIST_CONFIG, ...config };+}++export function getListConfig(): ListConfig {+ return { ...globalListConfig };+}++export function getIndentLevel(+ whitespaces: string,+ isImport: boolean = true,+): number {+ const tabs = whitespaces.match(/\t/g);+ const spaces = whitespaces.match(/ /g);+ let indent = 0;+ if (tabs) indent += tabs.length;+ if (spaces) {+ const spaceCount = spaces.length;+ const config = getListConfig();+ if (isImport) {+ const importSize = config.importMinIndentSize ?? 2;+ indent += Math.floor(spaceCount / importSize);+ } else {+ const exportSize = config.exportIndentSize ?? 2;+ indent += Math.floor(spaceCount / exportSize);+ }+ }+ return indent;+}++export function createListReplace(+ listType: ListType,+): ElementTransformer['replace'] {+ return (parentNode, children, match, isImport) => {+ const previousNode = parentNode.getPreviousSibling();+ const nextNode = parentNode.getNextSibling();+ const listItem = $createListItemNode(+ listType === 'check' ? match[3] === 'x' : undefined,+ );+ const indent = getIndentLevel(match[1], true);++ if ($isListNode(nextNode) && nextNode.getListType() === listType) {+ const firstChild = nextNode.getFirstChild();+ if (firstChild !== null) firstChild.insertBefore(listItem);+ else nextNode.append(listItem);+ parentNode.remove();+ } else if (+ $isListNode(previousNode) &&+ previousNode.getListType() === listType+ ) {+ previousNode.append(listItem);+ parentNode.remove();+ } else {+ const list = $createListNode(+ listType,+ listType === 'number' ? Number(match[2]) : undefined,+ );+ list.append(listItem);+ parentNode.replace(list);+ }++ listItem.append(...children);+ if (!isImport) listItem.select(0, 0);+ if (indent > 0) listItem.setIndent(indent);+ };+}++export function listExport(+ listNode: ListNode,+ exportChildren: (node: ElementNode) => string,+ depth: number = 0,+ config?: ListConfig,+): string {+ const mergedConfig = { ...globalListConfig, ...config };+ const indentSize = mergedConfig.exportIndentSize ?? 2;+ const output: string[] = [];+ const children = listNode.getChildren();+ let index = 0;++ for (const listItemNode of children) {+ if (!$isListItemNode(listItemNode)) continue;++ if (listItemNode.getChildrenSize() === 1) {+ const firstChild = listItemNode.getFirstChild();+ if ($isListNode(firstChild)) {+ output.push(listExport(firstChild, exportChildren, depth + 1, config));+ continue;+ }+ }++ const itemIndent = listItemNode.getIndent();+ const actualDepth = itemIndent !== undefined ? itemIndent : depth;+ const indent = ' '.repeat(actualDepth * indentSize);+ const listType = listNode.getListType();+ const prefix =+ listType === 'number'+ ? `${listNode.getStart() + index}. `+ : listType === 'check'+ ? `- [${listItemNode.getChecked() ? 'x' : ' '}] `+ : '- ';++ output.push(indent + prefix + exportChildren(listItemNode));+ index++;+ }+ return output.join('\n');+}++export function createListTransformer(+ listType: ListType,+ regex: RegExp,+): ElementTransformer {+ return {+ dependencies: [ListNode, ListItemNode],+ export: (+ node: LexicalNode,+ exportChildren: (node: ElementNode) => string,+ ) => {+ if (!$isListNode(node)) return null;+ return listExport(node, exportChildren, 0, getListConfig());+ },+ regExp: regex,+ replace: createListReplace(listType),+ type: 'element',+ };+}++export const UNORDERED_LIST: ElementTransformer = createListTransformer(+ 'bullet',+ UNORDERED_LIST_REGEX,+);+export const ORDERED_LIST: ElementTransformer = createListTransformer(+ 'number',+ ORDERED_LIST_REGEX,+);+export const CHECK_LIST: ElementTransformer = createListTransformer(+ 'check',+ CHECK_LIST_REGEX,+);diff --git a/web/src/lib/editor/markdown/markdown-transformers.ts b/web/src/lib/editor/markdown/markdown-transformers.tsnew file mode 100644index 0000000000..81d0d05ff0--- /dev/null+++ b/web/src/lib/editor/markdown/markdown-transformers.ts@@ -0,0 +1,308 @@+/**+ * Markdown transformers for Lexical import/export.+ * Ported from Nimbalyst — handles:+ * - HEADING, QUOTE, CODE, MERMAID+ * - LISTS (via ListTransformers)+ * - Text format (bold, italic, strikethrough, code, highlight)+ * - LINK, HR+ */++/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-object-type, no-useless-escape */++import { $createCodeNode, $isCodeNode, CodeNode } from '@lexical/code';+import {+ $createLinkNode,+ $isAutoLinkNode,+ $isLinkNode,+ LinkNode,+} from '@lexical/link';+import {+ BOLD_ITALIC_STAR as UPSTREAM_BOLD_ITALIC_STAR,+ BOLD_ITALIC_UNDERSCORE as UPSTREAM_BOLD_ITALIC_UNDERSCORE,+ BOLD_STAR as UPSTREAM_BOLD_STAR,+ BOLD_UNDERSCORE as UPSTREAM_BOLD_UNDERSCORE,+ HIGHLIGHT as UPSTREAM_HIGHLIGHT,+ INLINE_CODE as UPSTREAM_INLINE_CODE,+ ITALIC_STAR as UPSTREAM_ITALIC_STAR,+ ITALIC_UNDERSCORE as UPSTREAM_ITALIC_UNDERSCORE,+ STRIKETHROUGH as UPSTREAM_STRIKETHROUGH,+} from '@lexical/markdown';+import type { HeadingTagType } from '@lexical/rich-text';+import {+ $createHeadingNode,+ $createQuoteNode,+ $isHeadingNode,+ $isQuoteNode,+ HeadingNode,+ QuoteNode,+} from '@lexical/rich-text';+import {+ $createLineBreakNode,+ $createTextNode,+ type ElementNode,+ type LexicalNode,+} from 'lexical';++import type {+ ElementTransformer,+ MultilineElementTransformer,+ TextFormatTransformer,+ TextMatchTransformer,+ Transformer,+} from '@lexical/markdown';++import {+ CHECK_LIST,+ getListConfig,+ ORDERED_LIST,+ setListConfig,+ UNORDERED_LIST,+ type ListConfig,+} from './list-transformers';++export {+ CHECK_LIST,+ getListConfig,+ ORDERED_LIST,+ setListConfig,+ UNORDERED_LIST,+ type ListConfig,+};++import { MERMAID_TRANSFORMER } from '../mermaid-transformer';+import { TABLE_TRANSFORMER } from '../plugins/table-transformer';+import { HR_TRANSFORMER } from './horizontal-rule-transformer';++const HEADING_REGEX = /^(#{1,6})\s/;+const QUOTE_REGEX = /^>\s/;+const CODE_START_REGEX = /^[ \t]*```([\w-]+)?/;+const CODE_END_REGEX = /[ \t]*```$/;++const createBlockNode = (+ createNode: (match: Array<string>) => ElementNode,+): ElementTransformer['replace'] => {+ return (parentNode, children, match, isImport) => {+ const node = createNode(match);+ node.append(...children);+ parentNode.replace(node);+ if (!isImport) node.select(0, 0);+ };+};++export interface MarkdownConfig {}++export function setMarkdownConfig(+ config: Partial<MarkdownConfig & ListConfig>,+): void {+ if (+ 'exportIndentSize' in config ||+ 'importMinIndentSize' in config ||+ 'importMaxIndentSize' in config ||+ 'autoDetectIndent' in config+ ) {+ setListConfig(config);+ }+}++export function getMarkdownConfig(): MarkdownConfig & ListConfig {+ return { ...getListConfig() };+}++export const HEADING: ElementTransformer = {+ dependencies: [HeadingNode],+ export: (node, exportChildren) => {+ if (!$isHeadingNode(node)) return null;+ const level = Number(node.getTag().slice(1));+ return '#'.repeat(level) + ' ' + exportChildren(node);+ },+ regExp: HEADING_REGEX,+ replace: createBlockNode((match) => {+ const tag = ('h' + match[1].length) as HeadingTagType;+ return $createHeadingNode(tag);+ }),+ type: 'element',+};++export const QUOTE: ElementTransformer = {+ dependencies: [QuoteNode],+ export: (node, exportChildren) => {+ if (!$isQuoteNode(node)) return null;+ const lines = exportChildren(node).split('\n');+ return lines.map((line) => '> ' + line).join('\n');+ },+ regExp: QUOTE_REGEX,+ replace: (parentNode, children, _match, isImport) => {+ if (isImport) {+ const previousNode = parentNode.getPreviousSibling();+ if ($isQuoteNode(previousNode)) {+ previousNode.splice(previousNode.getChildrenSize(), 0, [+ $createLineBreakNode(),+ ...children,+ ]);+ parentNode.remove();+ return;+ }+ }+ const node = $createQuoteNode();+ node.append(...children);+ parentNode.replace(node);+ if (!isImport) node.select(0, 0);+ },+ type: 'element',+};++const NO_LANGUAGE_MARKER = 'plain';++export const CODE: MultilineElementTransformer = {+ dependencies: [CodeNode],+ export: (node: LexicalNode) => {+ if (!$isCodeNode(node)) return null;+ const textContent = node.getTextContent();+ const language = node.getLanguage();+ const langOutput = language === NO_LANGUAGE_MARKER ? '' : language || '';+ return (+ '```' ++ langOutput ++ (textContent ? '\n' + textContent : '') ++ '\n' ++ '```'+ );+ },+ regExpEnd: { optional: true, regExp: CODE_END_REGEX },+ regExpStart: CODE_START_REGEX,+ replace: (+ rootNode,+ children,+ startMatch,+ endMatch,+ linesInBetween,+ isImport,+ ) => {+ let codeBlockNode: CodeNode;+ let code: string;++ if (!children && linesInBetween) {+ if (linesInBetween.length === 1) {+ if (endMatch) {+ codeBlockNode = $createCodeNode(NO_LANGUAGE_MARKER);+ code = startMatch[1] + linesInBetween[0];+ } else {+ codeBlockNode = $createCodeNode(startMatch[1] || NO_LANGUAGE_MARKER);+ code = linesInBetween[0].startsWith(' ')+ ? linesInBetween[0].slice(1)+ : linesInBetween[0];+ }+ } else {+ codeBlockNode = $createCodeNode(startMatch[1] || NO_LANGUAGE_MARKER);+ if (linesInBetween[0].trim().length === 0) {+ while (linesInBetween.length > 0 && !linesInBetween[0].length)+ linesInBetween.shift();+ } else {+ linesInBetween[0] = linesInBetween[0].startsWith(' ')+ ? linesInBetween[0].slice(1)+ : linesInBetween[0];+ }+ while (+ linesInBetween.length > 0 &&+ !linesInBetween[linesInBetween.length - 1].length+ )+ linesInBetween.pop();+ code = linesInBetween.join('\n');+ }+ const textNode = $createTextNode(code);+ codeBlockNode.append(textNode);+ rootNode.append(codeBlockNode);+ } else if (children) {+ createBlockNode((match) => {+ return $createCodeNode(+ match && match[1] ? match[1] : NO_LANGUAGE_MARKER,+ );+ })(rootNode, children, startMatch, isImport);+ }+ },+ type: 'multiline-element',+};++// Re-export upstream text-format transformers+export const INLINE_CODE: TextFormatTransformer = UPSTREAM_INLINE_CODE;+export const HIGHLIGHT: TextFormatTransformer = UPSTREAM_HIGHLIGHT;+export const BOLD_ITALIC_STAR: TextFormatTransformer =+ UPSTREAM_BOLD_ITALIC_STAR;+export const BOLD_ITALIC_UNDERSCORE: TextFormatTransformer =+ UPSTREAM_BOLD_ITALIC_UNDERSCORE;+export const BOLD_STAR: TextFormatTransformer = UPSTREAM_BOLD_STAR;+export const BOLD_UNDERSCORE: TextFormatTransformer = UPSTREAM_BOLD_UNDERSCORE;+export const STRIKETHROUGH: TextFormatTransformer = UPSTREAM_STRIKETHROUGH;+export const ITALIC_STAR: TextFormatTransformer = UPSTREAM_ITALIC_STAR;+export const ITALIC_UNDERSCORE: TextFormatTransformer =+ UPSTREAM_ITALIC_UNDERSCORE;++export const LINK: TextMatchTransformer = {+ dependencies: [LinkNode],+ export: (node, exportChildren, _exportFormat) => {+ if (!$isLinkNode(node) || $isAutoLinkNode(node)) return null;+ const title = node.getTitle();+ const textContent = exportChildren(node);+ return title+ ? `[${textContent}](${node.getURL()} "${title}")`+ : `[${textContent}](${node.getURL()})`;+ },+ importRegExp:+ /(?<!!)(?:\[(?!!\[)([^\]]+)\])(?:\(([^\s\)]+)(?:\s+"([^"]*)")?\))/,+ regExp: /(?<!!)(?:\[(?!!\[)([^\]]+)\])(?:\(([^\s\)]+)(?:\s+"([^"]*)")?\))$/,+ replace: (textNode, match) => {+ const [, linkText, rawUrl, linkTitle] = match;+ const linkUrl =+ rawUrl && rawUrl.startsWith('<') && rawUrl.endsWith('>')+ ? rawUrl.slice(1, -1)+ : rawUrl;+ const linkNode = $createLinkNode(linkUrl, { title: linkTitle });+ const linkTextNode = $createTextNode(linkText);+ linkTextNode.setFormat(textNode.getFormat());+ linkNode.append(linkTextNode);+ textNode.replace(linkNode);+ return linkTextNode;+ },+ trigger: ')',+ type: 'text-match',+};++// Aggregated core transformer arrays+export const ELEMENT_TRANSFORMERS: Transformer[] = [+ HEADING,+ QUOTE,+ UNORDERED_LIST,+ ORDERED_LIST,+ TABLE_TRANSFORMER,+];++// MERMAID must come BEFORE CODE to intercept ```mermaid blocks first+export const MULTILINE_ELEMENT_TRANSFORMERS: Transformer[] = [+ MERMAID_TRANSFORMER,+ CODE,+];++export const TEXT_FORMAT_TRANSFORMERS: Transformer[] = [+ INLINE_CODE,+ BOLD_ITALIC_STAR,+ BOLD_ITALIC_UNDERSCORE,+ BOLD_STAR,+ BOLD_UNDERSCORE,+ HIGHLIGHT,+ ITALIC_STAR,+ ITALIC_UNDERSCORE,+ STRIKETHROUGH,+];+export const TEXT_MATCH_TRANSFORMERS: Transformer[] = [LINK];++export const CORE_TRANSFORMERS: Transformer[] = [+ HR_TRANSFORMER,+ CHECK_LIST,+ ...ELEMENT_TRANSFORMERS,+ ...MULTILINE_ELEMENT_TRANSFORMERS,+ ...TEXT_FORMAT_TRANSFORMERS,+ ...TEXT_MATCH_TRANSFORMERS,+];++export { MERMAID_TRANSFORMER } from '../mermaid-transformer';+export { TABLE_TRANSFORMER } from '../plugins/table-transformer';diff --git a/web/src/lib/editor/mermaid-node.tsx b/web/src/lib/editor/mermaid-node.tsxnew file mode 100644index 0000000000..d554723fbc--- /dev/null+++ b/web/src/lib/editor/mermaid-node.tsx@@ -0,0 +1,428 @@+/**+ * MermaidNode - A Lexical DecoratorNode for rendering Mermaid diagrams.+ * Ported from Nimbalyst — supports click-to-edit source code.+ */++/* eslint-disable @typescript-eslint/no-unused-vars */++import { addClassNamesToElement } from '@lexical/utils';+import type {+ DOMConversionMap,+ DOMConversionOutput,+ DOMExportOutput,+ EditorConfig,+ LexicalEditor,+ LexicalNode,+ NodeKey,+ SerializedLexicalNode,+ Spread,+} from 'lexical';+import { $applyNodeReplacement, DecoratorNode } from 'lexical';+import type { JSX } from 'react';++export interface MermaidPayload {+ content: string;+ key?: NodeKey;+}++export type SerializedMermaidNode = Spread<+ { content: string },+ SerializedLexicalNode+>;++export class MermaidNode extends DecoratorNode<JSX.Element> {+ __content: string;++ constructor(content: string, key?: NodeKey) {+ super(key);+ this.__content = content;+ }++ static getType(): string {+ return 'mermaid';+ }++ static clone(node: MermaidNode): MermaidNode {+ return new MermaidNode(node.__content, node.__key);+ }++ static importJSON(serializedNode: SerializedMermaidNode): MermaidNode {+ return $createMermaidNode({ content: serializedNode.content });+ }++ exportJSON(): SerializedMermaidNode {+ return {+ content: this.__content,+ type: 'mermaid',+ version: 1,+ };+ }++ createDOM(_config: EditorConfig, _editor: LexicalEditor): HTMLElement {+ const div = document.createElement('div');+ addClassNamesToElement(div, 'mermaid-container');+ return div;+ }++ updateDOM(_prevNode: MermaidNode, _dom: HTMLElement): boolean {+ return _prevNode.__content !== this.__content;+ }++ exportDOM(_editor: LexicalEditor): DOMExportOutput {+ const element = document.createElement('div');+ element.classList.add('mermaid-container');+ const pre = document.createElement('pre');+ const code = document.createElement('code');+ code.classList.add('language-mermaid');+ code.textContent = this.__content;+ pre.appendChild(code);+ element.appendChild(pre);+ return { element };+ }++ static importDOM(): DOMConversionMap | null {+ return {+ div: (domNode: HTMLElement) => {+ if (!domNode.classList.contains('mermaid-container')) return null;+ return { conversion: convertMermaidElement, priority: 1 };+ },+ };+ }++ getContent(): string {+ return this.__content;+ }++ getTextContent(): string {+ return this.__content;+ }++ setContent(content: string): void {+ const writable = this.getWritable();+ writable.__content = content;+ }++ decorate(_editor: LexicalEditor, _config: EditorConfig): JSX.Element {+ return (+ <MermaidComponent+ content={this.__content}+ nodeKey={this.__key}+ editor={_editor}+ />+ );+ }+}++function convertMermaidElement(+ domNode: HTMLElement,+): DOMConversionOutput | null {+ const codeElement = domNode.querySelector('code.language-mermaid');+ if (codeElement) {+ const node = $createMermaidNode({ content: codeElement.textContent || '' });+ return { node };+ }+ return null;+}++export function $createMermaidNode(payload?: MermaidPayload): MermaidNode {+ const content = payload?.content || 'graph TD\n A[Start] --> B[End]';+ return $applyNodeReplacement(new MermaidNode(content, payload?.key));+}++export function $isMermaidNode(+ node: LexicalNode | null | undefined,+): node is MermaidNode {+ return node instanceof MermaidNode;+}++// ─── React rendering component ─────────────────────────────++import { useTheme } from '@/components/theme-provider';+import { $getNodeByKey } from 'lexical';+import mermaid from 'mermaid';+import { useCallback, useEffect, useRef, useState } from 'react';++let mermaidInitialized = false;+function ensureMermaidInit(themeName: string) {+ const mermaidTheme = themeName === 'dark' ? 'dark' : 'default';+ if (!mermaidInitialized) {+ mermaid.initialize({+ startOnLoad: false,+ theme: mermaidTheme,+ securityLevel: 'antiscript',+ fontFamily: 'monospace',+ });+ mermaidInitialized = true;+ } else {+ mermaidInitialized = false;+ mermaid.initialize({+ startOnLoad: false,+ theme: mermaidTheme,+ securityLevel: 'antiscript',+ fontFamily: 'monospace',+ });+ mermaidInitialized = true;+ }+}++// Sequential render queue — avoids freezing with many diagrams+let renderQueue = Promise.resolve();+function queueRender(fn: () => Promise<void>): void {+ renderQueue = renderQueue.then(+ () =>+ new Promise<void>((resolve) => {+ setTimeout(async () => {+ await fn();+ resolve();+ }, 30);+ }),+ );+}++interface MermaidComponentProps {+ content: string;+ nodeKey: NodeKey;+ editor: LexicalEditor;+}++function MermaidComponent({ content, nodeKey, editor }: MermaidComponentProps) {+ const containerRef = useRef<HTMLDivElement>(null);+ const textareaRef = useRef<HTMLTextAreaElement>(null);+ const [state, setState] = useState<'loading' | 'error' | 'done'>('loading');+ const [error, setError] = useState<string | null>(null);+ const [editing, setEditing] = useState(false);+ const [editContent, setEditContent] = useState(content);+ const { theme } = useTheme();++ // ── Render/re-render diagram ──+ const doRender = useCallback(+ async (source: string) => {+ if (!containerRef.current) return;+ try {+ const id = `mermaid_${nodeKey}_${Date.now()}`;+ const { svg } = await mermaid.render(id, source);+ if (containerRef.current) {+ containerRef.current.innerHTML = svg;+ setState('done');+ setError(null);+ }+ } catch (err: any) {+ setState('error');+ setError(err?.message || String(err));+ }+ },+ [nodeKey],+ );++ useEffect(() => {+ let mounted = true;+ ensureMermaidInit(theme);++ queueRender(async () => {+ if (!mounted) return;+ if (!containerRef.current) return;+ await doRender(content);+ });++ return () => {+ mounted = false;+ };+ }, [content, nodeKey, theme, doRender, editing]);++ // ── Click to edit ──+ const handleDiagramClick = () => {+ setEditContent(content);+ setEditing(true);+ };++ // ── Commit changes back to Lexical node ──+ const commitChanges = useCallback(() => {+ const newContent = editContent.trim();+ if (newContent && newContent !== content) {+ editor.update(() => {+ const node = $getNodeByKey(nodeKey);+ if ($isMermaidNode(node)) {+ node.setContent(newContent);+ }+ });+ }+ setEditing(false);+ }, [editContent, content, editor, nodeKey]);++ // ── Live preview while editing (debounced) ──+ const debounceRef = useRef<ReturnType<typeof setTimeout>>();+ const handleEditChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {+ const val = e.target.value;+ setEditContent(val);+ if (debounceRef.current) clearTimeout(debounceRef.current);+ debounceRef.current = setTimeout(async () => {+ if (val.trim()) {+ ensureMermaidInit(theme);+ await doRender(val);+ }+ }, 350);+ };++ const handleKeyDown = (e: React.KeyboardEvent) => {+ if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {+ commitChanges();+ }+ if (e.key === 'Escape') {+ setEditing(false);+ setEditContent(content);+ }+ };++ // Error state+ if (state === 'error' && !editing) {+ return (+ <div+ className="mermaid-block"+ style={{+ margin: '12px 0',+ padding: 16,+ border: '1px solid var(--nim-error)',+ borderRadius: 8,+ background: 'color-mix(in srgb, var(--nim-error) 8%, transparent)',+ cursor: 'pointer',+ }}+ onClick={handleDiagramClick}+ >+ <pre+ style={{+ margin: 0,+ fontSize: 12,+ color: 'var(--nim-error)',+ whiteSpace: 'pre-wrap',+ }}+ >+ {content}+ </pre>+ <div+ style={{ fontSize: 11, color: 'var(--nim-text-faint)', marginTop: 8 }}+ >+ {error} — click to edit source+ </div>+ </div>+ );+ }++ // Edit mode+ if (editing) {+ return (+ <div className="mermaid-block" style={{ margin: '12px 0' }}>+ <div+ ref={containerRef}+ className="mermaid-render-container"+ style={{+ overflowX: 'auto',+ minHeight: 60,+ marginBottom: 8,+ border: '1px solid var(--nim-border)',+ borderRadius: 6,+ padding: 8,+ background: 'var(--nim-bg)',+ }}+ />+ <textarea+ ref={textareaRef}+ value={editContent}+ onChange={handleEditChange}+ onKeyDown={handleKeyDown}+ onBlur={commitChanges}+ autoFocus+ style={{+ width: '100%',+ minHeight: 80,+ padding: '8px 10px',+ fontSize: 13,+ fontFamily: 'Menlo, Consolas, monospace',+ lineHeight: 1.5,+ border: '1px solid var(--nim-border-focus)',+ borderRadius: 6,+ background: 'var(--nim-code-bg)',+ color: 'var(--nim-code-text)',+ resize: 'vertical',+ outline: 'none',+ boxSizing: 'border-box',+ }}+ placeholder="Edit mermaid source..."+ />+ <div+ style={{+ fontSize: 11,+ color: 'var(--nim-text-faint)',+ marginTop: 4,+ display: 'flex',+ gap: 12,+ }}+ >+ <span>Ctrl+Enter to apply</span>+ <span>Esc to cancel</span>+ </div>+ </div>+ );+ }++ // Normal display mode with border + edit button above+ return (+ <div+ className="mermaid-block"+ style={{+ margin: '16px 0',+ border: '1px solid var(--nim-border)',+ borderRadius: 8,+ overflow: 'hidden',+ }}+ >+ <div+ style={{+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'space-between',+ padding: '4px 10px',+ background: 'var(--nim-bg-tertiary)',+ borderBottom: '1px solid var(--nim-border)',+ fontSize: 12,+ }}+ >+ <span style={{ color: 'var(--nim-text-muted)', fontWeight: 600 }}>+ mermaid+ </span>+ <button+ onClick={(e) => {+ e.stopPropagation();+ setEditContent(content);+ setEditing(true);+ }}+ style={{+ padding: '2px 8px',+ border: '1px solid var(--nim-border)',+ borderRadius: 4,+ background: 'var(--nim-bg)',+ color: 'var(--nim-text-muted)',+ cursor: 'pointer',+ fontSize: 11,+ fontFamily: 'inherit',+ }}+ >+ Edit+ </button>+ </div>+ <div+ style={{ textAlign: 'center', cursor: 'pointer', padding: 8 }}+ onClick={handleDiagramClick}+ title="Click to edit source"+ >+ <div+ ref={containerRef}+ className="mermaid-render-container"+ style={{+ overflowX: 'auto',+ minHeight: state === 'loading' ? 60 : 'auto',+ }}+ />+ </div>+ </div>+ );+}diff --git a/web/src/lib/editor/mermaid-transformer.ts b/web/src/lib/editor/mermaid-transformer.tsnew file mode 100644index 0000000000..4f97dae5c4--- /dev/null+++ b/web/src/lib/editor/mermaid-transformer.ts@@ -0,0 +1,38 @@+/**+ * MermaidTransformer - handles ```mermaid code blocks.+ * Ported from Nimbalyst. Creates MermaidNode instead of CodeNode.+ */++/* eslint-disable no-console */++import type { MultilineElementTransformer } from '@lexical/markdown';+import {+ $createMermaidNode,+ $isMermaidNode,+ MermaidNode,+} from './mermaid-node';++const MERMAID_START_REGEX = /^[ \t]*```mermaid/;+const MERMAID_END_REGEX = /[ \t]*```$/;++export const MERMAID_TRANSFORMER: MultilineElementTransformer = {+ dependencies: [MermaidNode],+ export: (node) => {+ if (!$isMermaidNode(node)) return null;+ return '```mermaid\n' + node.getContent() + '\n```';+ },+ regExpStart: MERMAID_START_REGEX,+ regExpEnd: { optional: true, regExp: MERMAID_END_REGEX },+ replace: (rootNode, _children, _startMatch, _endMatch, linesInBetween) => {+ const content = linesInBetween ? linesInBetween.join('\n').trim() : '';+ console.log(+ '[MermaidTransformer] Creating MermaidNode, content length:',+ content.length,+ 'lines:',+ linesInBetween?.length,+ );+ const mermaidNode = $createMermaidNode({ content });+ rootNode.append(mermaidNode);+ },+ type: 'multiline-element',+};diff --git a/web/src/lib/editor/nodes.ts b/web/src/lib/editor/nodes.tsnew file mode 100644index 0000000000..8e08e65e8d--- /dev/null+++ b/web/src/lib/editor/nodes.ts@@ -0,0 +1,33 @@+/**+ * Lexical nodes for the editor.+ * Each node type must be registered in the LexicalComposer config.+ */++import { CodeHighlightNode, CodeNode } from '@lexical/code';+import { HashtagNode } from '@lexical/hashtag';+import { AutoLinkNode, LinkNode } from '@lexical/link';+import { ListItemNode, ListNode } from '@lexical/list';+import { HeadingNode, QuoteNode } from '@lexical/rich-text';+import { TableCellNode, TableNode, TableRowNode } from '@lexical/table';+import type { Klass, LexicalNode } from 'lexical';+import { HorizontalRuleNode } from './markdown/horizontal-rule-node';+import { MermaidNode } from './mermaid-node';++const EditorNodes: Array<Klass<LexicalNode>> = [+ HeadingNode,+ QuoteNode,+ CodeNode,+ CodeHighlightNode,+ ListItemNode,+ ListNode,+ LinkNode,+ AutoLinkNode,+ HashtagNode,+ HorizontalRuleNode,+ MermaidNode,+ TableNode,+ TableRowNode,+ TableCellNode,+];++export default EditorNodes;diff --git a/web/src/lib/editor/plugins/floating-selection-toolbar.tsx b/web/src/lib/editor/plugins/floating-selection-toolbar.tsxnew file mode 100644index 0000000000..2c25388cd8--- /dev/null+++ b/web/src/lib/editor/plugins/floating-selection-toolbar.tsx@@ -0,0 +1,442 @@+/**+ * FloatingSelectionToolbar — appears when text is selected,+ * provides formatting: heading, bold, italic, code, strikethrough, link, quote.+ */+import { $createCodeNode, $isCodeNode } from '@lexical/code';+import { TOGGLE_LINK_COMMAND } from '@lexical/link';+import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';+import type { HeadingTagType } from '@lexical/rich-text';+import {+ $createHeadingNode,+ $createQuoteNode,+ $isHeadingNode,+ $isQuoteNode,+} from '@lexical/rich-text';+import { $setBlocksType } from '@lexical/selection';+import {+ $createParagraphNode,+ $getRoot,+ $getSelection,+ $isElementNode,+ $isRangeSelection,+ COMMAND_PRIORITY_LOW,+ FORMAT_TEXT_COMMAND,+ SELECTION_CHANGE_COMMAND,+} from 'lexical';+import { useEffect, useRef, useState } from 'react';++export default function FloatingSelectionToolbar() {+ const [editor] = useLexicalComposerContext();+ const [show, setShow] = useState(false);+ const [pos, setPos] = useState({ x: 0, y: 0 });+ const barRef = useRef<HTMLDivElement>(null);+ const [currentBlock, setCurrentBlock] = useState<string>('paragraph');++ useEffect(() => {+ const removeUpdateListener = editor.registerUpdateListener(() => {+ editor.getEditorState().read(() => {+ const selection = $getSelection();+ if (!$isRangeSelection(selection) || selection.isCollapsed()) {+ setShow(false);+ return;+ }+ const nativeSel = window.getSelection();+ if (!nativeSel || nativeSel.isCollapsed || !nativeSel.rangeCount) {+ setShow(false);+ return;+ }++ // Detect current block type+ const anchor = selection.anchor.getNode();+ let block = 'paragraph';+ let parent = $isElementNode(anchor) ? anchor : anchor.getParent();+ while (parent && parent !== $getRoot()) {+ if ($isHeadingNode(parent)) {+ block = parent.getTag();+ break;+ }+ if ($isQuoteNode(parent)) {+ block = 'quote';+ break;+ }+ if ($isCodeNode(parent)) {+ block = 'code';+ break;+ }+ parent = parent.getParent();+ }+ setCurrentBlock(block);++ const range = nativeSel.getRangeAt(0);+ const rect = range.getBoundingClientRect();+ setPos({+ x: rect.left + rect.width / 2,+ y: rect.top - 10,+ });+ setShow(true);+ });+ });++ const removeSelectionListener = editor.registerCommand(+ SELECTION_CHANGE_COMMAND,+ () => false,+ COMMAND_PRIORITY_LOW,+ );++ return () => {+ removeUpdateListener();+ removeSelectionListener();+ };+ }, [editor]);++ const format = (type: 'bold' | 'italic' | 'strikethrough' | 'code') => {+ editor.dispatchCommand(FORMAT_TEXT_COMMAND, type);+ setShow(false);+ };++ const toggleLink = () => {+ const url = window.prompt('Enter URL:');+ if (url) {+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, url);+ }+ setShow(false);+ };++ const setHeading = (tag: HeadingTagType) => {+ editor.update(() => {+ const selection = $getSelection();+ if ($isRangeSelection(selection)) {+ $setBlocksType(selection, () => $createHeadingNode(tag));+ }+ });+ setShow(false);+ };++ const setQuote = () => {+ editor.update(() => {+ const selection = $getSelection();+ if ($isRangeSelection(selection)) {+ $setBlocksType(selection, () => $createQuoteNode());+ }+ });+ setShow(false);+ };++ const setParagraph = () => {+ editor.update(() => {+ const selection = $getSelection();+ if ($isRangeSelection(selection)) {+ $setBlocksType(selection, () => $createParagraphNode());+ }+ });+ setShow(false);+ };++ const [showCodeLang, setShowCodeLang] = useState(false);++ const setCodeBlock = (lang?: string) => {+ editor.update(() => {+ const selection = $getSelection();+ if ($isRangeSelection(selection)) {+ const node = $createCodeNode(lang);+ $setBlocksType(selection, () => node);+ }+ });+ setShow(false);+ };++ const codeLangs = [+ '',+ 'javascript',+ 'typescript',+ 'python',+ 'html',+ 'css',+ 'scss',+ 'less',+ 'json',+ 'yaml',+ 'xml',+ 'bash',+ 'sh',+ 'powershell',+ 'sql',+ 'graphql',+ 'go',+ 'rust',+ 'cpp',+ 'c',+ 'csharp',+ 'java',+ 'kotlin',+ 'swift',+ 'php',+ 'ruby',+ 'perl',+ 'lua',+ 'r',+ 'matlab',+ 'dart',+ 'zig',+ 'makefile',+ 'dockerfile',+ 'ini',+ 'toml',+ 'diff',+ 'markdown',+ 'mermaid',+ 'plaintext',+ ];++ const [showHeadingMenu, setShowHeadingMenu] = useState(false);++ if (!show) return null;++ const btnStyle: React.CSSProperties = {+ padding: '4px 7px',+ border: 'none',+ borderRadius: 4,+ cursor: 'pointer',+ fontSize: 12,+ fontWeight: 500,+ background: 'transparent',+ color: 'var(--nim-text)',+ fontFamily: 'inherit',+ lineHeight: 1,+ whiteSpace: 'nowrap',+ };+ const activeStyle: React.CSSProperties = {+ ...btnStyle,+ background: 'var(--nim-bg-selected)',+ color: 'var(--nim-primary)',+ };++ const headingLabels: Record<string, string> = {+ h1: 'H1',+ h2: 'H2',+ h3: 'H3',+ h4: 'H4',+ h5: 'H5',+ h6: 'H6',+ };++ return (+ <div+ ref={barRef}+ style={{+ position: 'fixed',+ left: pos.x,+ top: pos.y,+ transform: 'translate(-50%, -100%)',+ zIndex: 1000,+ display: 'flex',+ alignItems: 'center',+ gap: 2,+ padding: '4px 6px',+ background: 'var(--nim-bg-secondary)',+ border: '1px solid var(--nim-border)',+ borderRadius: 8,+ boxShadow: '0 4px 12px rgba(0,0,0,0.25)',+ }}+ >+ {/* Heading dropdown (H1-H6 only) */}+ <div style={{ position: 'relative' }}>+ <button+ style={{+ ...btnStyle,+ padding: '4px 14px 4px 7px',+ border: '1px solid var(--nim-border)',+ borderRadius: 4,+ background: 'var(--nim-bg-tertiary)',+ fontSize: 11,+ fontWeight: 600,+ }}+ onClick={() => setShowHeadingMenu(!showHeadingMenu)}+ title="Heading"+ >+ {headingLabels[currentBlock] || 'H'} ▾+ </button>+ {showHeadingMenu && (+ <div+ style={{+ position: 'absolute',+ top: '100%',+ left: 0,+ marginTop: 4,+ background: 'var(--nim-bg)',+ border: '1px solid var(--nim-border)',+ borderRadius: 6,+ boxShadow: '0 4px 12px rgba(0,0,0,0.25)',+ minWidth: 100,+ zIndex: 1001,+ padding: '4px 0',+ }}+ >+ {(['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const).map((tag) => (+ <div+ key={tag}+ onClick={() => {+ setShowHeadingMenu(false);+ setHeading(tag);+ }}+ style={{+ padding: '5px 12px',+ cursor: 'pointer',+ fontSize: 12,+ fontWeight: tag === 'h1' ? 700 : tag === 'h2' ? 600 : 500,+ color:+ currentBlock === tag+ ? 'var(--nim-primary)'+ : 'var(--nim-text)',+ background:+ currentBlock === tag+ ? 'var(--nim-bg-selected)'+ : 'transparent',+ }}+ onMouseEnter={(e) => {+ e.currentTarget.style.background = 'var(--nim-bg-hover)';+ }}+ onMouseLeave={(e) => {+ e.currentTarget.style.background =+ currentBlock === tag+ ? 'var(--nim-bg-selected)'+ : 'transparent';+ }}+ >+ {headingLabels[tag]}+ </div>+ ))}+ </div>+ )}+ </div>++ {/* Block type buttons: Paragraph, Quote */}+ <button+ style={currentBlock === 'paragraph' ? activeStyle : btnStyle}+ onClick={setParagraph}+ title="Paragraph"+ >+ ¶+ </button>+ <button+ style={currentBlock === 'quote' ? activeStyle : btnStyle}+ onClick={setQuote}+ title="Quote"+ >+ ❝+ </button>++ {/* Code Block with language picker */}+ <div style={{ position: 'relative' }}>+ <button+ style={currentBlock === 'code' ? activeStyle : btnStyle}+ onClick={() => setShowCodeLang(!showCodeLang)}+ title="Code Block"+ >+ {'{}'}+ </button>+ {showCodeLang && (+ <div+ style={{+ position: 'absolute',+ top: '100%',+ left: '50%',+ transform: 'translateX(-50%)',+ marginTop: 4,+ background: 'var(--nim-bg)',+ border: '1px solid var(--nim-border)',+ borderRadius: 6,+ boxShadow: '0 4px 12px rgba(0,0,0,0.25)',+ minWidth: 130,+ maxHeight: 200,+ overflowY: 'auto',+ zIndex: 1001,+ padding: '4px 0',+ }}+ >+ {codeLangs.map((lang) => (+ <div+ key={lang || '__plain'}+ role="button"+ tabIndex={-1}+ onClick={() => {+ setShowCodeLang(false);+ setCodeBlock(lang || undefined);+ }}+ onKeyDown={(e) => {+ if (e.key === 'Enter' || e.key === ' ') {+ e.preventDefault();+ setShowCodeLang(false);+ setCodeBlock(lang || undefined);+ }+ }}+ style={{+ padding: '4px 12px',+ cursor: 'pointer',+ fontSize: 11,+ color: 'var(--nim-text)',+ }}+ onMouseEnter={(e) => {+ e.currentTarget.style.background = 'var(--nim-bg-hover)';+ }}+ onMouseLeave={(e) => {+ e.currentTarget.style.background = 'transparent';+ }}+ >+ {lang || '(no language)'}+ </div>+ ))}+ </div>+ )}+ </div>++ <div+ style={{+ width: 1,+ height: 16,+ background: 'var(--nim-border)',+ margin: '0 3px',+ }}+ />++ {/* Inline format controls */}+ <button style={btnStyle} onClick={() => format('bold')} title="Bold">+ <strong>B</strong>+ </button>+ <button+ style={{ ...btnStyle, fontStyle: 'italic' }}+ onClick={() => format('italic')}+ title="Italic"+ >+ <em>I</em>+ </button>+ <button+ style={{ ...btnStyle, textDecoration: 'line-through' }}+ onClick={() => format('strikethrough')}+ title="Strikethrough"+ >+ <s>S</s>+ </button>+ <button+ style={{ ...btnStyle, fontFamily: 'monospace' }}+ onClick={() => format('code')}+ title="Inline Code"+ >+ </>+ </button>+ <div+ style={{+ width: 1,+ height: 16,+ background: 'var(--nim-border)',+ margin: '0 3px',+ }}+ />++ {/* Link */}+ <button style={btnStyle} onClick={toggleLink} title="Link">+ 🔗+ </button>+ </div>+ );+}diff --git a/web/src/lib/editor/plugins/table-actions-plugin.tsx b/web/src/lib/editor/plugins/table-actions-plugin.tsxnew file mode 100644index 0000000000..94f6ef9ac6--- /dev/null+++ b/web/src/lib/editor/plugins/table-actions-plugin.tsx@@ -0,0 +1,315 @@+/**+ * TableActionsPlugin — floating toolbar for table editing.+ * Appears above the table when cursor is inside it.+ * Provides: row/column count adjustment, text alignment.+ */+import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';+import {+ $createTableCellNode,+ $createTableRowNode,+ $isTableCellNode,+ $isTableNode,+ $isTableRowNode,+ $removeTableRowAtIndex,+ TableCellHeaderStates,+ type TableNode,+} from '@lexical/table';+import {+ $findMatchingParent,+ $getNodeByKey,+ $getSelection,+ $isElementNode,+ $isParagraphNode,+ $isRangeSelection,+ COMMAND_PRIORITY_LOW,+ SELECTION_CHANGE_COMMAND,+} from 'lexical';+import { useCallback, useEffect, useState } from 'react';++interface TableInfo {+ key: string;+ rows: number;+ cols: number;+}++/** Read-only: check if selection is inside a table and return its info. */+function $readTableInfo(): TableInfo | null {+ const selection = $getSelection();+ if (!$isRangeSelection(selection)) return null;+ const cellNode = $findMatchingParent(+ selection.anchor.getNode(),+ $isTableCellNode,+ );+ if (!cellNode) return null;+ const table = $findMatchingParent(cellNode, $isTableNode) as TableNode | null;+ if (!table) return null;+ const rows = table.getChildren().length;+ const firstRow = table.getFirstChild();+ const cols = $isTableRowNode(firstRow) ? firstRow.getChildren().length : 0;+ return { key: table.getKey(), rows, cols };+}++export default function TableActionsPlugin() {+ const [editor] = useLexicalComposerContext();+ const [show, setShow] = useState(false);+ const [rows, setRows] = useState(0);+ const [cols, setCols] = useState(0);+ const [tableKey, setTableKey] = useState<string | null>(null);+ const [pos, setPos] = useState({ x: 0, y: 0 });++ const checkTable = useCallback(() => {+ const info: TableInfo | null = editor.getEditorState().read(() => {+ return $readTableInfo();+ });++ if (!info) {+ setShow(false);+ setTableKey(null);+ return;+ }++ const { key, rows: r, cols: c } = info;+ setTableKey(key);+ setRows(r);+ setCols(c);++ // Try to position toolbar above the table's DOM element+ try {+ editor.read(() => {+ const domEl = editor.getElementByKey(key);+ if (domEl) {+ const tableRect = domEl.getBoundingClientRect();+ setPos({ x: tableRect.left, y: tableRect.top - 36 });+ setShow(true);+ }+ });+ } catch {+ // DOM not ready yet+ }+ }, [editor]);++ useEffect(() => {+ const removeUpdateListener = editor.registerUpdateListener(() => {+ checkTable();+ });++ const removeSelectionListener = editor.registerCommand(+ SELECTION_CHANGE_COMMAND,+ () => {+ checkTable();+ return false;+ },+ COMMAND_PRIORITY_LOW,+ );++ return () => {+ removeUpdateListener();+ removeSelectionListener();+ };+ }, [editor, checkTable]);++ const handleAddRow = useCallback(() => {+ if (!tableKey) return;+ editor.update(() => {+ const node = $getNodeByKey(tableKey);+ if (!$isTableNode(node)) return;+ const firstRow = node.getFirstChild();+ if (!$isTableRowNode(firstRow)) return;+ const colCount = firstRow.getChildren().length;+ const newRow = $createTableRowNode();+ for (let i = 0; i < colCount; i++) {+ newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS));+ }+ node.append(newRow);+ });+ }, [editor, tableKey]);++ const handleRemoveRow = useCallback(() => {+ if (!tableKey || rows <= 1) return;+ editor.update(() => {+ const node = $getNodeByKey(tableKey);+ if (!$isTableNode(node)) return;+ $removeTableRowAtIndex(node, rows - 1);+ });+ }, [editor, tableKey, rows]);++ const handleAddCol = useCallback(() => {+ if (!tableKey) return;+ editor.update(() => {+ const node = $getNodeByKey(tableKey);+ if (!$isTableNode(node)) return;+ for (const row of node.getChildren()) {+ if ($isTableRowNode(row)) {+ row.append($createTableCellNode(TableCellHeaderStates.NO_STATUS));+ }+ }+ });+ }, [editor, tableKey]);++ const handleRemoveCol = useCallback(() => {+ if (!tableKey || cols <= 1) return;+ editor.update(() => {+ const node = $getNodeByKey(tableKey);+ if (!$isTableNode(node)) return;+ for (const row of node.getChildren()) {+ if ($isTableRowNode(row)) {+ const lastCell = row.getLastChild();+ lastCell?.remove();+ }+ }+ });+ }, [editor, tableKey, cols]);++ const setAlignment = useCallback(+ (align: 'left' | 'center' | 'right') => {+ if (!tableKey) return;+ editor.update(() => {+ const node = $getNodeByKey(tableKey);+ if (!$isTableNode(node)) return;+ for (const row of node.getChildren()) {+ if (!$isTableRowNode(row)) continue;+ for (const cell of row.getChildren()) {+ if (!$isTableCellNode(cell)) continue;+ for (const child of cell.getChildren()) {+ if ($isParagraphNode(child) || $isElementNode(child)) {+ child.setFormat(align);+ }+ }+ }+ }+ });+ },+ [editor, tableKey],+ );++ if (!show) return null;++ const btnStyle: React.CSSProperties = {+ padding: '4px 7px',+ border: 'none',+ borderRadius: 4,+ cursor: 'pointer',+ fontSize: 11,+ fontWeight: 500,+ background: 'transparent',+ color: 'var(--nim-text)',+ fontFamily: 'inherit',+ lineHeight: 1,+ };++ const countStyle: React.CSSProperties = {+ padding: '2px 6px',+ fontSize: 12,+ fontWeight: 600,+ color: 'var(--nim-text)',+ minWidth: 22,+ textAlign: 'center',+ };++ return (+ <div+ style={{+ position: 'fixed',+ left: pos.x,+ top: pos.y,+ zIndex: 100,+ display: 'flex',+ alignItems: 'center',+ gap: 2,+ padding: '3px 6px',+ background: 'var(--nim-bg-secondary)',+ border: '1px solid var(--nim-border)',+ borderRadius: 6,+ boxShadow: '0 2px 8px rgba(0,0,0,0.25)',+ pointerEvents: 'auto',+ }}+ >+ <svg+ width="13"+ height="13"+ viewBox="0 0 16 16"+ style={{+ fill: 'none',+ stroke: 'var(--nim-text-muted)',+ strokeWidth: 1.5,+ verticalAlign: 'middle',+ marginRight: 4,+ flexShrink: 0,+ }}+ >+ <rect x="1.5" y="1.5" width="13" height="13" rx="1.5" />+ <line x1="1.5" y1="6" x2="14.5" y2="6" />+ <line x1="8" y1="1.5" x2="8" y2="14.5" />+ </svg>++ {/* Row controls */}+ <button+ onClick={handleRemoveRow}+ disabled={rows <= 1}+ style={{ ...btnStyle, opacity: rows <= 1 ? 0.35 : 1 }}+ title="Delete row"+ >+ −R+ </button>+ <span style={countStyle}>{rows}</span>+ <button onClick={handleAddRow} style={btnStyle} title="Add row">+ +R+ </button>++ <div+ style={{+ width: 1,+ height: 14,+ background: 'var(--nim-border)',+ margin: '0 3px',+ }}+ />++ {/* Column controls */}+ <button+ onClick={handleRemoveCol}+ disabled={cols <= 1}+ style={{ ...btnStyle, opacity: cols <= 1 ? 0.35 : 1 }}+ title="Delete column"+ >+ −C+ </button>+ <span style={countStyle}>{cols}</span>+ <button onClick={handleAddCol} style={btnStyle} title="Add column">+ +C+ </button>++ <div+ style={{+ width: 1,+ height: 14,+ background: 'var(--nim-border)',+ margin: '0 3px',+ }}+ />++ {/* Alignment */}+ <button+ onClick={() => setAlignment('left')}+ style={btnStyle}+ title="Align left"+ >+ ⇤+ </button>+ <button+ onClick={() => setAlignment('center')}+ style={btnStyle}+ title="Align center"+ >+ ⇔+ </button>+ <button+ onClick={() => setAlignment('right')}+ style={btnStyle}+ title="Align right"+ >+ ⇥+ </button>+ </div>+ );+}diff --git a/web/src/lib/editor/plugins/table-row-size-guard.ts b/web/src/lib/editor/plugins/table-row-size-guard.tsnew file mode 100644index 0000000000..ac9f2b0349--- /dev/null+++ b/web/src/lib/editor/plugins/table-row-size-guard.ts@@ -0,0 +1,46 @@+/**+ * Pure guard for table-row size. Kept in its own file so unit tests can+ * import the threshold and the check without pulling in TableTransformer's+ * markdown-import dependency chain (which transitively imports+ * `@lexical/extension` and other modules that fail to resolve under the+ * current `@lexical/*` version pinning - a pre-existing condition flagged+ * by `npx tsc --noEmit` and unrelated to this fix).+ *+ * Background (issue #321): @aawbeck reported a crash-on-load loop. The+ * TableTransformer's `$createTableCell` path recursively calls+ * `$convertFromEnhancedMarkdownString` for each cell on the main thread,+ * inside a single Lexical `editor.update()` transaction. With many large+ * cells the cumulative synchronous Lexical node allocation exhausts the+ * V8 heap and trips a TurboFan integrity-level assertion (SIGTRAP).+ * The next launch re-opens the same file (the `restoreTabs: true`+ * preference) and the loop repeats until the user manually deletes the+ * file.+ *+ * Concrete repro shape: 83 rows of 5,451 chars each (5 cells of ~1,090+ * chars each). The guard below sits above legitimate wide-table sizes+ * (a 10-column table with 400-char cells is ~4,400 chars including+ * pipes and spaces) and below the repro, so it fires on pathological+ * input without affecting normal use. Oversized rows fall through to+ * plain markdown text rendering rather than table parsing - no crash,+ * file still opens, content visible as piped text.+ *+ * Limitation: the guard is per-row only. A table built from many+ * narrow-but-numerous rows can still exhaust heap in aggregate. The+ * residual class is not addressed here; the right path for that is+ * either raising the per-row threshold (no help against narrow-row+ * pile-ups) or moving the recursive cell parse off the main thread.+ * Both are out of scope for this fix; this PR closes the reported+ * crash and unblocks the file-open path.+ */++export const MAX_TABLE_ROW_BYTES = 5_000;++/**+ * Returns true when the given table-row text content exceeds the+ * per-row size threshold and should be skipped by the table+ * transformer. The caller falls back to rendering the row as plain+ * markdown text.+ */+export function isTableRowOversized(textContent: string): boolean {+ return textContent.length > MAX_TABLE_ROW_BYTES;+}diff --git a/web/src/lib/editor/plugins/table-transformer.ts b/web/src/lib/editor/plugins/table-transformer.tsnew file mode 100644index 0000000000..44bed60dce--- /dev/null+++ b/web/src/lib/editor/plugins/table-transformer.ts@@ -0,0 +1,228 @@+/**+ * Table transformer for markdown import/export+ */++/* eslint-disable @typescript-eslint/no-unused-vars, no-console, @typescript-eslint/no-use-before-define */++import { ElementTransformer } from '@lexical/markdown';+import {+ $createTableCellNode,+ $createTableNode,+ $createTableRowNode,+ $isTableCellNode,+ $isTableNode,+ $isTableRowNode,+ TableCellHeaderStates,+ TableCellNode,+ TableNode,+ TableRowNode,+} from '@lexical/table';+import { $isParagraphNode, $isTextNode, LexicalNode } from 'lexical';+import {+ $convertFromEnhancedMarkdownString,+ $convertNodeToEnhancedMarkdownString,+} from '../markdown';+import { isTableRowOversized } from './table-row-size-guard';++// Import transformers from editor+import { getEditorTransformers } from '../markdown';++// Get the complete set of transformers including core and plugin transformers+const getTransformers = () => {+ return getEditorTransformers();+};++// Very primitive table setup+const TABLE_ROW_REG_EXP = /^(?:\|)(.+)(?:\|)\s?$/;+const TABLE_ROW_DIVIDER_REG_EXP = /^(\| ?:?-*:? ?)+\|\s?$/;++export const TABLE_TRANSFORMER: ElementTransformer = {+ dependencies: [TableNode, TableRowNode, TableCellNode],+ export: (node: LexicalNode, _exportChildren) => {+ if (!$isTableNode(node)) {+ return null;+ }++ const output: string[] = [];+ const rows = node.getChildren();++ for (const row of rows) {+ const rowOutput = [];+ if (!$isTableRowNode(row)) {+ continue;+ }++ let isHeaderRow = false;+ for (const cell of row.getChildren()) {+ // It's TableCellNode so it's just to make flow happy+ if ($isTableCellNode(cell)) {+ // Use $convertNodeToEnhancedMarkdownString for single nodes+ rowOutput.push(+ $convertNodeToEnhancedMarkdownString(getTransformers(), cell)+ .replace(/\n/g, '\\n')+ .trim(),+ );+ if (cell.__headerState === TableCellHeaderStates.ROW) {+ isHeaderRow = true;+ }+ }+ }++ output.push(`| ${rowOutput.join(' | ')} |`);+ if (isHeaderRow) {+ output.push(`| ${rowOutput.map((_) => '---').join(' | ')} |`);+ }+ }++ return output.join('\n');+ },+ regExp: TABLE_ROW_REG_EXP,+ replace: (parentNode, _1, match) => {+ console.log('[TableTransformer] replace called, match:', match[0]);+ // Header row+ if (TABLE_ROW_DIVIDER_REG_EXP.test(match[0])) {+ const table = parentNode.getPreviousSibling();+ if (!table || !$isTableNode(table)) {+ return;+ }++ const rows = table.getChildren();+ const lastRow = rows[rows.length - 1];+ if (!lastRow || !$isTableRowNode(lastRow)) {+ return;+ }++ // Add header state to row cells+ lastRow.getChildren().forEach((cell) => {+ if (!$isTableCellNode(cell)) {+ return;+ }+ cell.setHeaderStyles(+ TableCellHeaderStates.ROW,+ TableCellHeaderStates.ROW,+ );+ });++ // Remove line+ parentNode.remove();+ return;+ }++ const matchCells = mapToTableCells(match[0]);++ if (matchCells == null) {+ return;+ }++ const rows = [matchCells];+ let sibling = parentNode.getPreviousSibling();+ let maxCells = matchCells.length;++ while (sibling) {+ if (!$isParagraphNode(sibling)) {+ break;+ }++ if (sibling.getChildrenSize() !== 1) {+ break;+ }++ const firstChild = sibling.getFirstChild();++ if (!$isTextNode(firstChild)) {+ break;+ }++ const cells = mapToTableCells(firstChild.getTextContent());++ if (cells == null) {+ break;+ }++ maxCells = Math.max(maxCells, cells.length);+ rows.unshift(cells);+ const previousSibling = sibling.getPreviousSibling();+ sibling.remove();+ sibling = previousSibling;+ }++ const table = $createTableNode();++ for (const cells of rows) {+ const tableRow = $createTableRowNode();+ table.append(tableRow);++ for (let i = 0; i < maxCells; i++) {+ tableRow.append(i < cells.length ? cells[i] : $createTableCell(''));+ }+ }++ const previousSibling = parentNode.getPreviousSibling();+ if (+ $isTableNode(previousSibling) &&+ getTableColumnsSize(previousSibling) === maxCells+ ) {+ previousSibling.append(...table.getChildren());+ parentNode.remove();+ } else {+ try {+ parentNode.replace(table);+ } catch (e) {+ console.error('Error replacing node with table:', match, e);+ throw e;+ }+ }+ },+ type: 'element',+};++function getTableColumnsSize(table: TableNode) {+ const row = table.getFirstChild();+ return $isTableRowNode(row) ? row.getChildrenSize() : 0;+}++const $createTableCell = (textContent: string): TableCellNode => {+ console.log(+ '[TableTransformer] $createTableCell with:',+ JSON.stringify(textContent),+ );+ textContent = textContent.replace(/\\n/g, '\n');+ const cell = $createTableCellNode(TableCellHeaderStates.NO_STATUS);+ $convertFromEnhancedMarkdownString(+ textContent,+ getTransformers(),+ cell,+ true,+ );+ console.log(+ '[TableTransformer] cell created, children:',+ cell.getChildrenSize(),+ );+ return cell;+};++const mapToTableCells = (textContent: string): Array<TableCellNode> | null => {+ if (isTableRowOversized(textContent)) {+ console.log('[TableTransformer] row oversized:', textContent.length);+ return null;+ }+ const match = textContent.match(TABLE_ROW_REG_EXP);+ if (!match || !match[1]) {+ console.log('[TableTransformer] no regex match for:', textContent);+ return null;+ }+ console.log('[TableTransformer] matched row:', match[1]);+ const cells = match[1].split('|').map((text) => {+ // Remove exactly one space from start and end if present+ const trimmed = text.replace(/^ | $/g, '');+ console.log(+ '[TableTransformer] cell text:',+ JSON.stringify(text),+ '->',+ JSON.stringify(trimmed),+ );+ return $createTableCell(trimmed);+ });+ console.log('[TableTransformer] created', cells.length, 'cells');+ return cells;+};diff --git a/web/src/lib/editor/plugins/toolbar-plugin.tsx b/web/src/lib/editor/plugins/toolbar-plugin.tsxnew file mode 100644index 0000000000..e96ac43699--- /dev/null+++ b/web/src/lib/editor/plugins/toolbar-plugin.tsx@@ -0,0 +1,183 @@+/**+ * ToolbarPlugin — editor toolbar with Toggle Source and Table of Contents.+ */+import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';+import { $isHeadingNode, type HeadingTagType } from '@lexical/rich-text';+import {+ $getNodeByKey,+ $getRoot,+ $isElementNode,+ type LexicalNode,+} from 'lexical';+import { Code } from 'lucide-react';+import { useCallback, useEffect, useState } from 'react';++interface TOCItem {+ text: string;+ tag: HeadingTagType;+ key: string;+}++interface Props {+ onToggleSource: () => void;+ showSource: boolean;+}++export default function ToolbarPlugin({ onToggleSource, showSource }: Props) {+ const [editor] = useLexicalComposerContext();+ const [showToc, setShowToc] = useState(false);+ const [tocItems, setTocItems] = useState<TOCItem[]>([]);++ // Scan headings for TOC+ const scanHeadings = useCallback(() => {+ editor.read(() => {+ const items: TOCItem[] = [];+ const visit = (node: LexicalNode) => {+ if ($isHeadingNode(node)) {+ items.push({+ text: node.getTextContent(),+ tag: node.getTag(),+ key: node.__key,+ });+ }+ if ($isElementNode(node)) {+ for (const child of node.getChildren()) {+ visit(child);+ }+ }+ };+ visit($getRoot());+ setTocItems(items);+ });+ }, [editor]);++ useEffect(() => {+ if (showToc) scanHeadings();+ }, [showToc, scanHeadings]);++ const navigateToHeading = (key: string) => {+ editor.update(() => {+ const node = $getNodeByKey(key);+ if (node && 'selectStart' in node) {+ (node as any).selectStart();+ (node as any).scrollIntoView?.();+ }+ });+ setShowToc(false);+ };++ const tagToPadding: Record<string, string> = {+ h1: '0',+ h2: '12px',+ h3: '24px',+ h4: '36px',+ h5: '48px',+ h6: '60px',+ };++ return (+ <>+ <div+ style={{+ display: 'flex',+ alignItems: 'center',+ gap: 6,+ padding: '4px 12px',+ borderBottom: '1px solid var(--nim-border)',+ background: 'var(--nim-toolbar-bg)',+ flexShrink: 0,+ }}+ >+ <button+ type="button"+ onClick={onToggleSource}+ className="nim-mode-btn inline-flex items-center justify-center gap-1 px-2 py-1 text-xs font-medium rounded border transition-colors"+ style={{+ borderColor: showSource ? 'var(--nim-primary)' : 'transparent',+ background: showSource ? 'var(--nim-bg-selected)' : 'transparent',+ color: showSource ? 'var(--nim-primary)' : 'var(--nim-text-muted)',+ }}+ title="Source"+ >+ <Code className="size-3.5" />+ Source+ </button>+ <button+ onClick={() => {+ setShowToc(!showToc);+ }}+ className="nim-mode-btn"+ style={{+ padding: '4px 10px',+ border: showToc+ ? '1px solid var(--nim-primary)'+ : '1px solid transparent',+ borderRadius: 4,+ cursor: 'pointer',+ fontSize: 12,+ fontWeight: 500,+ background: showToc ? 'var(--nim-bg-selected)' : 'transparent',+ color: showToc ? 'var(--nim-primary)' : 'var(--nim-text-muted)',+ fontFamily: 'inherit',+ }}+ >+ ☰ Outline+ </button>+ </div>++ {/* TOC Dropdown */}+ {showToc && tocItems.length > 0 && (+ <div+ style={{+ position: 'absolute',+ top: 40,+ left: 80,+ zIndex: 50,+ background: 'var(--nim-bg)',+ border: '1px solid var(--nim-border)',+ borderRadius: 8,+ boxShadow: '0 4px 16px rgba(0,0,0,0.3)',+ maxHeight: 300,+ overflowY: 'auto',+ minWidth: 200,+ }}+ >+ <div+ style={{+ padding: '8px 12px',+ fontSize: 11,+ fontWeight: 600,+ color: 'var(--nim-text-faint)',+ textTransform: 'uppercase',+ letterSpacing: 0.5,+ borderBottom: '1px solid var(--nim-border)',+ }}+ >+ Table of Contents+ </div>+ {tocItems.map((item, i) => (+ <div+ key={item.key}+ onClick={() => navigateToHeading(item.key)}+ style={{+ padding: `6px 12px 6px calc(12px + ${tagToPadding[item.tag] || '0px'})`,+ fontSize: 13,+ cursor: 'pointer',+ color: 'var(--nim-text)',+ borderLeft: `3px solid ${item.tag === 'h1' ? 'var(--nim-primary)' : 'transparent'}`,+ }}+ onMouseEnter={(e) =>+ (e.currentTarget.style.background = 'var(--nim-bg-hover)')+ }+ onMouseLeave={(e) =>+ (e.currentTarget.style.background = 'transparent')+ }+ >+ {item.text || `(heading ${i + 1})`}+ </div>+ ))}+ </div>+ )}+ </>+ );+}diff --git a/web/src/lib/editor/raw-markdown-editor.tsx b/web/src/lib/editor/raw-markdown-editor.tsxnew file mode 100644index 0000000000..e6f7474bf2--- /dev/null+++ b/web/src/lib/editor/raw-markdown-editor.tsx@@ -0,0 +1,148 @@+/**+ * RawMarkdownEditor — raw markdown editing using Monaco Editor.+ * Theme follows the app's Nimbalyst theme system.+ */++import type { OnChange, OnMount } from '@monaco-editor/react';+import Editor from '@monaco-editor/react';+import { Eye } from 'lucide-react';+import type { editor as monacoEditor } from 'monaco-editor';+import type { JSX } from 'react';+import { useEffect, useRef } from 'react';++import { useTheme } from '@/components/theme-provider';++interface Props {+ content: string;+ onChange?: (value: string) => void;+ readOnly?: boolean;+ onToggleSource?: () => void;+ language?: string;+}++function defineTheme(monaco: typeof import('monaco-editor'), isDark: boolean) {+ const name = isDark ? 'llmwiki-dark' : 'llmwiki-light';+ monaco.editor.defineTheme(name, {+ base: isDark ? 'vs-dark' : 'vs',+ inherit: true,+ rules: [],+ colors: isDark+ ? {+ 'editor.background': '#2d2d2d',+ 'editor.foreground': '#ffffff',+ 'editor.lineHighlightBackground': '#3a3a3a',+ 'editor.selectionBackground': 'rgba(96,165,250,0.2)',+ 'editorCursor.foreground': '#60a5fa',+ 'editorLineNumber.foreground': '#808080',+ 'editorLineNumber.activeForeground': '#b3b3b3',+ 'editor.selectionHighlightBackground': 'rgba(96,165,250,0.1)',+ }+ : {+ 'editor.background': '#ffffff',+ 'editor.foreground': '#111827',+ 'editor.lineHighlightBackground': '#f3f4f6',+ 'editor.selectionBackground': 'rgba(59,130,246,0.2)',+ 'editorCursor.foreground': '#3b82f6',+ 'editorLineNumber.foreground': '#9ca3af',+ 'editorLineNumber.activeForeground': '#6b7280',+ 'editor.selectionHighlightBackground': 'rgba(59,130,246,0.1)',+ },+ });+ return name;+}++export default function RawMarkdownEditor({+ content,+ onChange,+ readOnly = false,+ onToggleSource,+ language = 'markdown',+}: Props & { showSource?: boolean }): JSX.Element {+ const { theme } = useTheme();+ const editorRef = useRef<monacoEditor.IStandaloneCodeEditor | null>(null);+ const monacoRef = useRef<typeof import('monaco-editor') | null>(null);+ const themeApplied = useRef<string>('');++ const handleMount: OnMount = (editor, monaco) => {+ editorRef.current = editor;+ monacoRef.current = monaco;+ const isDark = theme === 'dark';+ const name = defineTheme(monaco, isDark);+ monaco.editor.setTheme(name);+ themeApplied.current = name;+ };++ // Switch Monaco theme when app theme changes+ useEffect(() => {+ if (!monacoRef.current) return;+ const isDark = theme === 'dark';+ const expected = isDark ? 'llmwiki-dark' : 'llmwiki-light';+ if (themeApplied.current === expected) return;+ const name = defineTheme(monacoRef.current, isDark);+ monacoRef.current.editor.setTheme(name);+ themeApplied.current = name;+ }, [theme]);++ const handleChange: OnChange = (value) => {+ if (onChange && value !== undefined) {+ onChange(value);+ }+ };++ return (+ <div+ style={{+ display: 'flex',+ flexDirection: 'column',+ flex: 1,+ minHeight: 0,+ }}+ >+ <div+ style={{+ display: 'flex',+ alignItems: 'center',+ gap: 6,+ padding: '4px 12px',+ borderBottom: '1px solid var(--nim-border)',+ background: 'var(--nim-toolbar-bg)',+ flexShrink: 0,+ }}+ >+ <button+ type="button"+ onClick={onToggleSource}+ className="nim-mode-btn inline-flex items-center justify-center gap-1 px-2.5 py-1 text-xs font-medium border border-accent-primary rounded bg-accent-primary-5 text-accent-primary hover:bg-accent-primary-10 transition-colors"+ title="WYSIWYG"+ >+ <Eye className="size-3.5" />+ WYSIWYG+ </button>+ </div>+ <div style={{ flex: 1, minHeight: 0 }}>+ <Editor+ height="100%"+ defaultLanguage={language}+ value={content}+ onChange={handleChange}+ onMount={handleMount}+ options={{+ readOnly,+ minimap: { enabled: false },+ fontSize: 14,+ fontFamily: "'SF Mono', 'JetBrains Mono', 'Fira Code', monospace",+ lineNumbers: 'on',+ scrollBeyondLastLine: false,+ wordWrap: 'on',+ tabSize: 2,+ renderLineHighlight: 'line',+ cursorBlinking: 'smooth',+ smoothScrolling: true,+ padding: { top: 16 },+ automaticLayout: true,+ }}+ />+ </div>+ </div>+ );+}diff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex a61265b63b..5089549781 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -453,8 +453,19 @@ Example: A 1 KB message with 1024-dim embedding uses ~9 KB. The 5 MB default lim'This will extract entities and relationships from all your documents in this dataset. The process may take a while to complete.',generateRaptor:'Performs recursive clustering and summarization of document chunks to build a hierarchical tree structure, enabling more context-aware retrieval across lengthy documents.',+ generateArtifact:+ 'Compiles artifact pages (entity / concept / topic wiki) from every document configured with a knowledge compilation template. Only newly added chunks are processed on each run.',+ generateToSkills:+ 'Builds a hierarchical skill tree from this dataset and stores the generated skill pages for search and reuse.',+ noWikiPages: 'No wiki pages yet',+ clearWikiTitle: 'Clear wiki',+ clearWikiDescription:+ 'Are you sure you want to clear all wiki pages in this dataset? This action cannot be undone.',+ noSkills: 'No skills yet',generate: 'Generate',raptor: 'RAPTOR',+ artifact: 'Artifact',+ toSkills: 'To skills',processingType: 'Processing type',dataPipeline: 'Switch or configure ingestion pipeline.',dataPipelineTitle: 'Ingestion pipeline',@@ -489,6 +500,36 @@ Example: A 1 KB message with 1024-dim embedding uses ~9 KB. The 5 MB default limfiles: 'files',configuration: 'Configuration',knowledgeGraph: 'Knowledge graph',+ compilation: 'Compilation',+ export: 'Export',+ version: 'Version',+ versionHistory: 'Version history',+ currentVersion: 'Current version',+ versionDiff: "What's changed in this version",+ noDiffAvailable: 'No changes to display',+ viewingVersion: 'Viewing version',+ commit: 'Commit',+ confirmCommit: 'Confirm commit',+ versionContent: 'Version content',+ versionContentPlaceholder: 'Enter version content',+ versionContentRequired: 'Please input version content',+ graph: 'Graph',+ graphPlaceholder: 'Graph view placeholder',+ llmWiki: 'LLM Wiki',+ skills: 'Skills',+ contents: 'Contents',+ topics: 'Topics',+ concept: 'Concept',+ entity: 'Entity',+ createDirectoryFolder: 'Create directory',+ directoryName: 'Name',+ directoryNamePlaceholder: 'Instance name',+ directoryRule: 'Rule',+ directoryRulePlaceholder: 'Input',+ entity: 'Entity',+ selectArtifact: 'Select an item from the contents to view details',+ sourceDocuments: 'Source documents',+ compilationTitleSuffix: "' dataset",name: 'Name',namePlaceholder: 'Please input name!',doc: 'Docs',@@ -880,6 +921,8 @@ The above is the content you need to summarize.`,randomSeed: 'Random seed',randomSeedMessage: 'Random seed is required',entityTypes: 'Entity types',+ compilationTemplate: 'Compilation template',+ scopeFile: 'File',vietnamese: 'Vietnamese',pageRank: 'Page rank',pageRankTip: `You can assign a higher PageRank score to specific datasets during retrieval. The corresponding score is added to the hybrid similarity scores of retrieved chunks from these datasets, increasing their ranking. See https://ragflow.io/docs/dev/set_page_rank for details.`,@@ -958,6 +1001,18 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-squestionTip: `If there are given questions, the embedding of the chunk will be based on them.`,chunkResult: 'Chunk result',chunkResultTip: `View the chunked segments used for embedding and retrieval.`,+ representation: 'Representation',+ representationKinds: {+ knowledge_graph: 'Knowledge graph',+ mind_map: 'Mind map',+ page_index: 'Page index',+ timeline: 'Timeline',+ tree: 'Tree',+ raptor: 'RAPTOR',+ },+ representationUnsupported:+ 'This representation type is not supported yet.',+ representationEmpty: 'No representation templates available.',enable: 'Enable',disable: 'Disable',delete: 'Delete',@@ -1525,6 +1580,77 @@ Example: Virtual Hosted Style`,datasourceDescription: 'Manage your data source and connections',chatChannels: 'Chat channels',chatChannelsDescription: 'Manage your chat channel bots and credentials',+ compilationTemplates: 'Compilation templates',+ compilationTemplatesDescription: 'Manage your compilation templates',+ addTemplateGroup: 'Add template group',+ editTemplateGroup: 'Edit template group',+ groupName: 'Group name',+ groupNameRequired: 'Please input group name',+ groupDescription: 'Group description',+ templateCount: '{{count}} template(s)',+ atLeastOneTemplateRequired: 'At least one template is required',+ template: 'Template',+ deleteTemplateGroupModalTitle: 'Delete template group',+ deleteTemplateGroupModalContent:+ 'Are you sure you want to delete this template group? This action cannot be undone.',+ addTemplate: 'Add template',+ noTemplates: 'No compilation templates yet.',+ deleteTemplateModalTitle: 'Delete template',+ deleteTemplateModalContent:+ 'Are you sure you want to delete this template? This action cannot be undone.',+ editTemplate: 'Edit template',+ templateName: 'Name',+ templateNameRequired: 'Please input template name',+ templateDescription: 'Description',+ llmForExtraction: 'LLM for extraction',+ llmForExtractionRequired: 'Please select an LLM model',+ templateKind: 'Kind',+ templateKindRequired: 'Please select a kind',+ entitySpecification: 'Entity specification',+ relationSpecification: 'Relation specification',+ conceptSpecification: 'Concept specification',+ claimSpecification: 'Claim specification',+ field: 'Field',+ fieldType: 'Type',+ fieldTypeRequired: 'Please select a type',+ fieldDescription: 'Description',+ fieldDescriptionRequired: 'Please input description',+ fieldRule: 'Rule',+ rulePlaceholder: 'Input extraction rules',+ description: 'Description',+ descriptionPlaceholder: 'Enter description',+ addField: 'Add field',+ example: 'Page-structure example',+ examplePlaceholder: 'Input example',+ instruction: 'Instruction',+ globalRules: 'Global rules',+ globalRulesPlaceholder: 'Input global compilation rules',+ raptorTreeSettings: 'RAPTOR tree settings',+ summarizationPrompt: 'Summarization prompt',+ maxToken: 'Max token',+ maxTokenRequired: 'Please input max token',+ threshold: 'Threshold',+ rechunkByTreeLeaves: 'Re-chunk by tree leaves',+ rechunkByTreeLeavesTip:+ "Merge each leaf cluster's source chunks into a single replacement chunk. Originals are kept but marked unavailable for retrieval. Only one tree template per group may enable this.",+ jsonPreview: 'JSON preview',+ processFlow: 'Process flow',+ processFlowComingSoon: 'Process flow preview coming soon',+ basicInfo: 'Basic info',+ basicInfoDescription: 'Template group basic information',+ templateWizardConfiguration: 'Configuration',+ templateWizardConfigurationDescription: 'Configure templates',+ blueprints: 'Blueprints',+ blueprintsDescription: 'Select required blueprints',+ templates: 'Templates',+ addFieldModalTitle: 'Add field',+ editFieldModalTitle: 'Edit field',+ selectFieldType: 'Select field type',+ blueprintsPlaceholder: 'Blueprints placeholder',+ blueprintsPlaceholderDescription:+ "Select or customize a specific structure from the Blueprint library on the left to define your Wiki's content framework and visual presentation.",+ blueprintsPlaceholderSkip:+ 'If you have no special requirements, feel free to skip this step, and the system will automatically apply the default structure.',channelEmptyTip:'No chat channels added yet. Select one below to connect.',availableChannels: 'Available channels',@@ -1928,6 +2054,25 @@ Example: Virtual Hosted Style`,modelMaxTokensMessage: 'Max tokens must be a number',modelMaxTokensMinMessage: 'Max tokens must be at least 0',},+ knowledgeCompilation: {+ builtinTemplates: 'Built-in template',+ kind: {+ knowledge_graph: 'Knowledge graph',+ artifacts: 'Artifacts',+ timeline: 'Timeline',+ page_index: 'Page index',+ tree: 'Tree',+ mind_map: 'Mind map',+ empty: 'Empty',+ },+ },+ datasetSkill: {+ folders: 'Skills',+ empty: 'No skills available',+ selectFolder: 'Select a skill to view details',+ currentFolder: 'Skill',+ noContent: 'No content',+ },message: {registered: 'Registered!',logout: 'logout',@@ -2801,6 +2946,9 @@ This process aggregates variables from multiple branches into a single variableextractor: 'Transformer',extractorDescription:'Use an LLM to extract structured insights from document chunks—such as summaries, classifications, etc.',+ compiler: 'Compilation',+ compilerDescription:+ 'Compiles document chunks using knowledge compilation templates into structured artifacts.',outputFormat: 'Output format',fileFormats: 'File type',fileFormatOptions: {diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.tsindex a7c3c7443f..6a552ff050 100644--- a/web/src/locales/zh.ts+++ b/web/src/locales/zh.ts@@ -402,6 +402,17 @@ export default {subbarFiles: '文件列表',generate: '生成',raptor: 'RAPTOR',+ artifact: 'Artifact',+ toSkills: '生成技能',+ generateArtifact:+ '从配置了知识编译模板的每个文档中编译 Artifact 页面(实体 / 概念 / 主题 wiki)。每次运行仅处理新添加的 chunk。',+ generateToSkills:+ '从该数据集构建分层技能树,并存储生成的技能页面以供搜索和复用。',+ noWikiPages: '暂无 Wiki 页面',+ clearWikiTitle: '清空 Wiki',+ clearWikiDescription:+ '确定要清空该数据集下的所有 Wiki 页面吗?此操作无法撤销。',+ noSkills: '暂无技能',processingType: '处理类型',dataPipeline: '切换或配置 ingestion pipeline。',dataPipelineTitle: '数据管道',@@ -435,6 +446,35 @@ export default {testing: '检索测试',configuration: '配置',knowledgeGraph: '知识图谱',+ compilation: '汇编',+ export: '导出',+ version: '版本',+ versionHistory: '版本历史',+ currentVersion: '当前版本',+ versionDiff: '本版本改了什么',+ noDiffAvailable: '暂无变更内容',+ viewingVersion: '正在查看版本',+ commit: '提交',+ confirmCommit: '确认提交',+ versionContent: '版本内容',+ versionContentPlaceholder: '请输入版本内容',+ versionContentRequired: '请输入版本内容',+ graph: '图谱',+ graphPlaceholder: '图谱视图占位',+ llmWiki: 'LLM Wiki',+ skills: '技能',+ contents: '目录',+ topics: '主题',+ concept: '概念',+ createDirectoryFolder: '创建目录',+ directoryName: '名称',+ directoryNamePlaceholder: '实例名称',+ directoryRule: '规则',+ directoryRulePlaceholder: '输入',+ entity: '实体',+ selectArtifact: '从目录中选择一个条目以查看详情',+ sourceDocuments: '来源文档',+ compilationTitleSuffix: '的数据集',files: '个文件',name: '名称',namePlaceholder: '请输入名称',@@ -795,6 +835,8 @@ export default {'在 RAPTOR 中,数据块会根据它们的语义相似性进行聚类。阈值设定了数据块被分到同一组所需的最小相似度。阈值越高,每个聚类中的数据块越少;阈值越低,则每个聚类中的数据块越多。',maxClusterTip: '最多可创建的聚类数。',entityTypes: '实体类型',+ compilationTemplate: '编译模板',+ scopeFile: '文件',pageRank: '页面排名',pageRankTip: `知识库检索时,你可以为特定知识库设置较高的 PageRank 分数,该知识库中匹配文本块的混合相似度得分会自动叠加 PageRank 分数,从而提升排序权重。详见 https://ragflow.io/docs/dev/set_page_rank。`,tagName: '标签',@@ -859,6 +901,17 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取实体和关系questionTip: `如果有给定的问题,则块的嵌入将基于它们。`,chunkResult: '切片结果',chunkResultTip: `查看用于嵌入和召回的切片段落。`,+ representation: '表征',+ representationKinds: {+ knowledge_graph: '知识图谱',+ mind_map: '思维导图',+ page_index: '页面索引',+ timeline: '时间线',+ tree: '树',+ raptor: 'RAPTOR',+ },+ representationUnsupported: '暂不支持该表征类型。',+ representationEmpty: '暂无表征模板。',enable: '启用',disable: '禁用',delete: '删除',@@ -1227,6 +1280,76 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取实体和关系datasourceDescription: '管理您的数据源和连接',chatChannels: '聊天渠道',chatChannelsDescription: '管理您的聊天渠道机器人及凭证',+ compilationTemplates: 'Compilation templates',+ compilationTemplatesDescription: '管理您的 Compilation templates',+ addTemplateGroup: '添加模板分组',+ editTemplateGroup: '编辑模板分组',+ groupName: '分组名称',+ groupNameRequired: '请输入分组名称',+ groupDescription: '分组描述',+ templateCount: '{{count}} 个模板',+ atLeastOneTemplateRequired: '至少需要一个模板',+ template: '模板',+ deleteTemplateGroupModalTitle: '删除模板分组',+ deleteTemplateGroupModalContent:+ '确定要删除此模板分组吗?此操作无法撤销。',+ addTemplate: '添加模板',+ noTemplates: '暂无 Compilation templates。',+ deleteTemplateModalTitle: '删除模板',+ deleteTemplateModalContent: '确定要删除此模板吗?此操作无法撤销。',+ editTemplate: '编辑模板',+ templateName: '名称',+ templateNameRequired: '请输入模板名称',+ templateDescription: '描述',+ llmForExtraction: '用于提取的 LLM',+ llmForExtractionRequired: '请选择 LLM 模型',+ templateKind: '类型',+ templateKindRequired: '请选择类型',+ entitySpecification: 'Entity specification',+ relationSpecification: 'Relation specification',+ conceptSpecification: 'Concept specification',+ claimSpecification: 'Claim specification',+ field: '字段',+ fieldType: 'Type',+ fieldTypeRequired: '请选择 type',+ fieldDescription: '描述',+ fieldDescriptionRequired: '请输入描述',+ fieldRule: '规则',+ rulePlaceholder: '请输入提取规则',+ description: '描述',+ descriptionPlaceholder: '请输入描述',+ addField: '添加字段',+ example: '页面结构示例',+ examplePlaceholder: '请输入示例',+ instruction: 'Instruction',+ globalRules: '全局规则',+ globalRulesPlaceholder: '请输入全局编译规则',+ raptorTreeSettings: 'RAPTOR 树设置',+ summarizationPrompt: '摘要提示词',+ maxToken: '最大 token 数',+ maxTokenRequired: '请输入最大 token 数',+ threshold: '阈值',+ rechunkByTreeLeaves: '按树叶重新分块',+ rechunkByTreeLeavesTip:+ '将每个叶簇的源数据块合并为单个替换数据块。原始数据块保留但标记为不可检索。每个分组最多只能有一个树模板启用此功能。',+ jsonPreview: 'JSON 预览',+ processFlow: '流程视图',+ processFlowComingSoon: '流程视图预览即将到来',+ basicInfo: '基本信息',+ basicInfoDescription: '模板分组基础信息',+ templateWizardConfiguration: '配置',+ templateWizardConfigurationDescription: '管理模板的配置',+ blueprints: '蓝图',+ blueprintsDescription: '选择所需要的 blueprints',+ templates: '模板',+ addFieldModalTitle: '添加字段',+ editFieldModalTitle: '编辑字段',+ selectFieldType: '选择字段类型',+ blueprintsPlaceholder: '蓝图占位',+ blueprintsPlaceholderDescription:+ '从左侧的 Blueprint 库中选择或自定义特定结构,以定义您的 Wiki 内容框架和视觉呈现。',+ blueprintsPlaceholderSkip:+ '如果您没有特殊要求,可以跳过此步骤,系统将自动应用默认结构。',channelEmptyTip: '暂未添加任何聊天渠道,请从下方选择一个进行连接。',availableChannels: '可用渠道',availableChannelsDescription: '选择要添加的聊天渠道',@@ -1589,6 +1712,25 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取实体和关系modelMaxTokensMessage: '最大 Token 数必须为数字',modelMaxTokensMinMessage: '最大 Token 数不能小于 0',},+ knowledgeCompilation: {+ builtinTemplates: '内置模板',+ kind: {+ knowledge_graph: '知识图谱',+ artifacts: 'Artifacts',+ timeline: 'Timeline',+ page_index: 'Page index',+ tree: '树',+ mind_map: '思维导图',+ empty: '空',+ },+ },+ datasetSkill: {+ folders: '技能',+ empty: '暂无技能',+ selectFolder: '选择一个技能以查看详情',+ currentFolder: '技能',+ noContent: '无内容',+ },message: {registered: '注册成功',logout: '登出成功',@@ -2405,6 +2547,8 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取实体和关系extractor: '提取器',extractorDescription:'使用 LLM 从文档块(例如摘要、分类等)中提取结构化见解。',+ compiler: '汇编',+ compilerDescription: '使用知识汇编模板将文档块编译为结构化产物。',outputFormat: '输出格式',fileFormats: '文件类型',fileFormatOptions: {diff --git a/web/src/pages/agent/canvas/index.tsx b/web/src/pages/agent/canvas/index.tsxindex ffd8cd076f..951d2bf1d7 100644--- a/web/src/pages/agent/canvas/index.tsx+++ b/web/src/pages/agent/canvas/index.tsx@@ -55,6 +55,7 @@ import { AgentNode } from './node/agent-node';import { BeginNode } from './node/begin-node';import { CategorizeNode } from './node/categorize-node';import { ChunkerNode } from './node/chunker-node';+import { CompilationNode } from './node/compilation-node';import { DataOperationsNode } from './node/data-operations-node';import { NextStepDropdown } from './node/dropdown/next-step-dropdown';import { ExitLoopNode } from './node/exit-loop-node';@@ -96,6 +97,7 @@ export const nodeTypes: NodeTypes = {parserNode: ParserNode,tokenizerNode: TokenizerNode,chunkerNode: ChunkerNode,+ compilationNode: CompilationNode,contextNode: ExtractorNode,dataOperationsNode: DataOperationsNode,listOperationsNode: ListOperationsNode,diff --git a/web/src/pages/agent/canvas/node/compilation-node.tsx b/web/src/pages/agent/canvas/node/compilation-node.tsxnew file mode 100644index 0000000000..6180ecbccd--- /dev/null+++ b/web/src/pages/agent/canvas/node/compilation-node.tsx@@ -0,0 +1,15 @@+import { IRagNode } from '@/interfaces/database/agent';+import { NodeProps } from '@xyflow/react';+import { get } from 'lodash';+import { LLMLabelCard } from './card';+import { RagNode } from './index';++export function CompilationNode({ ...props }: NodeProps<IRagNode>) {+ const { data } = props;++ return (+ <RagNode {...props}>+ <LLMLabelCard llmId={get(data, 'form.llm_id')}></LLMLabelCard>+ </RagNode>+ );+}diff --git a/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx b/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsxindex 29e3e29af5..475240b0d5 100644--- a/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx+++ b/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx@@ -173,6 +173,7 @@ export function PipelineAccordionOperators({...restrictSingleOperatorOnCanvas([Operator.Parser, Operator.Tokenizer]),];list.push(Operator.Extractor);+ list.push(Operator.Compilation);return list;}, [restrictSingleOperatorOnCanvas]);@@ -188,6 +189,7 @@ export function PipelineAccordionOperators({const showChunker = useMemo(() => {return (getOperatorTypeFromId(nodeId) !== Operator.Extractor &&+ getOperatorTypeFromId(nodeId) !== Operator.Compilation &&chunkerOperators.length > 0);}, [chunkerOperators.length, getOperatorTypeFromId, nodeId]);diff --git a/web/src/pages/agent/constant/index.tsx b/web/src/pages/agent/constant/index.tsxindex 741ed6a563..5f1e4050bc 100644--- a/web/src/pages/agent/constant/index.tsx+++ b/web/src/pages/agent/constant/index.tsx@@ -736,6 +736,7 @@ export const RestrictedUpstreamMap = {[Operator.TitleChunker]: [Operator.Begin],[Operator.Tokenizer]: [Operator.Begin],[Operator.Extractor]: [Operator.Begin],+ [Operator.Compilation]: [Operator.Begin],[Operator.File]: [Operator.Begin],[Operator.Loop]: [Operator.Begin],[Operator.LoopStart]: [Operator.Begin],@@ -786,6 +787,7 @@ export const NodeMap = {[Operator.TokenChunker]: 'chunkerNode',[Operator.TitleChunker]: 'chunkerNode',[Operator.Extractor]: 'contextNode',+ [Operator.Compilation]: 'compilationNode',[Operator.DataOperations]: 'dataOperationsNode',[Operator.ListOperations]: 'listOperationsNode',[Operator.VariableAssigner]: 'variableAssignerNode',@@ -832,6 +834,7 @@ export const NoDebugOperatorsList = [Operator.TokenChunker,Operator.TitleChunker,Operator.Extractor,+ Operator.Compilation,Operator.Tool,Operator.Loop,];@@ -843,6 +846,7 @@ export const NoCopyOperatorsList = [Operator.TokenChunker,Operator.TitleChunker,Operator.Extractor,+ Operator.Compilation,];export enum NodeHandleId {diff --git a/web/src/pages/agent/constant/pipeline.tsx b/web/src/pages/agent/constant/pipeline.tsxindex 48c3302646..f13baf214c 100644--- a/web/src/pages/agent/constant/pipeline.tsx+++ b/web/src/pages/agent/constant/pipeline.tsx@@ -1,8 +1,5 @@import { ParseDocumentType } from '@/components/layout-recognize-form-field';-import {- initialLlmBaseValues,- DataflowOperator as Operator,-} from '@/constants/agent';+import { initialLlmBaseValues, Operator } from '@/constants/agent';import { cloneDeep } from 'lodash';export enum FileType {@@ -359,7 +356,15 @@ export const initialExtractorValues = {},};-export const NoDebugOperatorsList = [Operator.Begin];+export const initialCompilationValues = {+ ...initialLlmBaseValues,+ compilation_template_group_ids: [],+ outputs: {+ chunks: { type: 'Array<Object>', value: [] },+ },+};++export const NoDebugOperatorsList = [Operator.File];export const FileTypeSuffixMap = {[FileType.PDF]: ['pdf'],diff --git a/web/src/pages/agent/form-sheet/form-config-map.tsx b/web/src/pages/agent/form-sheet/form-config-map.tsxindex cd58843309..7e6b12c678 100644--- a/web/src/pages/agent/form-sheet/form-config-map.tsx+++ b/web/src/pages/agent/form-sheet/form-config-map.tsx@@ -4,6 +4,7 @@ import ArXivForm from '../form/arxiv-form';import BeginForm from '../form/begin-form';import BingForm from '../form/bing-form';import BrowserForm from '../form/browser-use-form';+import CompilationForm from '../form/compilation-form';import CategorizeForm from '../form/categorize-form';import CodeForm from '../form/code-form';import CrawlerForm from '../form/crawler-form';@@ -175,6 +176,9 @@ export const FormConfigMap = {[Operator.Extractor]: {component: ExtractorForm,},+ [Operator.Compilation]: {+ component: CompilationForm,+ },[Operator.DataOperations]: {component: DataOperationsForm,},diff --git a/web/src/pages/agent/form/compilation-form/index.tsx b/web/src/pages/agent/form/compilation-form/index.tsxnew file mode 100644index 0000000000..f04c4d3547--- /dev/null+++ b/web/src/pages/agent/form/compilation-form/index.tsx@@ -0,0 +1,47 @@+import { CompilationTemplateFormField } from '@/components/compilation-template-form-field';+import { LargeModelFormField } from '@/components/large-model-form-field';+import { LlmSettingSchema } from '@/components/llm-setting-items/next';+import { Form } from '@/components/ui/form';+import { zodResolver } from '@hookform/resolvers/zod';+import { memo } from 'react';+import { useForm } from 'react-hook-form';+import { z } from 'zod';+import { initialCompilationValues } from '../../constant/pipeline';+import { useFormValues } from '../../hooks/use-form-values';+import { useWatchFormChange } from '../../hooks/use-watch-form-change';+import { INextOperatorForm } from '../../interface';+import { buildOutputList } from '../../utils/build-output-list';+import { FormWrapper } from '../components/form-wrapper';+import { Output } from '../components/output';++export const FormSchema = z.object({+ compilation_template_group_ids: z.array(z.string()).optional(),+ ...LlmSettingSchema,+});++export type CompilationFormSchemaType = z.infer<typeof FormSchema>;++const outputList = buildOutputList(initialCompilationValues.outputs);++const CompilationForm = ({ node }: INextOperatorForm) => {+ const defaultValues = useFormValues(initialCompilationValues, node);++ const form = useForm<CompilationFormSchemaType>({+ defaultValues,+ resolver: zodResolver(FormSchema),+ });++ useWatchFormChange(node?.id, form);++ return (+ <Form {...form}>+ <FormWrapper>+ <LargeModelFormField></LargeModelFormField>+ <CompilationTemplateFormField name="compilation_template_group_ids"></CompilationTemplateFormField>+ <Output list={outputList}></Output>+ </FormWrapper>+ </Form>+ );+};++export default memo(CompilationForm);diff --git a/web/src/pages/agent/form/components/prompt-editor/index.tsx b/web/src/pages/agent/form/components/prompt-editor/index.tsxindex 8216dfb9e5..d9e2a688ba 100644--- a/web/src/pages/agent/form/components/prompt-editor/index.tsx+++ b/web/src/pages/agent/form/components/prompt-editor/index.tsx@@ -25,7 +25,15 @@ import { cn } from '@/lib/utils';import { JsonSchemaDataType } from '@/pages/agent/constant';import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';import { Variable } from 'lucide-react';-import { forwardRef, ReactNode, useCallback, useEffect, useState } from 'react';+import {+ forwardRef,+ ReactNode,+ useCallback,+ useEffect,+ useId,+ useMemo,+ useState,+} from 'react';import { useTranslation } from 'react-i18next';import { EnterKeyPlugin } from './enter-key-plugin';import { PasteHandlerPlugin } from './paste-handler-plugin';@@ -194,14 +202,18 @@ export const PromptEditor = forwardRef(function PromptEditor(ref: React.Ref<HTMLDivElement>,) {const { t } = useTranslation();+ const id = useId();const [isPathQueryAutoMergeEnabled, setIsPathQueryAutoMergeEnabled] =useState(enablePathQueryAutoMerge);- const initialConfig: InitialConfigType = {- namespace: 'PromptEditor',- theme,- onError,- nodes: Nodes,- };+ const initialConfig: InitialConfigType = useMemo(+ () => ({+ namespace: `PromptEditor-${id}`,+ theme,+ onError,+ nodes: Nodes,+ }),+ [id],+ );useEffect(() => {setIsPathQueryAutoMergeEnabled(enablePathQueryAutoMerge);diff --git a/web/src/pages/agent/form/components/prompt-editor/variable-picker-plugin.tsx b/web/src/pages/agent/form/components/prompt-editor/variable-picker-plugin.tsxindex 31e092ca3e..e95bd6ec09 100644--- a/web/src/pages/agent/form/components/prompt-editor/variable-picker-plugin.tsx+++ b/web/src/pages/agent/form/components/prompt-editor/variable-picker-plugin.tsx@@ -68,7 +68,7 @@ class VariableOption extends MenuOption {label: string;value: string;parentLabel: string | JSX.Element;- icon?: ReactNode;+ icon?: JSX.Element;type?: string;options?: VariableOption[];@@ -83,7 +83,7 @@ class VariableOption extends MenuOption {this.label = label;this.value = value;this.parentLabel = parentLabel;- this.icon = icon;+ this.icon = icon as JSX.Element | undefined;this.type = type;}}@@ -388,10 +388,13 @@ export default function VariablePickerMenuPlugin({const previousValue = useRef<string | undefined>();const [queryString, setQueryString] = React.useState<string>('');- let options = useFilterQueryVariableOptionsByTypes({ types });+ let options: VariablePickerMenuOptionType[] =+ useFilterQueryVariableOptionsByTypes({+ types,+ }) as VariablePickerMenuOptionType[];if (baseOptions) {- options = baseOptions as typeof options;+ options = baseOptions;}const unifiedOptions = useMemo(() => {@@ -527,7 +530,7 @@ export default function VariablePickerMenuPlugin({icon?: ReactNode;}>>((pre, cur) => {- return pre.concat(cur.options);+ return pre.concat(cur.options as typeof pre);}, []);// agent structured outputdiff --git a/web/src/pages/agent/hooks/use-add-node.ts b/web/src/pages/agent/hooks/use-add-node.tsindex 3a9b9cd322..2c86bfd711 100644--- a/web/src/pages/agent/hooks/use-add-node.ts+++ b/web/src/pages/agent/hooks/use-add-node.ts@@ -16,6 +16,7 @@ import {initialBrowserValues,initialCategorizeValues,initialCodeValues,+ initialCompilationValues,initialCrawlerValues,initialDataOperationsValues,initialDocGeneratorValues,@@ -182,6 +183,10 @@ export const useInitializeOperatorParams = () => {sys_prompt: t('flow.prompts.system.summary'),prompts: t('flow.prompts.user.summary'),},+ [Operator.Compilation]: {+ ...initialCompilationValues,+ llm_id: llmId,+ },[Operator.DataOperations]: initialDataOperationsValues,[Operator.ListOperations]: initialListOperationsValues,[Operator.VariableAssigner]: initialVariableAssignerValues,diff --git a/web/src/pages/agent/operator-icon.tsx b/web/src/pages/agent/operator-icon.tsxindex fba627e22f..2e1d7eb31f 100644--- a/web/src/pages/agent/operator-icon.tsx+++ b/web/src/pages/agent/operator-icon.tsx@@ -2,6 +2,7 @@ import { IconFontFill } from '@/components/icon-font';import SvgIcon from '@/components/svg-icon';import { cn } from '@/lib/utils';import {+ Columns3Cog,FileCode,FileText,Globe,@@ -61,6 +62,7 @@ export const LucideIconMap = {[Operator.ExitLoop]: LogOut,[Operator.DocGenerator]: FileText,[Operator.Browser]: Globe,+ [Operator.Compilation]: Columns3Cog,};const Empty = () => {diff --git a/web/src/pages/agent/utils/dsl-bridge.ts b/web/src/pages/agent/utils/dsl-bridge.tsindex f21f843a07..4d08e1bba1 100644--- a/web/src/pages/agent/utils/dsl-bridge.ts+++ b/web/src/pages/agent/utils/dsl-bridge.ts@@ -30,7 +30,7 @@import { Edge } from '@xyflow/react';-import { DataflowOperator, EmptyDsl, Operator } from '@/constants/agent';+import { EmptyDsl, Operator } from '@/constants/agent';import {DSL,DSLComponents,@@ -227,10 +227,7 @@ export const inferIsAgentFromImport = (raw: Record<string, any>): boolean => {const graph = raw?.graph;if (graph && Array.isArray(graph.nodes)) {const labels = (graph.nodes as any[]).map((n: any) => n?.data?.label);- if (- labels.includes(DataflowOperator.Begin) &&- labels.includes(DataflowOperator.Parser)- ) {+ if (labels.includes(Operator.File) && labels.includes(Operator.Parser)) {return false;}return true;diff --git a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/document-view-switch/index.tsx b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/document-view-switch/index.tsxnew file mode 100644index 0000000000..a6949820f1--- /dev/null+++ b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/document-view-switch/index.tsx@@ -0,0 +1,110 @@+import DocumentPreview from '@/components/document-preview';+import DocumentHeader from '@/components/document-preview/document-header';+import { Segmented, type SegmentedValue } from '@/components/ui/segmented';+import Representation, {+ type ClickableNode,+} from '@/pages/chunk/representation';+import { File, LayoutList } from 'lucide-react';+import { useCallback, useState } from 'react';+import { useTranslation } from 'react-i18next';+import { IHighlight } from 'react-pdf-highlighter';++enum ViewMode {+ Preview = 'preview',+ Representations = 'representations',+}++interface DocumentViewSwitchProps {+ documentInfo?: {+ size: number;+ name: string;+ create_date: string;+ };+ fileType: string;+ highlights: IHighlight[];+ setWidthAndHeight: (width: number, height: number) => void;+ url: string;+ onChunkIdsChange?: (chunkIds: string[]) => void;+}++export default function DocumentViewSwitch({+ documentInfo,+ fileType,+ highlights,+ setWidthAndHeight,+ url,+ onChunkIdsChange,+}: DocumentViewSwitchProps) {+ const { t } = useTranslation();+ const [viewMode, setViewMode] = useState<ViewMode>(ViewMode.Preview);++ const handleNodeClick = useCallback(+ (node: ClickableNode) => {+ onChunkIdsChange?.(node.source_chunk_ids ?? []);+ },+ [onChunkIdsChange],+ );++ const handleViewModeChange = useCallback(+ (value: SegmentedValue) => {+ setViewMode(value as ViewMode);+ if (value === ViewMode.Preview && viewMode !== ViewMode.Preview) {+ onChunkIdsChange?.([]);+ }+ },+ [onChunkIdsChange, viewMode],+ );++ const options = [+ {+ value: ViewMode.Preview,+ label: (+ <div className="flex items-center gap-1">+ <File className="h-4 w-4" />+ <span>{t('common.preview', 'Preview')}</span>+ </div>+ ),+ },+ {+ value: ViewMode.Representations,+ label: (+ <div className="flex items-center gap-1">+ <LayoutList className="h-4 w-4" />+ <span>{t('chunk.representation', 'Representation')}</span>+ </div>+ ),+ },+ ];++ return (+ <>+ <DocumentHeader+ className="flex-1 min-w-0"+ wrapperClassName="flex items-center justify-between p-5 pb-0 gap-2"+ size={documentInfo?.size ?? 0}+ name={documentInfo?.name ?? ''}+ create_date={documentInfo?.create_date ?? ''}+ >+ <Segmented+ options={options}+ value={viewMode}+ onChange={handleViewModeChange}+ />+ </DocumentHeader>++ <div className="flex-1 h-0 min-h-0 overflow-hidden p-5 pt-2.5 [&>section]:h-full [&>section]:min-h-0">+ {viewMode === ViewMode.Preview ? (+ <DocumentPreview+ className="h-full min-h-0 overflow-auto [&_img]:max-w-full [&_img]:h-auto"+ fileType={fileType}+ highlights={highlights}+ setWidthAndHeight={setWidthAndHeight}+ url={url}+ />+ ) : (+ <Representation onNodeClick={handleNodeClick} />+ )}+ </div>+ </>+ );+}diff --git a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsxindex 18ae5aa4b9..a615c8663d 100644--- a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx+++ b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx@@ -17,10 +17,9 @@ import {import ChunkResultBar from './components/chunk-result-bar';import CheckboxSets from './components/chunk-result-bar/checkbox-sets';+import DocumentViewSwitch from './components/document-view-switch';// import DocumentHeader from './components/document-preview/document-header';-import DocumentPreview from '@/components/document-preview';-import DocumentHeader from '@/components/document-preview/document-header';import { useGetDocumentUrl } from '@/components/document-preview/hooks';import { PageHeader } from '@/components/page-header';import { Button } from '@/components/ui/button';@@ -38,7 +37,8 @@ import {import { LucideArrowBigLeft } from 'lucide-react';import styles from './index.module.less';-const Chunk = () => {+function Chunk() {+ const [filterChunkIds, setFilterChunkIds] = useState<string[]>([]);const [selectedChunkIds, setSelectedChunkIds] = useState<string[]>([]);const { removeChunk } = useDeleteChunkByIds();const {@@ -50,7 +50,7 @@ const Chunk = () => {available,handleSetAvailable,dataUpdatedAt,- } = useFetchNextChunkList();+ } = useFetchNextChunkList(true, { chunkIds: filterChunkIds });const { handleChunkCardClick, selectedChunkId } = useHandleChunkCardClick();const isPdf = documentInfo?.type === 'pdf';@@ -103,6 +103,16 @@ const Chunk = () => {[],);+ const handleChunkIdsChange = useCallback(+ (chunkIds: string[]) => {+ setFilterChunkIds(chunkIds);+ if (chunkIds.length === 0) {+ pagination.onChange?.(1, pagination.pageSize);+ }+ },+ [pagination],+ );+const showSelectedChunkWarning = useCallback(() => {message.warning(t('message.pleaseSelectChunk'));}, [t]);@@ -188,17 +198,14 @@ const Chunk = () => {<Card className="mx-5 mb-5 flex-1 h-0 p-0 bg-transparent shadow-none"><CardContent className="p-0 h-full flex flex-row divide-x-0.5 rtl:divide-x-reverse"><article className="w-2/5 flex flex-col">- <DocumentHeader className="flex-0 p-5 pb-0" {...documentInfo} />-- <div className="flex-1 h-0 min-h-0 overflow-hidden p-5 pt-2.5 [&>section]:h-full [&>section]:min-h-0">- <DocumentPreview- className="h-full min-h-0 overflow-auto [&_img]:max-w-full [&_img]:h-auto"- fileType={fileType}- highlights={highlights}- setWidthAndHeight={setWidthAndHeight}- url={fileUrl}- />- </div>+ <DocumentViewSwitch+ documentInfo={documentInfo}+ fileType={fileType}+ highlights={highlights}+ setWidthAndHeight={setWidthAndHeight}+ url={fileUrl}+ onChunkIdsChange={handleChunkIdsChange}+ /></article><article@@ -293,6 +300,6 @@ const Chunk = () => {)}</main>);-};+}export default Chunk;diff --git a/web/src/pages/chunk/representation/components/representation-renderer.tsx b/web/src/pages/chunk/representation/components/representation-renderer.tsxnew file mode 100644index 0000000000..4b16125fed--- /dev/null+++ b/web/src/pages/chunk/representation/components/representation-renderer.tsx@@ -0,0 +1,167 @@+import ArtifactForceGraph from '@/components/artifact-force-graph';+import { TreeView, type TreeDataItem } from '@/components/ui/tree-view';+import { CompilationTemplateKind } from '@/constants/compilation';+import { type IArtifactGraphEntity } from '@/interfaces/database/dataset';+import {+ type IStructureGraphTemplate,+ type StructureTemplateKind,+} from '@/interfaces/database/document-structure';+import { useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import {+ adaptKnowledgeGraphToForceGraph,+ adaptPageIndexToTreeData,+ adaptTimelineToX6Data,+ adaptTreeToTreeData,+ filterTreeDataByKeyword,+} from '../utils/adapters';+import TimelineX6Graph from './timeline-x6-graph';++export interface ClickableNode {+ id: string;+ name?: string;+ source_chunk_ids?: string[];+}++interface RepresentationRendererProps {+ template?: IStructureGraphTemplate;+ searchKeyword?: string;+ onNodeClick?: (node: ClickableNode) => void;+}++function UnsupportedPlaceholder({ kind }: { kind: StructureTemplateKind }) {+ const { t } = useTranslation();++ return (+ <div className="flex items-center justify-center h-full text-text-secondary">+ {t('chunk.representationUnsupported', {+ kind,+ defaultValue: 'This representation type is not supported yet.',+ })}+ </div>+ );+}++export function RepresentationRenderer({+ template,+ searchKeyword = '',+ onNodeClick,+}: RepresentationRendererProps) {+ const handleTreeItemClick = useCallback(+ (item: TreeDataItem | undefined) => {+ if (item?.source_chunk_ids?.length) {+ onNodeClick?.({+ id: item.id,+ name: item.name,+ source_chunk_ids: item.source_chunk_ids,+ });+ }+ },+ [onNodeClick],+ );++ const handleArtifactNodeClick = useCallback(+ (node: IArtifactGraphEntity) => {+ if (node.source_chunk_ids?.length) {+ onNodeClick?.({+ id: node.slug,+ name: node.name,+ source_chunk_ids: node.source_chunk_ids,+ });+ }+ },+ [onNodeClick],+ );++ const handleTimelineNodeClick = useCallback(+ (node: { id: string; name: string; source_chunk_ids?: string[] }) => {+ if (node.source_chunk_ids?.length) {+ onNodeClick?.(node);+ }+ },+ [onNodeClick],+ );++ const getArtifactNodeName = useCallback(+ (node: IArtifactGraphEntity) => node.name,+ [],+ );++ const filteredTreeData = useMemo<TreeDataItem[]>(() => {+ if (!template) return [];+ if (template.kind === CompilationTemplateKind.PageIndex) {+ const data = adaptPageIndexToTreeData(template);+ return searchKeyword.trim()+ ? filterTreeDataByKeyword(data, searchKeyword)+ : data;+ }+ if (template.kind === CompilationTemplateKind.Tree) {+ const data = adaptTreeToTreeData(template);+ return searchKeyword.trim()+ ? filterTreeDataByKeyword(data, searchKeyword)+ : data;+ }+ return [];+ }, [template, searchKeyword]);++ if (!template) {+ return null;+ }++ switch (template.kind) {+ case CompilationTemplateKind.PageIndex:+ return (+ <div className="mt-6 overflow-auto scrollbar-auto">+ <TreeView+ data={filteredTreeData}+ expandAll+ onSelectChange={handleTreeItemClick}+ />+ </div>+ );+ case CompilationTemplateKind.Tree:+ return (+ <div className="mt-6 overflow-auto scrollbar-auto">+ <TreeView+ data={filteredTreeData}+ expandAll+ onSelectChange={handleTreeItemClick}+ />+ </div>+ );+ case CompilationTemplateKind.KnowledgeGraph:+ return (+ <div className="mt-6 flex-1 min-h-0">+ <ArtifactForceGraph+ data={adaptKnowledgeGraphToForceGraph(template)}+ show+ getNodeId={getArtifactNodeName}+ onNodeClick={handleArtifactNodeClick}+ />+ </div>+ );+ case CompilationTemplateKind.Timeline:+ return (+ <div className="mt-6 flex-1 min-h-0">+ <TimelineX6Graph+ data={adaptTimelineToX6Data(template)}+ show+ onNodeClick={handleTimelineNodeClick}+ />+ </div>+ );+ case CompilationTemplateKind.MindMap:+ return (+ <div className="mt-6 flex-1 min-h-0">+ <ArtifactForceGraph+ data={adaptKnowledgeGraphToForceGraph(template)}+ show+ getNodeId={getArtifactNodeName}+ onNodeClick={handleArtifactNodeClick}+ />+ </div>+ );+ default:+ return <UnsupportedPlaceholder kind={template.kind} />;+ }+}diff --git a/web/src/pages/chunk/representation/components/representation-select.tsx b/web/src/pages/chunk/representation/components/representation-select.tsxnew file mode 100644index 0000000000..dc8dc9bc5e--- /dev/null+++ b/web/src/pages/chunk/representation/components/representation-select.tsx@@ -0,0 +1,55 @@+import {+ SelectWithSearch,+ type SelectWithSearchFlagOptionType,+} from '@/components/originui/select-with-search';+import {+ type IStructureGraphTemplate,+ type StructureTemplateKind,+} from '@/interfaces/database/document-structure';+import { useMemo } from 'react';+import { useTranslation } from 'react-i18next';++interface RepresentationSelectProps {+ templates: IStructureGraphTemplate[];+ value?: string;+ onChange?: (value: string) => void;+}++function getKindLabel(+ t: (key: string) => string,+ kind: StructureTemplateKind,+): string {+ return t(`chunk.representationKinds.${kind}`);+}++export function RepresentationSelect({+ templates,+ value,+ onChange,+}: RepresentationSelectProps) {+ const { t } = useTranslation();++ const options = useMemo<SelectWithSearchFlagOptionType[]>(() => {+ return templates.map((template) => ({+ value: template.template_id,+ label: (+ <span className="flex items-center gap-2">+ <span className="truncate">{template.template_name}</span>+ <span className="text-xs text-text-secondary shrink-0">+ {getKindLabel(t, template.kind)}+ </span>+ </span>+ ),+ keywords: [template.template_name, template.kind],+ }));+ }, [templates, t]);++ return (+ <SelectWithSearch+ options={options}+ value={value}+ onChange={onChange}+ triggerClassName="w-1/2"+ />+ );+}diff --git a/web/src/pages/chunk/representation/components/timeline-x6-graph/hooks/use-x6-graph.ts b/web/src/pages/chunk/representation/components/timeline-x6-graph/hooks/use-x6-graph.tsnew file mode 100644index 0000000000..8968d900d7--- /dev/null+++ b/web/src/pages/chunk/representation/components/timeline-x6-graph/hooks/use-x6-graph.ts@@ -0,0 +1,88 @@+import { DagreLayout } from '@antv/layout';+import { Graph, type EdgeMetadata, type NodeMetadata } from '@antv/x6';+import { useEffect, useRef } from 'react';++import { type TimelineNodeValue, type TimelineX6GraphProps } from '../types';++export function useX6Graph(+ containerRef: React.RefObject<HTMLDivElement | null>,+ data: TimelineX6GraphProps['data'],+ onNodeClick?: (node: TimelineNodeValue) => void,+) {+ const graphRef = useRef<Graph | null>(null);++ // Initialize the X6 graph instance once.+ useEffect(() => {+ const container = containerRef.current;+ if (!container) return;++ const graph = new Graph({+ container,+ autoResize: true,+ background: { color: 'transparent' },+ grid: false,+ panning: { enabled: true },+ mousewheel: { enabled: true },+ scaling: { min: 0.1, max: 3 },+ });++ graph.on('node:click', ({ node }) => {+ const entity = node.getData<Record<string, unknown> | undefined>();+ const chunkIds = entity?.source_chunk_ids as string[] | undefined;+ if (chunkIds?.length) {+ onNodeClick?.({+ id: node.id,+ name: (entity?.name as string) || node.id,+ source_chunk_ids: chunkIds,+ });+ }+ });++ graphRef.current = graph;++ return () => {+ graph.dispose();+ graphRef.current = null;+ };+ }, [containerRef, onNodeClick]);++ // Re-layout and render whenever the graph data changes.+ useEffect(() => {+ const graph = graphRef.current;+ if (!graph || !data.nodes.length) return;++ const dagreLayout = new DagreLayout({+ type: 'dagre',+ rankdir: 'LR',+ align: 'UL',+ ranksep: 240,+ nodesep: 200,+ edgeMinLen: 2,+ controlPoints: false,+ });++ const layoutData = {+ nodes: data.nodes.map((node) => ({ ...node })) as NodeMetadata[],+ edges: data.edges.map((edge) => ({ ...edge })) as EdgeMetadata[],+ };++ dagreLayout.execute(layoutData).then(() => {+ const positionedNodes = new Map<string, NodeMetadata>();++ dagreLayout.forEachNode((node) => {+ positionedNodes.set(String(node.id), {+ ...(node._original as NodeMetadata),+ x: node.x,+ y: node.y,+ });+ });++ const nodes = layoutData.nodes+ .map((node) => positionedNodes.get(node.id as string))+ .filter(Boolean) as NodeMetadata[];++ graph.fromJSON({ nodes, edges: layoutData.edges });+ graph.zoomToFit({ padding: 20 });+ });+ }, [data]);+}diff --git a/web/src/pages/chunk/representation/components/timeline-x6-graph/index.tsx b/web/src/pages/chunk/representation/components/timeline-x6-graph/index.tsxnew file mode 100644index 0000000000..7cbf81ef20--- /dev/null+++ b/web/src/pages/chunk/representation/components/timeline-x6-graph/index.tsx@@ -0,0 +1,24 @@+import { cn } from '@/lib/utils';+import { useRef } from 'react';++import { useX6Graph } from './hooks/use-x6-graph';+import { type TimelineX6GraphProps } from './types';++export function TimelineX6Graph({+ data,+ show = true,+ onNodeClick,+}: TimelineX6GraphProps) {+ const containerRef = useRef<HTMLDivElement>(null);++ useX6Graph(containerRef, data, onNodeClick);++ return (+ <div+ ref={containerRef}+ className={cn('w-full h-full min-h-0', !show && 'hidden')}+ />+ );+}++export default TimelineX6Graph;diff --git a/web/src/pages/chunk/representation/components/timeline-x6-graph/types.ts b/web/src/pages/chunk/representation/components/timeline-x6-graph/types.tsnew file mode 100644index 0000000000..17509e5a4b--- /dev/null+++ b/web/src/pages/chunk/representation/components/timeline-x6-graph/types.ts@@ -0,0 +1,19 @@+import {+ type TimelineX6EdgeData,+ type TimelineX6NodeData,+} from '../../utils/adapters';++export interface TimelineNodeValue {+ id: string;+ name: string;+ source_chunk_ids?: string[];+}++export interface TimelineX6GraphProps {+ data: {+ nodes: TimelineX6NodeData[];+ edges: TimelineX6EdgeData[];+ };+ show?: boolean;+ onNodeClick?: (node: TimelineNodeValue) => void;+}diff --git a/web/src/pages/chunk/representation/hooks/use-selected-template.ts b/web/src/pages/chunk/representation/hooks/use-selected-template.tsnew file mode 100644index 0000000000..eeaf2857de--- /dev/null+++ b/web/src/pages/chunk/representation/hooks/use-selected-template.ts@@ -0,0 +1,31 @@+import {+ type IStructureGraphTemplate,+ type StructureTemplateKind,+} from '@/interfaces/database/document-structure';+import { useMemo, useState } from 'react';++export function useSelectedTemplate(templates: IStructureGraphTemplate[]) {+ const [selectedTemplateId, setSelectedTemplateId] = useState<string>('');++ const effectiveSelectedTemplateId = useMemo(() => {+ return selectedTemplateId || templates[0]?.template_id || '';+ }, [selectedTemplateId, templates]);++ const selectedTemplate = useMemo(() => {+ return templates.find(+ (template) => template.template_id === effectiveSelectedTemplateId,+ );+ }, [templates, effectiveSelectedTemplateId]);++ const selectedKind = useMemo(+ () => selectedTemplate?.kind ?? ('' as StructureTemplateKind),+ [selectedTemplate],+ );++ return {+ selectedTemplateId: effectiveSelectedTemplateId,+ setSelectedTemplateId,+ selectedTemplate,+ selectedKind,+ };+}diff --git a/web/src/pages/chunk/representation/index.tsx b/web/src/pages/chunk/representation/index.tsxnew file mode 100644index 0000000000..6932b7ea4a--- /dev/null+++ b/web/src/pages/chunk/representation/index.tsx@@ -0,0 +1,105 @@+import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';+import { ExpandableSearchInput } from '@/components/expandable-search-input';+import { Button } from '@/components/ui/button';+import {+ useDeleteDocumentStructureGraph,+ useFetchDocumentStructureGraph,+} from '@/hooks/use-document-request';+import { Trash2 } from 'lucide-react';+import { memo, useCallback, useState } from 'react';+import { useTranslation } from 'react-i18next';+import {+ type ClickableNode,+ RepresentationRenderer,+} from './components/representation-renderer';+import { RepresentationSelect } from './components/representation-select';+import { useSelectedTemplate } from './hooks/use-selected-template';++interface RepresentationProps {+ onNodeClick?: (node: ClickableNode) => void;+}++function Representation({ onNodeClick }: RepresentationProps) {+ const { t } = useTranslation();+ const { data, loading } = useFetchDocumentStructureGraph();+ const { deleteDocumentStructureGraph, loading: deleting } =+ useDeleteDocumentStructureGraph();+ const templates = data?.templates ?? [];+ const { selectedTemplateId, setSelectedTemplateId, selectedTemplate } =+ useSelectedTemplate(templates);+ const [searchKeyword, setSearchKeyword] = useState('');++ const handleSearchChange = useCallback((value: string) => {+ setSearchKeyword(value);+ }, []);++ const handleDelete = useCallback(async () => {+ if (!selectedTemplateId) return;+ await deleteDocumentStructureGraph(selectedTemplateId);+ }, [deleteDocumentStructureGraph, selectedTemplateId]);++ const handleNodeClick = useCallback(+ (node: ClickableNode) => {+ if (!node.source_chunk_ids?.length) return;+ onNodeClick?.(node);+ },+ [onNodeClick],+ );++ return (+ <section className="p-5 rounded-2xl h-full flex flex-col">+ <div className="flex items-center justify-between">+ <RepresentationSelect+ templates={templates}+ value={selectedTemplateId}+ onChange={setSelectedTemplateId}+ />+ <div className="relative flex items-center gap-2">+ <ExpandableSearchInput+ value={searchKeyword}+ onChange={handleSearchChange}+ placeholder={t('chunk.search', 'Search')}+ />+ {templates.length > 0 && (+ <ConfirmDeleteDialog onOk={handleDelete}>+ <Button+ variant="ghost"+ size="icon"+ type="button"+ disabled={deleting}+ aria-label={t('common.delete', 'Delete')}+ className="absolute top-9 right-0"+ >+ <Trash2 className="h-5 w-5" />+ </Button>+ </ConfirmDeleteDialog>+ )}+ </div>+ </div>+ {loading && (+ <div className="mt-6 text-text-secondary">+ {t('common.loading', 'Loading...')}+ </div>+ )}+ {!loading && templates.length === 0 && (+ <div className="mt-6 text-text-secondary">+ {t(+ 'chunk.representationEmpty',+ 'No representation templates available.',+ )}+ </div>+ )}+ {!loading && templates.length > 0 && (+ <RepresentationRenderer+ template={selectedTemplate}+ searchKeyword={searchKeyword}+ onNodeClick={handleNodeClick}+ />+ )}+ </section>+ );+}++export default memo(Representation);++export type { ClickableNode };diff --git a/web/src/pages/chunk/representation/utils/adapters.ts b/web/src/pages/chunk/representation/utils/adapters.tsnew file mode 100644index 0000000000..e511961466--- /dev/null+++ b/web/src/pages/chunk/representation/utils/adapters.ts@@ -0,0 +1,251 @@+import { type TreeDataItem } from '@/components/ui/tree-view';+import {+ type IArtifactGraph,+ type IArtifactGraphEntity,+} from '@/interfaces/database/dataset';+import {+ type IStructureGraphEntity,+ type IStructureGraphRelation,+ type IStructureGraphTemplate,+} from '@/interfaces/database/document-structure';+import { type TreeData } from '@antv/g6/lib/types';++declare module '@/components/ui/tree-view' {+ interface TreeDataItem {+ source_chunk_ids?: string[];+ }+}++function normalizeEntity(entity: IStructureGraphEntity) {+ const id = entity.id ?? entity.name ?? '';+ const name = entity.name ?? entity.id ?? '';+ return { ...entity, id, name };+}++function getEntityDescription(entity: IStructureGraphEntity): string {+ return entity.description ?? entity.discription ?? '';+}++function buildTreeDataItems(+ entities: IStructureGraphEntity[],+ relations: IStructureGraphRelation[],+ relationTypes: string[],+): TreeDataItem[] {+ const normalized = entities+ .map(normalizeEntity)+ .filter((entity) => entity.id);+ const map = new Map<string, TreeDataItem>(+ normalized.map((entity) => [+ entity.id,+ {+ id: entity.id,+ name: entity.name,+ source_chunk_ids: entity.source_chunk_ids,+ },+ ]),+ );+ const childIds = new Set<string>();++ for (const relation of relations) {+ if (!relationTypes.includes(relation.type ?? '')) continue;++ const parent = map.get(relation.from);+ const child = map.get(relation.to);+ if (!parent || !child) continue;++ childIds.add(child.id);+ parent.children = parent.children ?? [];+ parent.children.push(child);+ }++ return normalized+ .filter((entity) => !childIds.has(entity.id))+ .map((entity) => map.get(entity.id))+ .filter((item): item is TreeDataItem => item !== undefined);+}++export function adaptPageIndexToTreeData(+ template: IStructureGraphTemplate,+): TreeDataItem[] {+ return buildTreeDataItems(template.entities, template.relations, ['include']);+}++export function adaptTreeToTreeData(+ template: IStructureGraphTemplate,+): TreeDataItem[] {+ return buildTreeDataItems(template.entities, template.relations, ['child']);+}++function filterTreeDataItems(+ items: TreeDataItem[],+ keyword: string,+): TreeDataItem[] {+ const lowerKeyword = keyword.toLowerCase();++ return items.reduce<TreeDataItem[]>((acc, item) => {+ const children = item.children+ ? filterTreeDataItems(item.children, keyword)+ : [];+ const matches = item.name.toLowerCase().includes(lowerKeyword);++ if (matches || children.length > 0) {+ acc.push({+ ...item,+ children: children.length > 0 ? children : item.children,+ });+ }++ return acc;+ }, []);+}++export function filterTreeDataByKeyword(+ data: TreeDataItem[],+ keyword: string,+): TreeDataItem[] {+ if (!keyword.trim()) return data;+ return filterTreeDataItems(data, keyword);+}++export function adaptKnowledgeGraphToForceGraph(+ template: IStructureGraphTemplate,+): IArtifactGraph {+ const entities: IArtifactGraphEntity[] = template.entities.map((entity) => {+ const normalized = normalizeEntity(entity);+ return {+ slug: normalized.id,+ name: normalized.name,+ aliases: normalized.aliases ?? [],+ description: getEntityDescription(normalized),+ type: normalized.type ?? '',+ weight: normalized.mention_count ?? 0,+ source_chunk_ids: normalized.source_chunk_ids,+ };+ });++ const entityNames = new Set(entities.map((entity) => entity.slug));++ return {+ entities,+ relations: template.relations+ .filter(+ (relation) =>+ // Only keep relations whose source and target entities both exist in the graph.+ entityNames.has(relation.from) && entityNames.has(relation.to),+ )+ .map((relation) => ({+ from: relation.from,+ to: relation.to,+ })),+ };+}++function treeDataItemToG6TreeData(item: TreeDataItem): TreeData {+ const node: TreeData = {+ id: item.id,+ source_chunk_ids: item.source_chunk_ids,+ };++ if (item.children && item.children.length > 0) {+ node.children = item.children.map(treeDataItemToG6TreeData);+ }++ return node;+}++export interface TimelineX6NodeData {+ id: string;+ shape: 'rect' | 'circle';+ width: number;+ height: number;+ label: string;+ data?: IStructureGraphEntity;+ attrs?: Record<string, unknown>;+}++export interface TimelineX6EdgeData {+ id: string;+ shape: 'edge';+ source: string;+ target: string;+ attrs?: Record<string, unknown>;+}++export function adaptTimelineToX6Data(template: IStructureGraphTemplate): {+ nodes: TimelineX6NodeData[];+ edges: TimelineX6EdgeData[];+} {+ const normalized = template.entities+ .map(normalizeEntity)+ .filter((entity) => entity.id);+ const entityIds = new Set(normalized.map((entity) => entity.id));++ const nodes = normalized.map((entity) => {+ const isTimestamp = entity.type === 'timestamp';+ return {+ id: entity.id,+ shape: isTimestamp ? ('circle' as const) : ('rect' as const),+ width: isTimestamp ? 96 : 200,+ height: isTimestamp ? 96 : 80,+ label: entity.name,+ data: entity,+ attrs: {+ body: {+ fill: isTimestamp ? '#e6f7ff' : '#fff7e6',+ stroke: isTimestamp ? '#1890ff' : '#fa8c16',+ rx: isTimestamp ? 48 : 8,+ ry: isTimestamp ? 48 : 8,+ },+ label: {+ fill: '#262626',+ fontSize: 12,+ textWrap: {+ width: isTimestamp ? 80 : 180,+ height: isTimestamp ? 80 : 64,+ ellipsis: true,+ },+ },+ },+ };+ });++ const edges = template.relations+ .filter(+ (relation) => entityIds.has(relation.from) && entityIds.has(relation.to),+ )+ .map((relation, index) => ({+ id: `timeline-edge-${index}`,+ shape: 'edge' as const,+ source: relation.from,+ target: relation.to,+ attrs: {+ line: {+ stroke: '#8c8c8c',+ strokeWidth: 1,+ targetMarker: 'classic',+ },+ },+ }));++ return { nodes, edges };+}++export function adaptMindMapToIndentedTree(+ template: IStructureGraphTemplate,+): TreeData {+ const roots = buildTreeDataItems(template.entities, template.relations, [+ 'has_branch',+ 'has_sub_branch',+ ]);++ const g6Roots = roots.map(treeDataItemToG6TreeData);++ if (g6Roots.length === 1) {+ return g6Roots[0]!;+ }++ return {+ id: 'mindmap-root',+ children: g6Roots,+ };+}diff --git a/web/src/pages/dataset/compilation/constants.ts b/web/src/pages/dataset/compilation/constants.tsnew file mode 100644index 0000000000..387f011e22--- /dev/null+++ b/web/src/pages/dataset/compilation/constants.ts@@ -0,0 +1,10 @@+export enum ViewMode {+ Graph = 'graph',+ LlmWiki = 'llm-wiki',+ Skills = 'skills',+}++export enum LeftPanelTab {+ Contents = 'contents',+ Graph = 'graph',+}diff --git a/web/src/pages/dataset/compilation/create-directory-dialog/create-directory-form.tsx b/web/src/pages/dataset/compilation/create-directory-dialog/create-directory-form.tsxnew file mode 100644index 0000000000..1d7b0981f3--- /dev/null+++ b/web/src/pages/dataset/compilation/create-directory-dialog/create-directory-form.tsx@@ -0,0 +1,25 @@+'use client';++import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Input } from '@/components/ui/input';+import { Textarea } from '@/components/ui/textarea';+import { useTranslation } from 'react-i18next';++export function CreateDirectoryFormFields() {+ const { t } = useTranslation();++ return (+ <div className="space-y-4">+ <RAGFlowFormItem+ name="name"+ label={t('knowledgeDetails.directoryName')}+ required+ >+ <Input placeholder={t('common.pleaseInput')} autoComplete="off" />+ </RAGFlowFormItem>+ <RAGFlowFormItem name="rule" label={t('knowledgeDetails.directoryRule')}>+ <Textarea placeholder={t('common.pleaseInput')} />+ </RAGFlowFormItem>+ </div>+ );+}diff --git a/web/src/pages/dataset/compilation/create-directory-dialog/index.tsx b/web/src/pages/dataset/compilation/create-directory-dialog/index.tsxnew file mode 100644index 0000000000..90d91ac397--- /dev/null+++ b/web/src/pages/dataset/compilation/create-directory-dialog/index.tsx@@ -0,0 +1,51 @@+'use client';++import { Form } from '@/components/ui/form';+import { Modal } from '@/components/ui/modal/modal';+import { UseFormReturn } from 'react-hook-form';+import { useTranslation } from 'react-i18next';+import { CreateDirectoryFormValues } from '../interface';+import { CreateDirectoryFormFields } from './create-directory-form';++export interface CreateDirectoryDialogProps {+ open: boolean;+ loading: boolean;+ form: UseFormReturn<CreateDirectoryFormValues>;+ onOk: (values: CreateDirectoryFormValues) => void;+ onCancel: () => void;+}++export function CreateDirectoryDialog({+ open,+ loading,+ form,+ onOk,+ onCancel,+}: CreateDirectoryDialogProps) {+ const { t } = useTranslation();++ const handleOk = () => {+ form.handleSubmit(onOk)();+ };++ const handleOpenChange = (val: boolean) => {+ if (!val) {+ onCancel();+ }+ };++ return (+ <Modal+ open={open}+ onOpenChange={handleOpenChange}+ title={t('knowledgeDetails.createDirectoryFolder')}+ onOk={handleOk}+ onCancel={onCancel}+ confirmLoading={loading}+ >+ <Form {...form}>+ <CreateDirectoryFormFields />+ </Form>+ </Modal>+ );+}diff --git a/web/src/pages/dataset/compilation/empty-state.tsx b/web/src/pages/dataset/compilation/empty-state.tsxnew file mode 100644index 0000000000..a1055c1c67--- /dev/null+++ b/web/src/pages/dataset/compilation/empty-state.tsx@@ -0,0 +1,132 @@+import { CirclePause, WandSparkles } from 'lucide-react';+import { useCallback } from 'react';+import { useTranslation } from 'react-i18next';++import { IconFontFill } from '@/components/icon-font';+import { Button } from '@/components/ui/button';+import { cn } from '@/lib/utils';+import {+ GenerateType,+ IconKeyMap,+} from '@/pages/dataset/dataset/generate-button/constants';+import {+ ITraceInfo,+ useDatasetGenerate,+} from '@/pages/dataset/dataset/generate-button/hook';+import { useGenerateStatus } from '@/pages/dataset/dataset/generate-button/use-generate-status';+import { replaceText } from '@/pages/dataset/process-log-modal';+import { toFixed } from '@/utils/common-util';++type EmptyStateType = 'llm-wiki' | 'skills';++interface ICompilationEmptyStateProps {+ type: EmptyStateType;+ disabled?: boolean;+ data?: ITraceInfo;+}++const DefaultGenerateTypeMap: Record<EmptyStateType, GenerateType> = {+ 'llm-wiki': GenerateType.Artifact,+ skills: GenerateType.ToSkills,+};++const TitleKeyMap: Record<EmptyStateType, string> = {+ 'llm-wiki': 'knowledgeDetails.noWikiPages',+ skills: 'knowledgeDetails.noSkills',+};++const LabelKeyMap: Record<EmptyStateType, string> = {+ 'llm-wiki': 'knowledgeDetails.artifact',+ skills: 'knowledgeDetails.toSkills',+};++export function CompilationEmptyState({+ type,+ disabled,+ data,+}: ICompilationEmptyStateProps) {+ const { t } = useTranslation();+ const generateType = DefaultGenerateTypeMap[type];+ const { runGenerate, pauseGenerate } = useDatasetGenerate();+ const { status, percent } = useGenerateStatus(data);++ const handleGenerate = useCallback(() => {+ runGenerate({ type: generateType }).catch(() => {});+ }, [runGenerate, generateType]);++ const handlePause = useCallback(() => {+ if (data?.id) {+ pauseGenerate({ task_id: data.id, type: generateType }).catch(() => {});+ }+ }, [pauseGenerate, data?.id, generateType]);++ const showProgress = status === 'running' || status === 'failed';++ return (+ <div className="flex-1 min-h-0 flex flex-col items-center justify-center border border-dashed border-border-button rounded-xl">+ {!showProgress ? (+ <div className="flex flex-col items-center gap-4">+ <p className="text-text-secondary text-lg">{t(TitleKeyMap[type])}</p>+ <Button+ variant="outline"+ onClick={handleGenerate}+ disabled={disabled}+ >+ <WandSparkles className="mr-2 size-4" />+ {t('knowledgeDetails.generate')}+ </Button>+ </div>+ ) : (+ <div className="w-full max-w-md p-6 flex flex-col gap-4">+ <div className="flex items-center gap-2 text-text-primary">+ <IconFontFill+ name={IconKeyMap[generateType]}+ className="text-accent-primary"+ />+ <span>{t(LabelKeyMap[type])}</span>+ </div>+ <div className="flex items-center gap-2">+ <div+ className={cn('bg-border-button h-1 rounded-full', {+ 'w-[calc(100%-100px)]': status === 'running',+ 'w-[calc(100%-50px)]': status === 'failed',+ })}+ >+ <div+ className={cn('h-1 rounded-full', {+ 'bg-state-error': status === 'failed',+ 'bg-accent-primary': status === 'running',+ })}+ style={{ width: `${toFixed(percent)}%` }}+ />+ </div>+ {status === 'running' && (+ <span>{(toFixed(percent) as string) + '%'}</span>+ )}+ {status === 'failed' && (+ <span+ className="text-state-error cursor-pointer"+ onClick={handleGenerate}+ >+ <IconFontFill name="reparse" className="text-accent-primary" />+ </span>+ )}+ {status !== 'failed' && (+ <span+ className="text-state-error cursor-pointer"+ onClick={handlePause}+ >+ <CirclePause />+ </span>+ )}+ </div>+ <div className="whitespace-pre-line text-wrap rounded-lg max-h-[350px] overflow-y-auto scrollbar-auto p-2 bg-bg-base text-sm text-text-secondary">+ {replaceText(data?.progress_msg || '')}+ </div>+ </div>+ )}+ </div>+ );+}++export default CompilationEmptyState;diff --git a/web/src/pages/dataset/compilation/hooks/use-commit-artifact.ts b/web/src/pages/dataset/compilation/hooks/use-commit-artifact.tsnew file mode 100644index 0000000000..4a72559120--- /dev/null+++ b/web/src/pages/dataset/compilation/hooks/use-commit-artifact.ts@@ -0,0 +1,80 @@+import { useUpdateArtifactPage } from '@/hooks/use-knowledge-request';+import { zodResolver } from '@hookform/resolvers/zod';+import { useCallback, useMemo, useState } from 'react';+import { useForm } from 'react-hook-form';+import { useTranslation } from 'react-i18next';+import { z } from 'zod';++import type { CommitFormValues } from '../interface';++type UseCommitArtifactParams = {+ editedContent: string;+ pageType: string;+ slug: string;+ onSuccess?: () => void;+};++export function useCommitArtifact({+ editedContent,+ pageType,+ slug,+ onSuccess,+}: UseCommitArtifactParams) {+ const { t } = useTranslation();+ const { updateArtifactPage, loading: isUpdating } = useUpdateArtifactPage();+ const [isOpen, setIsOpen] = useState(false);++ const CommitFormSchema = useMemo(+ () =>+ z.object({+ comments: z.string().min(1, {+ message: t('knowledgeDetails.versionContentRequired'),+ }),+ }),+ [t],+ );++ const form = useForm<CommitFormValues>({+ resolver: zodResolver(CommitFormSchema),+ defaultValues: { comments: '' },+ });++ const open = useCallback(() => {+ form.reset({ comments: '' });+ setIsOpen(true);+ }, [form]);++ const close = useCallback(() => {+ setIsOpen(false);+ }, []);++ const handleConfirm = useCallback(+ async (values: CommitFormValues) => {+ if (!pageType || !slug) return;++ const result = await updateArtifactPage({+ pageType,+ slug,+ body: {+ content_md: editedContent,+ comments: values.comments,+ },+ });++ if (result?.code === 0) {+ onSuccess?.();+ setIsOpen(false);+ }+ },+ [editedContent, onSuccess, pageType, slug, updateArtifactPage],+ );++ return {+ isOpen,+ open,+ close,+ form,+ handleConfirm,+ isUpdating,+ };+}diff --git a/web/src/pages/dataset/compilation/hooks/use-compilation-artifact.ts b/web/src/pages/dataset/compilation/hooks/use-compilation-artifact.tsnew file mode 100644index 0000000000..de180127a3--- /dev/null+++ b/web/src/pages/dataset/compilation/hooks/use-compilation-artifact.ts@@ -0,0 +1,32 @@+import { IArtifact } from '@/interfaces/database/dataset';+import { useCallback, useState } from 'react';+import { useWikiVersion } from './use-wiki-version';++export function useCompilationArtifact() {+ const [selectedArtifact, setSelectedArtifact] = useState<IArtifact | null>(+ null,+ );+ const { selectedVersion, selectVersion, clearVersion } = useWikiVersion();++ const handleSelectArtifact = useCallback(+ (artifact: IArtifact) => {+ setSelectedArtifact(artifact);+ clearVersion();+ },+ [clearVersion],+ );++ const clearSelectedArtifact = useCallback(() => {+ setSelectedArtifact(null);+ clearVersion();+ }, [clearVersion]);++ return {+ selectedArtifact,+ selectedVersion,+ selectVersion,+ clearVersion,+ handleSelectArtifact,+ clearSelectedArtifact,+ };+}diff --git a/web/src/pages/dataset/compilation/hooks/use-compilation-skill.ts b/web/src/pages/dataset/compilation/hooks/use-compilation-skill.tsnew file mode 100644index 0000000000..703061ce47--- /dev/null+++ b/web/src/pages/dataset/compilation/hooks/use-compilation-skill.ts@@ -0,0 +1,20 @@+import {+ useFetchDatasetSkillPage,+ useFetchDatasetSkillTree,+} from '@/hooks/use-dataset-skill-request';+import { useState } from 'react';++export function useCompilationSkill() {+ const [selectedSkill, setSelectedSkill] = useState<string | null>(null);+ const { data: skillTree, loading: skillTreeLoading } =+ useFetchDatasetSkillTree();+ const { data: skillPage } = useFetchDatasetSkillPage(selectedSkill);++ return {+ selectedSkill,+ setSelectedSkill,+ skillTree,+ skillTreeLoading,+ skillPage,+ };+}diff --git a/web/src/pages/dataset/compilation/hooks/use-compilation-view.ts b/web/src/pages/dataset/compilation/hooks/use-compilation-view.tsnew file mode 100644index 0000000000..4a529e0521--- /dev/null+++ b/web/src/pages/dataset/compilation/hooks/use-compilation-view.ts@@ -0,0 +1,67 @@+import { DatasetSkillKeys } from '@/hooks/use-dataset-skill-request';+import { ArtifactKeys, ArtifactTopicKeys } from '@/hooks/use-knowledge-request';+import { useTraceGenerate } from '@/pages/dataset/dataset/generate-button/hook';+import { useGenerateStatus } from '@/pages/dataset/dataset/generate-button/use-generate-status';+import { useQueryClient } from '@tanstack/react-query';+import { useCallback, useEffect, useState } from 'react';+import { useParams } from 'react-router';+import { LeftPanelTab, ViewMode } from '../constants';++export function useCompilationView() {+ const { id } = useParams();+ const queryClient = useQueryClient();+ const [leftTab, setLeftTab] = useState<LeftPanelTab>(LeftPanelTab.Contents);+ const [viewMode, setViewMode] = useState<ViewMode>(ViewMode.LlmWiki);++ const { artifactRunData, skillRunData } = useTraceGenerate({ open: true });+ const { status: artifactStatus } = useGenerateStatus(artifactRunData);+ const { status: skillStatus } = useGenerateStatus(skillRunData);++ useEffect(() => {+ if (viewMode === ViewMode.LlmWiki && artifactStatus === 'completed') {+ queryClient.invalidateQueries({+ queryKey: ArtifactKeys.listByDataset(id!),+ });+ queryClient.invalidateQueries({+ queryKey: ArtifactTopicKeys.listByDataset(id!),+ });+ }+ }, [viewMode, artifactStatus, queryClient, id]);++ useEffect(() => {+ if (viewMode === ViewMode.Skills && skillStatus === 'completed') {+ queryClient.invalidateQueries({+ queryKey: DatasetSkillKeys.tree(id!),+ });+ }+ }, [viewMode, skillStatus, queryClient, id]);++ const handleSwitchToGraph = useCallback(() => {+ setViewMode(ViewMode.Graph);+ }, []);++ const handleSwitchToLlmWiki = useCallback(() => {+ setViewMode(ViewMode.LlmWiki);+ }, []);++ const handleSwitchToSkills = useCallback(() => {+ setViewMode(ViewMode.Skills);+ }, []);++ const handleLeftTabChange = useCallback((value: string) => {+ setLeftTab(value as LeftPanelTab);+ }, []);++ return {+ leftTab,+ viewMode,+ artifactRunData,+ skillRunData,+ artifactStatus,+ skillStatus,+ handleSwitchToGraph,+ handleSwitchToLlmWiki,+ handleSwitchToSkills,+ handleLeftTabChange,+ };+}diff --git a/web/src/pages/dataset/compilation/hooks/use-create-directory.ts b/web/src/pages/dataset/compilation/hooks/use-create-directory.tsnew file mode 100644index 0000000000..839686c25c--- /dev/null+++ b/web/src/pages/dataset/compilation/hooks/use-create-directory.ts@@ -0,0 +1,59 @@+import { zodResolver } from '@hookform/resolvers/zod';+import { useCallback, useMemo, useState } from 'react';+import { useForm } from 'react-hook-form';+import { z } from 'zod';++import type { CreateDirectoryFormValues } from '../interface';++export function useCreateDirectory() {+ const [open, setOpen] = useState(false);+ const [loading, setLoading] = useState(false);++ const FormSchema = useMemo(+ () =>+ z.object({+ name: z.string().min(1).trim(),+ rule: z.string().optional(),+ }),+ [],+ );++ const form = useForm<CreateDirectoryFormValues>({+ resolver: zodResolver(FormSchema),+ defaultValues: { name: '', rule: '' },+ });++ const showModal = useCallback(() => {+ form.reset({ name: '', rule: '' });+ setOpen(true);+ }, [form]);++ const hideModal = useCallback(() => {+ setOpen(false);+ form.reset({ name: '', rule: '' });+ }, [form]);++ const handleOk = useCallback(+ async (values: CreateDirectoryFormValues) => {+ setLoading(true);+ try {+ // TODO: Replace with real API call+ console.log('Create directory:', values);+ setOpen(false);+ form.reset({ name: '', rule: '' });+ } finally {+ setLoading(false);+ }+ },+ [form],+ );++ return {+ open,+ loading,+ form,+ showModal,+ hideModal,+ handleOk,+ };+}diff --git a/web/src/pages/dataset/compilation/hooks/use-wiki-editor.ts b/web/src/pages/dataset/compilation/hooks/use-wiki-editor.tsnew file mode 100644index 0000000000..d5da8b4a06--- /dev/null+++ b/web/src/pages/dataset/compilation/hooks/use-wiki-editor.ts@@ -0,0 +1,41 @@+import { useCallback, useEffect, useState } from 'react';++type UseWikiEditorParams = {+ content: string;+ artifactSlug?: string;+};++export function useWikiEditor({ content, artifactSlug }: UseWikiEditorParams) {+ const [editedContent, setEditedContent] = useState(content);+ const [isDirty, setIsDirty] = useState(false);++ useEffect(() => {+ setEditedContent(content);+ setIsDirty(false);+ }, [content, artifactSlug]);++ const handleContentChange = useCallback(+ (value: string) => {+ setEditedContent(value);+ setIsDirty(value !== content);+ },+ [content],+ );++ const handleCancelEdit = useCallback(() => {+ setEditedContent(content);+ setIsDirty(false);+ }, [content]);++ const handleMarkAsSaved = useCallback(() => {+ setIsDirty(false);+ }, []);++ return {+ editedContent,+ isDirty,+ handleContentChange,+ handleCancelEdit,+ handleMarkAsSaved,+ };+}diff --git a/web/src/pages/dataset/compilation/hooks/use-wiki-version.ts b/web/src/pages/dataset/compilation/hooks/use-wiki-version.tsnew file mode 100644index 0000000000..0c23aee44f--- /dev/null+++ b/web/src/pages/dataset/compilation/hooks/use-wiki-version.ts@@ -0,0 +1,30 @@+import { IWikiCommit } from '@/interfaces/database/dataset';+import { useCallback, useState } from 'react';++type UseWikiVersionReturn = {+ selectedVersionId: string | null;+ selectedVersion: IWikiCommit | null;+ selectVersion: (version: IWikiCommit | null) => void;+ clearVersion: () => void;+};++export function useWikiVersion(): UseWikiVersionReturn {+ const [selectedVersion, setSelectedVersion] = useState<IWikiCommit | null>(+ null,+ );++ const selectVersion = useCallback((version: IWikiCommit | null) => {+ setSelectedVersion(version);+ }, []);++ const clearVersion = useCallback(() => {+ setSelectedVersion(null);+ }, []);++ return {+ selectedVersionId: selectedVersion?.id ?? null,+ selectedVersion,+ selectVersion,+ clearVersion,+ };+}diff --git a/web/src/pages/dataset/compilation/index.tsx b/web/src/pages/dataset/compilation/index.tsxnew file mode 100644index 0000000000..042bc017a6--- /dev/null+++ b/web/src/pages/dataset/compilation/index.tsx@@ -0,0 +1,194 @@+import BackButton from '@/components/back-button';+import MarkdownEditor from '@/components/markdown-editor';+import { RAGFlowAvatar } from '@/components/ragflow-avatar';+import { SkeletonCard } from '@/components/skeleton-card';+import { Button } from '@/components/ui/button';+import { Card } from '@/components/ui/card';+import {+ ResizableHandle,+ ResizablePanel,+ ResizablePanelGroup,+} from '@/components/ui/resizable';+import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';+import {+ useFetchArtifactTopicList,+ useFetchKnowledgeBaseConfiguration,+ useFetchKnowledgeGraph,+} from '@/hooks/use-knowledge-request';+import { Routes } from '@/routes';+import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';++import { ViewMode } from './constants';+import CompilationEmptyState from './empty-state';+import { useCompilationArtifact } from './hooks/use-compilation-artifact';+import { useCompilationSkill } from './hooks/use-compilation-skill';+import { useCompilationView } from './hooks/use-compilation-view';+import KnowledgeForceGraph from './knowledge-force-graph';+import { SkillsLeftPanel } from './skills-left-panel';+import { WikiDetailContent } from './wiki-detail-content';+import { WikiLeftPanel } from './wiki-left-panel';++export default function Compilation() {+ const { t } = useTranslation();+ const { id } = useParams();+ const { navigateToDataFile } = useNavigatePage();+ const { data: knowledgeBase } = useFetchKnowledgeBaseConfiguration();+ const { data: knowledgeGraph, loading: knowledgeGraphLoading } =+ useFetchKnowledgeGraph();+ const { topics, loading: topicListLoading } = useFetchArtifactTopicList();++ const {+ leftTab,+ viewMode,+ artifactRunData,+ skillRunData,+ handleSwitchToLlmWiki,+ handleSwitchToSkills,+ handleLeftTabChange,+ } = useCompilationView();++ const {+ selectedArtifact,+ selectedVersion,+ selectVersion,+ handleSelectArtifact,+ clearSelectedArtifact,+ } = useCompilationArtifact();++ const {+ selectedSkill,+ setSelectedSkill,+ skillTree,+ skillTreeLoading,+ skillPage,+ } = useCompilationSkill();++ const isLlmWikiEmpty = topics.length === 0 && !topicListLoading;+ const canGenerate = (knowledgeBase?.chunk_count ?? 0) > 0;++ const isGraphLoading = knowledgeGraphLoading && !knowledgeGraph?.graph;+ const isLlmWikiLoading = topicListLoading && topics.length === 0;+ const isSkillsLoading =+ skillTreeLoading && !skillTree?.skill_with_weight?.length;+ const isSkillsEmpty =+ !skillTree?.skill_with_weight?.length && !skillTreeLoading;++ const loadingCard = (+ <Card className="flex-1 min-h-0 overflow-hidden flex border-border-button rounded-xl flex-col p-8">+ <SkeletonCard className="flex-1" />+ </Card>+ );++ return (+ <section className="flex flex-col p-4 gap-4 h-full">+ <header className="space-y-5">+ <BackButton+ to={`${Routes.DatasetBase}${Routes.Files}/${id}`}+ onClick={navigateToDataFile(id!)}+ >+ {t('common.back')}+ </BackButton>++ <section className="flex items-center justify-between">+ <div className="flex items-center gap-3">+ <RAGFlowAvatar+ avatar={knowledgeBase?.avatar}+ name={knowledgeBase?.name}+ className="size-10 rounded-lg"+ />+ <h2 className="text-xl font-medium text-text-primary">+ {knowledgeBase?.name}+ {t('knowledgeDetails.compilationTitleSuffix')}+ </h2>+ </div>++ <div className="flex items-center gap-2">+ <Button+ variant={viewMode === ViewMode.LlmWiki ? 'default' : 'outline'}+ size="sm"+ onClick={handleSwitchToLlmWiki}+ >+ {t('knowledgeDetails.llmWiki')}+ </Button>+ <Button+ variant={viewMode === ViewMode.Skills ? 'default' : 'outline'}+ size="sm"+ onClick={handleSwitchToSkills}+ >+ {t('knowledgeDetails.skills')}+ </Button>+ </div>+ </section>+ </header>++ {viewMode === ViewMode.Graph ? (+ isGraphLoading ? (+ loadingCard+ ) : (+ <div className="flex-1 min-h-0 flex flex-col">+ <KnowledgeForceGraph data={knowledgeGraph?.graph} show />+ </div>+ )+ ) : viewMode === ViewMode.LlmWiki ? (+ isLlmWikiLoading ? (+ loadingCard+ ) : isLlmWikiEmpty ? (+ <CompilationEmptyState+ type="llm-wiki"+ disabled={!canGenerate}+ data={artifactRunData}+ />+ ) : (+ <Card className="flex-1 min-h-0 overflow-hidden flex border-border-button rounded-xl flex-col">+ <ResizablePanelGroup direction="horizontal" className="flex-1">+ <ResizablePanel defaultSize={33} minSize={20} maxSize={50}>+ <WikiLeftPanel+ tab={leftTab}+ onTabChange={handleLeftTabChange}+ selectedArtifact={selectedArtifact}+ onSelectArtifact={handleSelectArtifact}+ onClearWiki={clearSelectedArtifact}+ />+ </ResizablePanel>+ <ResizableHandle withHandle />+ <ResizablePanel>+ <WikiDetailContent+ selectedArtifact={selectedArtifact}+ selectedVersion={selectedVersion}+ onSelectVersion={selectVersion}+ />+ </ResizablePanel>+ </ResizablePanelGroup>+ </Card>+ )+ ) : isSkillsLoading ? (+ loadingCard+ ) : isSkillsEmpty ? (+ <CompilationEmptyState+ type="skills"+ disabled={!canGenerate}+ data={skillRunData}+ />+ ) : (+ <Card className="flex-1 min-h-0 overflow-hidden flex border-border-button rounded-xl flex-col">+ <ResizablePanelGroup direction="horizontal" className="flex-1">+ <ResizablePanel defaultSize={33} minSize={20} maxSize={50}>+ <SkillsLeftPanel+ selectedSkill={selectedSkill}+ onSelectSkill={setSelectedSkill}+ />+ </ResizablePanel>+ <ResizableHandle withHandle />+ <ResizablePanel className="flex flex-col">+ <MarkdownEditor+ content={skillPage?.md_with_weight ?? ''}+ readOnly+ />+ </ResizablePanel>+ </ResizablePanelGroup>+ </Card>+ )}+ </section>+ );+}diff --git a/web/src/pages/dataset/compilation/interface.ts b/web/src/pages/dataset/compilation/interface.tsnew file mode 100644index 0000000000..1d0a4a582d--- /dev/null+++ b/web/src/pages/dataset/compilation/interface.ts@@ -0,0 +1,20 @@+export interface CreateDirectoryFormValues {+ name: string;+ rule: string;+}++export type CommitFormValues = {+ comments: string;+};++export type WikiDiffLineType = 'added' | 'removed' | 'context' | 'header';++export type WikiDiffLine = {+ type: WikiDiffLineType;+ content: string;+};++export type WikiDiffHunk = {+ header: string;+ lines: WikiDiffLine[];+};diff --git a/web/src/pages/dataset/compilation/knowledge-force-graph.tsx b/web/src/pages/dataset/compilation/knowledge-force-graph.tsxnew file mode 100644index 0000000000..fdb338324d--- /dev/null+++ b/web/src/pages/dataset/compilation/knowledge-force-graph.tsx@@ -0,0 +1,347 @@+import { useIsDarkTheme } from '@/components/theme-provider';+import { cn } from '@/lib/utils';+import isEmpty from 'lodash/isEmpty';+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';+import ForceGraph2D, { LinkObject, NodeObject } from 'react-force-graph-2d';++import { buildNodesAndCombos } from '../knowledge-graph/util';++interface IProps {+ data: any;+ show: boolean;+}++interface NodeData {+ rank?: number;+ entity_type?: string;+ description?: string;+ weight?: number;+ communities?: string[];+ combo?: string;+ __bckgDimensions?: [number, number];+}++interface LinkData {+ weight?: number;+}++type GNode = NodeObject<NodeData>;+type GLink = LinkObject<NodeData, LinkData>;++const NodeColorPalette = [+ '#5B8FF9',+ '#5AD8A6',+ '#F6BD16',+ '#E8684A',+ '#6DC8EC',+ '#9270CA',+ '#FF9D4D',+ '#269A99',+ '#FF99C3',+ '#A9A9A9',+];++const getNodeSize = (node: GNode) => {+ const size = 180 + ((node.rank as number) || 0) * 5;+ return Math.min(size, 300) / 2;+};++const getLinkWidth = (link: GLink) => {+ const weight = Number(link.weight) || 2;+ return Math.min(weight * 4, 8);+};++export function KnowledgeForceGraph({ data, show }: IProps) {+ const containerRef = useRef<HTMLDivElement>(null);+ const fgRef = useRef<any>(null);+ const isDark = useIsDarkTheme();+ const [hoverNode, setHoverNode] = useState<GNode | null>(null);+ const [dimensions, setDimensions] = useState({ width: 0, height: 0 });+ const forceConfiguredRef = useRef(false);++ const graphData = useMemo(() => {+ if (isEmpty(data)) {+ return { nodes: [], links: [] };+ }++ const rawNodes = data.nodes || [];+ const rawEdges = data.edges || [];+ const { nodes: comboNodes } = buildNodesAndCombos(rawNodes);++ const entityTypes = Array.from(+ new Set(rawNodes.map((n: any) => n.entity_type).filter(Boolean)),+ );++ const typeColorMap = entityTypes.reduce<Record<string, string>>(+ (pre, cur, idx) => {+ pre[cur as string] = NodeColorPalette[idx % NodeColorPalette.length];+ return pre;+ },+ {},+ );++ const nodes = comboNodes.map((n: any) => ({+ ...n,+ color: typeColorMap[n.entity_type as string] || NodeColorPalette[0],+ }));++ const links = rawEdges.map((e: any) => ({+ source: e.source,+ target: e.target,+ weight: e.weight,+ }));++ return { nodes, links };+ }, [data]);++ // Compute the set of node IDs directly connected to the hovered node (degree: 1)+ const connectedNodeIds = useMemo(() => {+ if (!hoverNode) return new Set<string>();+ const ids = new Set<string>();+ ids.add(hoverNode.id as string);+ graphData.links.forEach((link: any) => {+ const sourceId =+ typeof link.source === 'object' ? link.source.id : link.source;+ const targetId =+ typeof link.target === 'object' ? link.target.id : link.target;+ if (sourceId === hoverNode.id) ids.add(targetId as string);+ if (targetId === hoverNode.id) ids.add(sourceId as string);+ });+ return ids;+ }, [hoverNode, graphData.links]);++ useEffect(() => {+ if (!containerRef.current || !show) return;++ const observer = new ResizeObserver((entries) => {+ const entry = entries[0];+ if (entry) {+ const { width, height } = entry.contentRect;+ setDimensions({ width, height });+ }+ });++ observer.observe(containerRef.current);+ return () => observer.disconnect();+ }, [show]);++ // Reset the flag when graphData changes, so forces are reconfigured for new data+ useEffect(() => {+ forceConfiguredRef.current = false;+ }, [graphData]);++ useEffect(() => {+ if (+ fgRef.current &&+ !isEmpty(graphData.nodes) &&+ !forceConfiguredRef.current+ ) {+ forceConfiguredRef.current = true;+ // D3 force configuration+ const linkForce = fgRef.current.d3Force('link');+ if (linkForce) {+ linkForce.distance((link: GLink) => {+ const source =+ typeof link.source === 'object'+ ? (link.source as GNode)+ : (graphData.nodes.find(+ (n: GNode) => n.id === link.source,+ ) as GNode);+ const target =+ typeof link.target === 'object'+ ? (link.target as GNode)+ : (graphData.nodes.find(+ (n: GNode) => n.id === link.target,+ ) as GNode);+ const sourceSize = source ? getNodeSize(source) : 16;+ const targetSize = target ? getNodeSize(target) : 16;+ return sourceSize + targetSize + 200;+ });+ }++ const chargeForce = fgRef.current.d3Force('charge');+ if (chargeForce) {+ chargeForce.strength(-1000);+ }++ const timer = setTimeout(() => {+ fgRef.current?.zoomToFit(400, 50);+ }, 600);+ return () => clearTimeout(timer);+ }+ }, [graphData, dimensions]);++ const getNodeLabel = useCallback((node: GNode) => {+ const parts = [`<h3 class="font-semibold">${node.id}</h3>`];++ if (node.entity_type) {+ parts.push(+ `<div class="flex items-center gap-[.5ch]"><dt><b>Entity type: </b></dt><dd>${node.entity_type}</dd></div>`,+ );+ }++ if (node.weight) {+ parts.push(+ `<div class="flex items-center gap-[.5ch]"><dt><b>Weight: </b></dt><dd>${node.weight}</dd></div>`,+ );+ }++ if (node.description) {+ parts.push(+ `<p class="text-xs mt-1 max-w-[240px]">${node.description}</p>`,+ );+ }++ return `<dl class="mb-1 empty:hidden">${parts.join('')}</dl>`;+ }, []);++ const getLinkLabel = useCallback((link: GLink) => {+ const sourceId =+ typeof link.source === 'object' ? link.source.id : link.source;+ const targetId =+ typeof link.target === 'object' ? link.target.id : link.target;+ return `${sourceId} → ${targetId}`;+ }, []);++ const nodeCanvasObject = useCallback(+ (node: GNode, ctx: CanvasRenderingContext2D, globalScale: number) => {+ const size = getNodeSize(node);+ const label = (node.id as string) || '';+ const fontSize = Math.max(12 / globalScale, Math.min(size / 2, 40));++ // Dim non-connected nodes when hovering+ const isDimmed = hoverNode && !connectedNodeIds.has(node.id as string);+ ctx.globalAlpha = isDimmed ? 0.1 : 1;++ // Node circle (solid fill by entity_type color)+ const nodeColor = (node as any).color || NodeColorPalette[0];+ ctx.beginPath();+ ctx.arc(node.x!, node.y!, size, 0, 2 * Math.PI);+ ctx.fillStyle = nodeColor;+ ctx.fill();+ ctx.strokeStyle = isDark ? 'rgba(255,255,255,0.3)' : 'rgba(0,0,0,0.2)';+ ctx.lineWidth = Math.max(2 / globalScale, 3);+ ctx.stroke();++ // Only show label on hover+ if (hoverNode?.id === node.id) {+ ctx.font = `${fontSize}px Sans-Serif`;+ const textWidth = ctx.measureText(label).width;+ const padding = fontSize * 0.4;+ const bckgDimensions: [number, number] = [+ textWidth + padding * 2,+ fontSize + padding * 2,+ ];++ // Label background+ ctx.fillStyle = isDark+ ? 'rgba(0, 0, 0, 0.1)'+ : 'rgba(255, 255, 255, 0.1)';+ ctx.fillRect(+ node.x! - bckgDimensions[0] / 2,+ node.y! + size + fontSize / 2,+ bckgDimensions[0],+ bckgDimensions[1],+ );++ // Label text+ ctx.textAlign = 'center';+ ctx.textBaseline = 'middle';+ ctx.fillStyle = isDark ? '#fff' : '#000';+ ctx.fillText(label, node.x!, node.y! + size + fontSize);++ (node as any).__bckgDimensions = bckgDimensions;+ }++ ctx.globalAlpha = 1;+ },+ [isDark, hoverNode, connectedNodeIds],+ );++ const nodePointerAreaPaint = useCallback(+ (node: GNode, color: string, ctx: CanvasRenderingContext2D) => {+ const size = getNodeSize(node);+ ctx.fillStyle = color;+ ctx.beginPath();+ ctx.arc(node.x!, node.y!, size, 0, 2 * Math.PI);+ ctx.fill();+ },+ [],+ );++ const linkCanvasObject = useCallback(+ (link: GLink, ctx: CanvasRenderingContext2D) => {+ const source =+ typeof link.source === 'object'+ ? (link.source as GNode)+ : (graphData.nodes.find((n: GNode) => n.id === link.source) as GNode);+ const target =+ typeof link.target === 'object'+ ? (link.target as GNode)+ : (graphData.nodes.find((n: GNode) => n.id === link.target) as GNode);++ if (!source || !target) return;++ const isDimmed =+ hoverNode &&+ !(+ connectedNodeIds.has(source.id as string) &&+ connectedNodeIds.has(target.id as string)+ );+ ctx.globalAlpha = isDimmed ? 0.1 : 1;++ const lineWidth = getLinkWidth(link);+ ctx.lineWidth = lineWidth;+ ctx.strokeStyle = isDark ? 'rgba(255,255,255,0.5)' : 'rgba(0,0,0,0.5)';++ ctx.beginPath();+ ctx.moveTo(source.x!, source.y!);+ ctx.lineTo(target.x!, target.y!);+ ctx.stroke();+ ctx.globalAlpha = 1;+ },+ [graphData.nodes, hoverNode, connectedNodeIds, isDark],+ );++ const handleNodeHover = useCallback((node: GNode | null) => {+ setHoverNode(node);+ }, []);++ const backgroundColor = isDark ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)';++ return (+ <div+ ref={containerRef}+ className={cn('flex-1 min-h-0', !show && 'hidden')}+ aria-haspopup="true"+ >+ {dimensions.width > 0 && dimensions.height > 0 && (+ <ForceGraph2D+ ref={fgRef}+ width={dimensions.width}+ height={dimensions.height}+ graphData={graphData}+ backgroundColor={backgroundColor}+ nodeLabel={getNodeLabel}+ linkLabel={getLinkLabel}+ nodeRelSize={1}+ nodeCanvasObject={nodeCanvasObject}+ nodePointerAreaPaint={nodePointerAreaPaint}+ linkCanvasObject={linkCanvasObject}+ linkWidth={getLinkWidth}+ linkColor={() =>+ isDark ? 'rgba(255,255,255,0.5)' : 'rgba(0,0,0,0.5)'+ }+ onNodeHover={handleNodeHover}+ enableNodeDrag+ enableZoomInteraction+ enablePanInteraction+ warmupTicks={50}+ cooldownTicks={100}+ />+ )}+ </div>+ );+}++export default KnowledgeForceGraph;diff --git a/web/src/pages/dataset/compilation/skills-left-panel.tsx b/web/src/pages/dataset/compilation/skills-left-panel.tsxnew file mode 100644index 0000000000..3e1ce489f1--- /dev/null+++ b/web/src/pages/dataset/compilation/skills-left-panel.tsx@@ -0,0 +1,127 @@+import { SearchInput } from '@/components/ui/input';+import { Spin } from '@/components/ui/spin';+import { useFetchDatasetSkillTree } from '@/hooks/use-dataset-skill-request';+import { DatasetSkillTreeNode } from '@/interfaces/database/dataset-skill';+import { cn } from '@/lib/utils';+import { useDebounce } from 'ahooks';+import { useCallback, useMemo, useState } from 'react';+import { useTranslation } from 'react-i18next';++type FlatSkillNode = {+ skill_kwd: string;+ depth: number;+};++type SkillsLeftPanelProps = {+ selectedSkill: string | null;+ onSelectSkill: (skillKwd: string) => void;+};++function flattenSkillTree(nodes: DatasetSkillTreeNode[] = []): FlatSkillNode[] {+ const result: FlatSkillNode[] = [];++ function walk(items: DatasetSkillTreeNode[], depth: number) {+ for (const item of items) {+ result.push({ skill_kwd: item.skill_kwd, depth });+ if (item.children_kwd?.length) {+ walk(item.children_kwd, depth + 1);+ }+ }+ }++ walk(nodes, 0);+ return result;+}++type SkillListItemProps = {+ item: FlatSkillNode;+ isSelected: boolean;+ onSelect: (skillKwd: string) => void;+};++function SkillListItem({ item, isSelected, onSelect }: SkillListItemProps) {+ const handleClick = useCallback(() => {+ onSelect(item.skill_kwd);+ }, [item.skill_kwd, onSelect]);++ return (+ <li+ onClick={handleClick}+ className={cn(+ 'flex items-center gap-2 px-3 py-2 rounded-md text-sm cursor-pointer',+ 'text-text-secondary hover:bg-bg-base hover:text-text-primary',+ isSelected && 'bg-bg-card text-text-primary',+ )}+ style={{ paddingLeft: `${item.depth * 16 + 12}px` }}+ >+ <span className="truncate">{item.skill_kwd}</span>+ </li>+ );+}++export function SkillsLeftPanel({+ selectedSkill,+ onSelectSkill,+}: SkillsLeftPanelProps) {+ const { t } = useTranslation();+ const { data: tree, loading } = useFetchDatasetSkillTree();+ const [searchString, setSearchString] = useState('');+ const debouncedSearchString = useDebounce(searchString, { wait: 500 });++ const allNodes = useMemo(+ () => flattenSkillTree(tree?.skill_with_weight),+ [tree?.skill_with_weight],+ );++ const filteredNodes = useMemo(() => {+ const keyword = debouncedSearchString.trim().toLowerCase();+ if (!keyword) return allNodes;+ return allNodes.filter((node) =>+ node.skill_kwd.toLowerCase().includes(keyword),+ );+ }, [allNodes, debouncedSearchString]);++ const handleSearchChange = useCallback(+ (e: React.ChangeEvent<HTMLInputElement>) => {+ setSearchString(e.target.value);+ },+ [],+ );++ return (+ <aside className="size-full flex flex-col">+ <div className="px-3 py-2">+ <SearchInput+ placeholder={t('common.search')}+ value={searchString}+ onChange={handleSearchChange}+ />+ </div>++ <div className="flex-1 min-h-0 overflow-y-auto px-3 pb-3">+ {loading && filteredNodes.length === 0 ? (+ <div className="py-8 flex justify-center">+ <Spin size="small" />+ </div>+ ) : filteredNodes.length === 0 ? (+ <div className="py-8 text-center text-sm text-text-secondary">+ {debouncedSearchString+ ? t('common.noData')+ : t('datasetSkill.empty')}+ </div>+ ) : (+ <ul className="space-y-1">+ {filteredNodes.map((item) => (+ <SkillListItem+ key={item.skill_kwd}+ item={item}+ isSelected={selectedSkill === item.skill_kwd}+ onSelect={onSelectSkill}+ />+ ))}+ </ul>+ )}+ </div>+ </aside>+ );+}diff --git a/web/src/pages/dataset/compilation/utils/parse-wiki-diff.ts b/web/src/pages/dataset/compilation/utils/parse-wiki-diff.tsnew file mode 100644index 0000000000..42646c498b--- /dev/null+++ b/web/src/pages/dataset/compilation/utils/parse-wiki-diff.ts@@ -0,0 +1,53 @@+import type {+ WikiDiffHunk,+ WikiDiffLine,+ WikiDiffLineType,+} from '../interface';++export function parseWikiDiff(diff: string): WikiDiffHunk[] {+ const rawLines = (diff || '').split('\n');+ const hunks: WikiDiffHunk[] = [];+ let currentHunk: WikiDiffHunk | null = null;++ for (const rawLine of rawLines) {+ if (rawLine.startsWith('@@')) {+ if (currentHunk) {+ hunks.push(currentHunk);+ }+ currentHunk = { header: rawLine, lines: [] };+ continue;+ }++ if (rawLine.startsWith('---') || rawLine.startsWith('+++')) {+ // File header — not rendered per-line.+ continue;+ }++ let type: WikiDiffLineType = 'context';+ let content = rawLine;++ if (rawLine.startsWith('+')) {+ type = 'added';+ content = rawLine.slice(1);+ } else if (rawLine.startsWith('-')) {+ type = 'removed';+ content = rawLine.slice(1);+ }++ if (currentHunk) {+ currentHunk.lines.push({ type, content });+ }+ }++ if (currentHunk) {+ hunks.push(currentHunk);+ }++ return hunks;+}++export function getWikiDiffChanges(hunks: WikiDiffHunk[]): WikiDiffLine[] {+ return hunks+ .flatMap((hunk) => hunk.lines)+ .filter((line) => line.type === 'added' || line.type === 'removed');+}diff --git a/web/src/pages/dataset/compilation/version-history-item.tsx b/web/src/pages/dataset/compilation/version-history-item.tsxnew file mode 100644index 0000000000..a20ffe3378--- /dev/null+++ b/web/src/pages/dataset/compilation/version-history-item.tsx@@ -0,0 +1,51 @@+import { IWikiCommit } from '@/interfaces/database/dataset';+import { cn } from '@/lib/utils';+import { formatDate } from '@/utils/date';++type VersionHistoryItemProps = {+ version: IWikiCommit;+ isSelected: boolean;+ onSelect: (version: IWikiCommit) => void;+};++export function VersionHistoryItem({+ version,+ isSelected,+ onSelect,+}: VersionHistoryItemProps) {+ const handleClick = () => {+ onSelect(version);+ };++ return (+ <button+ onClick={handleClick}+ className={cn(+ 'w-full text-left px-6 py-4 border-b border-border-button transition-colors rounded',+ isSelected ? 'bg-bg-card' : 'hover:bg-bg-card/50',+ )}+ >+ <div className="flex items-center gap-2 mb-1">+ <span className="text-text-primary truncate">{version.title}</span>+ <span+ className={cn(+ 'size-2 rounded-full shrink-0',+ isSelected ? 'bg-accent-primary' : 'bg-transparent',+ )}+ />+ </div>+ <div className="space-y-1">+ {version.comments && (+ <p className="text-text-secondary">{version.comments}</p>+ )}+ <div className="flex items-center gap-2 text-xs text-text-disabled">+ <span>{version.user_nickname}</span>+ <span>·</span>+ <time dateTime={formatDate(version.create_time)}>+ {formatDate(version.create_time)}+ </time>+ </div>+ </div>+ </button>+ );+}diff --git a/web/src/pages/dataset/compilation/version-history-sheet.tsx b/web/src/pages/dataset/compilation/version-history-sheet.tsxnew file mode 100644index 0000000000..1e8e15b32c--- /dev/null+++ b/web/src/pages/dataset/compilation/version-history-sheet.tsx@@ -0,0 +1,86 @@+import { Button } from '@/components/ui/button';+import {+ Sheet,+ SheetContent,+ SheetHeader,+ SheetTitle,+ SheetTrigger,+} from '@/components/ui/sheet';+import { Spin } from '@/components/ui/spin';+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@/components/ui/tooltip';+import { useFetchWikiCommits } from '@/hooks/use-knowledge-request';+import { IArtifact, IWikiCommit } from '@/interfaces/database/dataset';+import { ClipboardClock } from 'lucide-react';+import { useState } from 'react';+import { useTranslation } from 'react-i18next';+import { VersionHistoryItem } from './version-history-item';++type VersionHistorySheetProps = {+ selectedArtifact: IArtifact | null;+ selectedVersion: IWikiCommit | null;+ onSelectVersion: (version: IWikiCommit | null) => void;+};++export function VersionHistorySheet({+ selectedArtifact,+ selectedVersion,+ onSelectVersion,+}: VersionHistorySheetProps) {+ const { t } = useTranslation();+ const [isVersionHistoryOpen, setIsVersionHistoryOpen] = useState(false);+ const { commits, loading } = useFetchWikiCommits(+ selectedArtifact,+ isVersionHistoryOpen,+ );++ const handleSelect = (version: IWikiCommit) => {+ onSelectVersion(version);+ setIsVersionHistoryOpen(false);+ };++ return (+ <Sheet+ open={isVersionHistoryOpen}+ onOpenChange={setIsVersionHistoryOpen}+ modal={false}+ >+ <Tooltip>+ <TooltipTrigger asChild>+ <SheetTrigger asChild>+ <Button variant="ghost" size="icon" className="size-8">+ <ClipboardClock className="size-4" />+ </Button>+ </SheetTrigger>+ </TooltipTrigger>+ <TooltipContent>{t('knowledgeDetails.version')}</TooltipContent>+ </Tooltip>+ <SheetContent className="flex flex-col">+ <SheetHeader>+ <SheetTitle>{t('knowledgeDetails.versionHistory')}</SheetTitle>+ </SheetHeader>+ <div className="flex-1 overflow-y-auto">+ {loading && commits.length === 0 && (+ <div className="py-8 flex justify-center">+ <Spin size="large" />+ </div>+ )}+ {commits.map((version) => {+ const isSelected = selectedVersion?.id === version.id;+ return (+ <VersionHistoryItem+ key={version.id}+ version={version}+ isSelected={isSelected}+ onSelect={handleSelect}+ />+ );+ })}+ </div>+ </SheetContent>+ </Sheet>+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-commit-modal.tsx b/web/src/pages/dataset/compilation/wiki-commit-modal.tsxnew file mode 100644index 0000000000..c09e35cf17--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-commit-modal.tsx@@ -0,0 +1,56 @@+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Form } from '@/components/ui/form';+import { Modal } from '@/components/ui/modal/modal';+import { Textarea } from '@/components/ui/textarea';+import { UseFormReturn } from 'react-hook-form';+import { useTranslation } from 'react-i18next';+import { CommitFormValues } from './interface';++type WikiCommitModalProps = {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ form: UseFormReturn<CommitFormValues>;+ onConfirm: (values: CommitFormValues) => void;+ loading?: boolean;+};++export function WikiCommitModal({+ open,+ onOpenChange,+ form,+ onConfirm,+ loading,+}: WikiCommitModalProps) {+ const { t } = useTranslation();++ return (+ <Modal+ open={open}+ onOpenChange={onOpenChange}+ title={t('knowledgeDetails.confirmCommit')}+ onOk={() => form.handleSubmit(onConfirm)()}+ confirmLoading={loading}+ okText={t('common.confirm')}+ cancelText={t('common.cancel')}+ >+ <Form {...form}>+ <form className="space-y-4">+ <RAGFlowFormItem+ name="comments"+ label={t('knowledgeDetails.versionContent')}+ required+ rules={{ required: true }}+ >+ {(field) => (+ <Textarea+ placeholder={t('knowledgeDetails.versionContentPlaceholder')}+ {...field}+ autoSize={{ minRows: 4, maxRows: 8 }}+ />+ )}+ </RAGFlowFormItem>+ </form>+ </Form>+ </Modal>+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-detail-content.tsx b/web/src/pages/dataset/compilation/wiki-detail-content.tsxnew file mode 100644index 0000000000..0165528d84--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-detail-content.tsx@@ -0,0 +1,238 @@+import Empty from '@/components/empty/empty';+import MarkdownEditor from '@/components/markdown-editor';+import { ReferenceDocumentList } from '@/components/next-message-item/reference-document-list';+import { Button } from '@/components/ui/button';+import {+ ResizableHandle,+ ResizablePanel,+ ResizablePanelGroup,+} from '@/components/ui/resizable';+import { Spin } from '@/components/ui/spin';+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@/components/ui/tooltip';+import { useFetchDocumentsByIds } from '@/hooks/use-document-request';+import {+ useFetchArtifactPage,+ useFetchWikiCommit,+} from '@/hooks/use-knowledge-request';+import { Docagg } from '@/interfaces/database/chat';+import { IArtifact, IWikiCommit } from '@/interfaces/database/dataset';+import { downloadMarkdownFile } from '@/utils/file-util';+import { Download } from 'lucide-react';+import { useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useCommitArtifact } from './hooks/use-commit-artifact';+import { useWikiEditor } from './hooks/use-wiki-editor';+import { VersionHistorySheet } from './version-history-sheet';+import { WikiCommitModal } from './wiki-commit-modal';+import { WikiVersionDiffPanel } from './wiki-version-diff-panel';++type WikiDetailContentProps = {+ selectedArtifact: IArtifact | null;+ selectedVersion: IWikiCommit | null;+ onSelectVersion: (version: IWikiCommit | null) => void;+};++export function WikiDetailContent({+ selectedArtifact,+ selectedVersion,+ onSelectVersion,+}: WikiDetailContentProps) {+ const { t } = useTranslation();+ const isVersionView = !!selectedVersion;++ const { data: pageData, loading: pageLoading } = useFetchArtifactPage(+ isVersionView ? null : selectedArtifact,+ );+ const { data: commitDetail, loading: commitLoading } = useFetchWikiCommit(+ selectedVersion?.id ?? null,+ );++ const title = pageData?.title ?? selectedArtifact?.title;++ const pageType = isVersionView+ ? selectedArtifact?.page_type+ : pageData?.page_type;+ const slug = isVersionView ? selectedArtifact?.slug : pageData?.slug;+ const content = isVersionView+ ? (commitDetail?.content_after ?? '')+ : (pageData?.content_md_rendered ?? '');+ const sourceDocIds = isVersionView ? [] : (pageData?.source_doc_ids ?? []);++ const editorKey = isVersionView+ ? `${selectedArtifact?.slug}@${selectedVersion?.id}`+ : selectedArtifact?.slug;++ const {+ editedContent,+ isDirty,+ handleContentChange,+ handleCancelEdit,+ handleMarkAsSaved,+ } = useWikiEditor({+ content,+ artifactSlug: editorKey,+ });++ const handleCommitSuccess = useCallback(() => {+ handleMarkAsSaved();+ if (isVersionView) {+ onSelectVersion(null);+ }+ }, [handleMarkAsSaved, isVersionView, onSelectVersion]);++ const { isOpen, open, close, form, handleConfirm, isUpdating } =+ useCommitArtifact({+ editedContent,+ pageType: pageType ?? '',+ slug: slug ?? '',+ onSuccess: handleCommitSuccess,+ });++ const { documents } = useFetchDocumentsByIds(sourceDocIds);++ const referenceDocuments = useMemo<Docagg[]>(() => {+ return documents.map(+ (doc): Docagg => ({+ doc_id: doc.id,+ doc_name: doc.name,+ count: 0,+ }),+ );+ }, [documents]);++ const handleExport = useCallback(() => {+ const filename = `${title ?? 'document'}.md`;+ downloadMarkdownFile(editedContent, filename);+ }, [title, editedContent]);++ const renderToolbarButtons = () => {+ if (isDirty) {+ return (+ <div className="flex items-center gap-2">+ <Button+ type="button"+ variant="outline"+ size="sm"+ onClick={handleCancelEdit}+ >+ {t('common.cancel')}+ </Button>+ <Button type="button" size="sm" onClick={open}>+ {t('knowledgeDetails.commit')}+ </Button>+ </div>+ );+ }++ return (+ <div className="flex items-center gap-1">+ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ variant="ghost"+ size="icon"+ className="size-8"+ onClick={handleExport}+ >+ <Download className="size-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>{t('knowledgeDetails.export')}</TooltipContent>+ </Tooltip>+ <VersionHistorySheet+ selectedArtifact={selectedArtifact}+ selectedVersion={selectedVersion}+ onSelectVersion={onSelectVersion}+ />+ </div>+ );+ };++ const loading = isVersionView ? commitLoading : pageLoading;++ return (+ <section className="size-full min-w-0 flex flex-col">+ {selectedArtifact ? (+ <>+ <header className="shrink-0 px-8 pt-8 pb-4">+ <div className="flex items-start justify-between">+ <div className="flex flex-col gap-2">+ <h1 className="text-3xl font-semibold text-text-primary">+ {title ?? selectedArtifact.title}+ </h1>+ <div className="flex items-center gap-2">+ {isVersionView && commitDetail && (+ <span className="text-sm text-accent-primary bg-accent-primary-5 px-2 py-0.5 rounded">+ {commitDetail.title}+ </span>+ )}+ </div>+ </div>++ {renderToolbarButtons()}+ </div>+ </header>++ <div className="flex-1 min-h-0 flex flex-col border-t border-border-button">+ <ResizablePanelGroup direction="horizontal" className="flex-1">+ <ResizablePanel minSize={30}>+ <div className="h-full min-w-0 overflow-y-auto px-8 pb-8 flex flex-col">+ {loading && !content ? (+ <div className="py-8 flex justify-center">+ <Spin size="large" />+ </div>+ ) : (+ <MarkdownEditor+ content={editedContent}+ onChange={handleContentChange}+ />+ )}++ {referenceDocuments.length > 0 && (+ <div className="mt-8">+ <h3 className="text-sm font-medium text-text-secondary mb-3">+ {t('knowledgeDetails.sourceDocuments')}+ </h3>+ <ReferenceDocumentList list={referenceDocuments} />+ </div>+ )}+ </div>+ </ResizablePanel>++ {isVersionView && commitDetail && (+ <>+ <ResizableHandle withHandle />+ <ResizablePanel defaultSize={30} minSize={20}>+ <WikiVersionDiffPanel+ diff={commitDetail.diff}+ title={commitDetail.comments || commitDetail.title}+ />+ </ResizablePanel>+ </>+ )}+ </ResizablePanelGroup>+ </div>++ <WikiCommitModal+ open={isOpen}+ onOpenChange={close}+ form={form}+ onConfirm={handleConfirm}+ loading={isUpdating}+ />+ </>+ ) : (+ <div className="flex-1 overflow-y-auto p-8">+ <Empty+ className="h-full"+ text={t('knowledgeDetails.selectArtifact')}+ />+ </div>+ )}+ </section>+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-left-panel/hooks/use-wiki-clear.ts b/web/src/pages/dataset/compilation/wiki-left-panel/hooks/use-wiki-clear.tsnew file mode 100644index 0000000000..171ca27832--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-left-panel/hooks/use-wiki-clear.ts@@ -0,0 +1,21 @@+import { useClearWiki } from '@/hooks/use-knowledge-request';+import { useCallback, useState } from 'react';++type UseWikiClearOptions = {+ onClearWiki?: () => void;+};++export function useWikiClear({ onClearWiki }: UseWikiClearOptions = {}) {+ const { clearWiki, loading } = useClearWiki();+ const [open, setOpen] = useState(false);++ const handleConfirm = useCallback(async () => {+ setOpen(false);+ const data = await clearWiki();+ if (data?.code === 0) {+ onClearWiki?.();+ }+ }, [clearWiki, onClearWiki]);++ return { open, setOpen, handleConfirm, loading };+}diff --git a/web/src/pages/dataset/compilation/wiki-left-panel/hooks/use-wiki-navigation.ts b/web/src/pages/dataset/compilation/wiki-left-panel/hooks/use-wiki-navigation.tsnew file mode 100644index 0000000000..c1696ad136--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-left-panel/hooks/use-wiki-navigation.ts@@ -0,0 +1,118 @@+import {+ useFetchArtifactList,+ useFetchArtifactTopicList,+} from '@/hooks/use-knowledge-request';+import { IArtifactTopic } from '@/interfaces/database/dataset';+import { useDebounce } from 'ahooks';+import { useCallback, useMemo, useRef, useState } from 'react';++export type WikiPageType = 'concept' | 'entity';++export function useWikiNavigation() {+ const scrollRef = useRef<HTMLDivElement>(null);+ const [searchString, setSearchString] = useState('');+ const debouncedSearchString = useDebounce(searchString, { wait: 500 });+ const [selectedTopic, setSelectedTopic] = useState<IArtifactTopic | null>(+ null,+ );+ const [pageType, setPageType] = useState<WikiPageType>('entity');++ const {+ topics,+ loading: topicLoading,+ handleScroll: handleTopicScroll,+ hasMore: topicHasMore,+ } = useFetchArtifactTopicList({+ keywords: debouncedSearchString,+ });++ const {+ artifacts,+ loading: artifactLoading,+ handleScroll: handleArtifactScroll,+ hasMore: artifactHasMore,+ } = useFetchArtifactList({+ keywords: debouncedSearchString,+ topic: selectedTopic?.topic,+ pageType,+ enabled: !!selectedTopic,+ });++ const handleSearchChange = useCallback(+ (e: React.ChangeEvent<HTMLInputElement>) => {+ setSearchString(e.target.value);+ },+ [],+ );++ const resetScroll = useCallback(() => {+ if (scrollRef.current) {+ scrollRef.current.scrollTop = 0;+ }+ }, []);++ const handleSelectTopic = useCallback(+ (topic: IArtifactTopic) => {+ setSelectedTopic(topic);+ resetScroll();+ },+ [resetScroll],+ );++ const handleBackToTopics = useCallback(() => {+ setSelectedTopic(null);+ resetScroll();+ }, [resetScroll]);++ const handlePageTypeChange = useCallback((value: WikiPageType) => {+ setPageType(value);+ }, []);++ const handleScroll = useCallback(+ (e: React.UIEvent<HTMLDivElement>) => {+ if (selectedTopic) {+ handleArtifactScroll(e);+ } else {+ handleTopicScroll(e);+ }+ },+ [selectedTopic, handleArtifactScroll, handleTopicScroll],+ );++ const loading = selectedTopic ? artifactLoading : topicLoading;+ const hasMore = selectedTopic ? artifactHasMore : topicHasMore;++ return useMemo(+ () => ({+ scrollRef,+ searchString,+ debouncedSearchString,+ selectedTopic,+ pageType,+ topics,+ artifacts,+ loading,+ hasMore,+ handleSearchChange,+ handleSelectTopic,+ handleBackToTopics,+ handlePageTypeChange,+ handleScroll,+ }),+ [+ searchString,+ debouncedSearchString,+ selectedTopic,+ pageType,+ topics,+ artifacts,+ loading,+ hasMore,+ handleSearchChange,+ handleSelectTopic,+ handleBackToTopics,+ handlePageTypeChange,+ handleScroll,+ ],+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-left-panel/index.tsx b/web/src/pages/dataset/compilation/wiki-left-panel/index.tsxnew file mode 100644index 0000000000..e9cf875520--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-left-panel/index.tsx@@ -0,0 +1,92 @@+import ArtifactForceGraph from '@/components/artifact-force-graph';+import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';+import { Button } from '@/components/ui/button';+import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';+import { useFetchArtifactGraph } from '@/hooks/use-knowledge-request';+import { IArtifact, IArtifactGraphEntity } from '@/interfaces/database/dataset';+import { Trash2 } from 'lucide-react';+import { useTranslation } from 'react-i18next';++import { LeftPanelTab } from '../constants';+import { useWikiClear } from './hooks/use-wiki-clear';+import { WikiNavBar } from './wiki-nav-bar';++const mapNodeToValue = (node: IArtifactGraphEntity) => ({+ slug: node.slug,+ title: node.name,+ page_type: node.type,+});++type WikiLeftPanelProps = {+ tab: LeftPanelTab;+ onTabChange: (value: string) => void;+ selectedArtifact: IArtifact | null;+ onSelectArtifact: (artifact: IArtifact) => void;+ onClearWiki?: () => void;+};++export function WikiLeftPanel({+ tab,+ onTabChange,+ selectedArtifact,+ onSelectArtifact,+ onClearWiki,+}: WikiLeftPanelProps) {+ const { t } = useTranslation();+ const { data } = useFetchArtifactGraph(undefined, {+ enabled: tab === LeftPanelTab.Graph,+ });+ const { open, setOpen, handleConfirm, loading } = useWikiClear({+ onClearWiki,+ });++ return (+ <aside className="size-full flex flex-col p-5">+ <section className="flex items-center justify-between pb-5">+ <Tabs value={tab} onValueChange={onTabChange}>+ <TabsList className="grid grid-cols-2 w-80">+ <TabsTrigger value={LeftPanelTab.Contents}>+ {t('knowledgeDetails.contents')}+ </TabsTrigger>+ <TabsTrigger value={LeftPanelTab.Graph}>+ {t('knowledgeDetails.graph')}+ </TabsTrigger>+ </TabsList>+ </Tabs>+ <ConfirmDeleteDialog+ open={open}+ onOpenChange={setOpen}+ title={t('knowledgeDetails.clearWikiTitle')}+ content={{ title: t('knowledgeDetails.clearWikiDescription') }}+ onOk={handleConfirm}+ >+ <Button+ variant="ghost"+ size="icon-sm"+ disabled={loading}+ data-testid="wiki-clear-trigger"+ >+ <Trash2 className="size-[1em]" />+ </Button>+ </ConfirmDeleteDialog>+ </section>++ <div className="flex-1 min-h-0 relative">+ {tab === LeftPanelTab.Contents && (+ <WikiNavBar+ selectedArtifact={selectedArtifact}+ onSelectArtifact={onSelectArtifact}+ />+ )}+ {tab === LeftPanelTab.Graph && (+ <ArtifactForceGraph+ data={data}+ show+ mapNodeToValue={mapNodeToValue}+ onNodeClick={onSelectArtifact}+ />+ )}+ </div>+ </aside>+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-left-panel/wiki-artifact-list.tsx b/web/src/pages/dataset/compilation/wiki-left-panel/wiki-artifact-list.tsxnew file mode 100644index 0000000000..d5604d39c9--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-left-panel/wiki-artifact-list.tsx@@ -0,0 +1,48 @@+import { Spin } from '@/components/ui/spin';+import { IArtifact } from '@/interfaces/database/dataset';+import { useTranslation } from 'react-i18next';++import { WikiArtifactListItem } from './wiki-list-item';++type WikiArtifactListProps = {+ artifacts: IArtifact[];+ selectedArtifact: IArtifact | null;+ loading: boolean;+ hasMore: boolean;+ onSelectArtifact: (artifact: IArtifact) => void;+};++export function WikiArtifactList({+ artifacts,+ selectedArtifact,+ loading,+ hasMore,+ onSelectArtifact,+}: WikiArtifactListProps) {+ const { t } = useTranslation();++ return (+ <>+ <ul className="space-y-1">+ {artifacts.map((item) => (+ <WikiArtifactListItem+ key={item.slug}+ item={item}+ isSelected={selectedArtifact?.slug === item.slug}+ onSelect={onSelectArtifact}+ />+ ))}+ </ul>+ {loading && (+ <div className="py-4 flex justify-center">+ <Spin size="small" />+ </div>+ )}+ {!loading && !hasMore && artifacts.length > 0 && (+ <div className="py-2 text-center text-sm text-text-secondary">+ {t('knowledgeList.noMoreData')}+ </div>+ )}+ </>+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-left-panel/wiki-list-item.tsx b/web/src/pages/dataset/compilation/wiki-left-panel/wiki-list-item.tsxnew file mode 100644index 0000000000..832d93f993--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-left-panel/wiki-list-item.tsx@@ -0,0 +1,64 @@+import { IArtifact, IArtifactTopic } from '@/interfaces/database/dataset';+import { cn } from '@/lib/utils';+import { FileText, Folder } from 'lucide-react';++type WikiTopicListItemProps = {+ topic: IArtifactTopic;+ onSelect: (topic: IArtifactTopic) => void;+};++export function WikiTopicListItem({ topic, onSelect }: WikiTopicListItemProps) {+ const handleClick = () => {+ onSelect(topic);+ };++ return (+ <li+ onClick={handleClick}+ className={cn(+ 'flex items-center gap-2 px-3 py-2 rounded-md text-sm cursor-pointer',+ 'text-text-secondary hover:bg-bg-base hover:text-text-primary',+ )}+ >+ <Folder className="size-4 shrink-0" />+ <span className="truncate">{topic.title}</span>+ </li>+ );+}++type WikiArtifactListItemProps = {+ item: IArtifact;+ isSelected: boolean;+ onSelect: (artifact: IArtifact) => void;+};++export function WikiArtifactListItem({+ item,+ isSelected,+ onSelect,+}: WikiArtifactListItemProps) {+ const handleClick = () => {+ onSelect(item);+ };++ return (+ <li+ onClick={handleClick}+ className={cn(+ 'flex items-center justify-between gap-2 px-3 py-2 rounded-md text-sm cursor-pointer',+ 'text-text-secondary hover:bg-bg-base hover:text-text-primary',+ isSelected && 'bg-bg-card text-text-primary',+ )}+ >+ <div className="flex items-center gap-2 min-w-0">+ <FileText className="size-4 shrink-0" />+ <span className="truncate">{item.title}</span>+ </div>+ {item.page_type && (+ <span className="text-text-disabled shrink-0 capitalize text-xs">+ {item.page_type}+ </span>+ )}+ </li>+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-left-panel/wiki-nav-bar.tsx b/web/src/pages/dataset/compilation/wiki-left-panel/wiki-nav-bar.tsxnew file mode 100644index 0000000000..a36daf7ded--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-left-panel/wiki-nav-bar.tsx@@ -0,0 +1,171 @@+import {+ Breadcrumb,+ BreadcrumbItem,+ BreadcrumbLink,+ BreadcrumbList,+ BreadcrumbSeparator,+} from '@/components/ui/breadcrumb';+import { Button } from '@/components/ui/button';+import { SearchInput } from '@/components/ui/input';+import { IArtifact } from '@/interfaces/database/dataset';+import { cn } from '@/lib/utils';+import { Plus } from 'lucide-react';+import { useCallback } from 'react';+import { useTranslation } from 'react-i18next';++import { CreateDirectoryDialog } from '../create-directory-dialog';+import { useCreateDirectory } from '../hooks/use-create-directory';+import { useWikiNavigation, WikiPageType } from './hooks/use-wiki-navigation';+import { WikiArtifactList } from './wiki-artifact-list';+import { WikiTopicList } from './wiki-topic-list';++type PageTypeFilterProps = {+ value: WikiPageType;+ onChange: (value: WikiPageType) => void;+};++function PageTypeFilter({ value, onChange }: PageTypeFilterProps) {+ const { t } = useTranslation();++ const handleConceptClick = useCallback(() => {+ onChange('concept');+ }, [onChange]);++ const handleEntityClick = useCallback(() => {+ onChange('entity');+ }, [onChange]);++ return (+ <div className="flex items-center gap-2">+ <Button+ variant={value === 'concept' ? 'default' : 'outline'}+ size="sm"+ onClick={handleConceptClick}+ >+ {t('knowledgeDetails.concept')}+ </Button>+ <Button+ variant={value === 'entity' ? 'default' : 'outline'}+ size="sm"+ onClick={handleEntityClick}+ >+ {t('knowledgeDetails.entity')}+ </Button>+ </div>+ );+}++type WikiNavBarProps = {+ selectedArtifact: IArtifact | null;+ onSelectArtifact: (artifact: IArtifact) => void;+};++export function WikiNavBar({+ selectedArtifact,+ onSelectArtifact,+}: WikiNavBarProps) {+ const { t } = useTranslation();+ const {+ scrollRef,+ searchString,+ selectedTopic,+ pageType,+ topics,+ artifacts,+ loading,+ hasMore,+ handleSearchChange,+ handleSelectTopic,+ handleBackToTopics,+ handlePageTypeChange,+ handleScroll,+ } = useWikiNavigation();+ const {+ open,+ loading: createLoading,+ form,+ showModal: handleShowCreateDialog,+ hideModal: handleHideCreateDialog,+ handleOk: handleCreateOk,+ } = useCreateDirectory();++ return (+ <div className="size-full flex flex-col gap-3 px-3">+ <SearchInput+ placeholder={t('common.search')}+ value={searchString}+ onChange={handleSearchChange}+ />+ <PageTypeFilter value={pageType} onChange={handlePageTypeChange} />+ <section>+ <div className="flex items-center justify-between">+ <Breadcrumb>+ <BreadcrumbList>+ <BreadcrumbItem>+ <BreadcrumbLink+ onClick={handleBackToTopics}+ className={cn(+ 'text-sm',+ selectedTopic+ ? 'text-text-secondary cursor-pointer'+ : 'text-text-primary cursor-default',+ )}+ >+ {t('knowledgeDetails.topics')}+ </BreadcrumbLink>+ </BreadcrumbItem>+ {selectedTopic && (+ <>+ <BreadcrumbSeparator />+ <BreadcrumbItem>+ <BreadcrumbLink className="text-text-primary text-sm cursor-default">+ {selectedTopic.title}+ </BreadcrumbLink>+ </BreadcrumbItem>+ </>+ )}+ </BreadcrumbList>+ </Breadcrumb>+ {!selectedTopic && (+ <Button+ variant="secondary"+ size="icon-xs"+ onClick={handleShowCreateDialog}+ >+ <Plus className="size-4" />+ </Button>+ )}+ </div>+ </section>+ <CreateDirectoryDialog+ open={open}+ loading={createLoading}+ form={form}+ onOk={handleCreateOk}+ onCancel={handleHideCreateDialog}+ />+ <div+ ref={scrollRef}+ className="flex-1 min-h-0 overflow-y-auto pb-3"+ onScroll={handleScroll}+ >+ {selectedTopic ? (+ <WikiArtifactList+ artifacts={artifacts}+ selectedArtifact={selectedArtifact}+ loading={loading}+ hasMore={hasMore}+ onSelectArtifact={onSelectArtifact}+ />+ ) : (+ <WikiTopicList+ topics={topics}+ loading={loading}+ hasMore={hasMore}+ onSelectTopic={handleSelectTopic}+ />+ )}+ </div>+ </div>+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-left-panel/wiki-topic-list.tsx b/web/src/pages/dataset/compilation/wiki-left-panel/wiki-topic-list.tsxnew file mode 100644index 0000000000..fcce86507a--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-left-panel/wiki-topic-list.tsx@@ -0,0 +1,45 @@+import { Spin } from '@/components/ui/spin';+import { IArtifactTopic } from '@/interfaces/database/dataset';+import { useTranslation } from 'react-i18next';++import { WikiTopicListItem } from './wiki-list-item';++type WikiTopicListProps = {+ topics: IArtifactTopic[];+ loading: boolean;+ hasMore: boolean;+ onSelectTopic: (topic: IArtifactTopic) => void;+};++export function WikiTopicList({+ topics,+ loading,+ hasMore,+ onSelectTopic,+}: WikiTopicListProps) {+ const { t } = useTranslation();++ return (+ <>+ <ul className="space-y-1">+ {topics.map((topic) => (+ <WikiTopicListItem+ key={topic.topic}+ topic={topic}+ onSelect={onSelectTopic}+ />+ ))}+ </ul>+ {loading && (+ <div className="py-4 flex justify-center">+ <Spin size="small" />+ </div>+ )}+ {!loading && !hasMore && topics.length > 0 && (+ <div className="py-2 text-center text-sm text-text-secondary">+ {t('knowledgeList.noMoreData')}+ </div>+ )}+ </>+ );+}diff --git a/web/src/pages/dataset/compilation/wiki-version-diff-panel.tsx b/web/src/pages/dataset/compilation/wiki-version-diff-panel.tsxnew file mode 100644index 0000000000..2391434471--- /dev/null+++ b/web/src/pages/dataset/compilation/wiki-version-diff-panel.tsx@@ -0,0 +1,58 @@+import { cn } from '@/lib/utils';+import { useTranslation } from 'react-i18next';+import { WikiDiffLine } from './interface';+import { getWikiDiffChanges, parseWikiDiff } from './utils/parse-wiki-diff';++type WikiVersionDiffPanelProps = {+ diff: string;+ title?: string;+};++type DiffLineProps = {+ line: WikiDiffLine;+};++function DiffLine({ line }: DiffLineProps) {+ return (+ <div+ className={cn(+ 'p-2.5 rounded',+ line.type === 'added' && 'bg-[#3BA05C]/10',+ line.type === 'removed' && 'bg-[#D8494B]/10',+ )}+ >+ {line.content.length === 0 ? <br /> : line.content}+ </div>+ );+}++export function WikiVersionDiffPanel({+ diff,+ title,+}: WikiVersionDiffPanelProps) {+ const { t } = useTranslation();+ const changes = getWikiDiffChanges(parseWikiDiff(diff));++ return (+ <section className="flex flex-col h-full border-l border-border-button p-5">+ <header className="shrink-0 pb-5">+ <h3 className="font-semibold text-text-primary">+ {title || t('knowledgeDetails.versionDiff')}+ </h3>+ </header>+ <div className="flex-1 overflow-y-auto">+ {changes.length === 0 ? (+ <div className=" text-sm text-text-secondary">+ {t('knowledgeDetails.noDiffAvailable')}+ </div>+ ) : (+ <div className="space-y-5">+ {changes.map((line, index) => (+ <DiffLine key={index} line={line} />+ ))}+ </div>+ )}+ </div>+ </section>+ );+}diff --git a/web/src/pages/dataset/dataset-overview/dataset-common.ts b/web/src/pages/dataset/dataset-overview/dataset-common.tsindex 566416dccd..aecc2225aa 100644--- a/web/src/pages/dataset/dataset-overview/dataset-common.ts+++ b/web/src/pages/dataset/dataset-overview/dataset-common.ts@@ -6,10 +6,14 @@ export enum LogTabs {export enum ProcessingType {knowledgeGraph = 'Graph',raptor = 'RAPTOR',+ artifact = 'Artifact',+ skill = 'Skill',}export const ProcessingTypeMap = {[ProcessingType.knowledgeGraph]: 'Knowledge Graph',[ProcessingType.raptor]: 'RAPTOR',+ [ProcessingType.artifact]: 'Artifact',+ [ProcessingType.skill]: 'Skill',GraphRAG: 'Knowledge Graph',};diff --git a/web/src/pages/dataset/dataset-setting/configuration/naive.tsx b/web/src/pages/dataset/dataset-setting/configuration/naive.tsxindex d69319970e..2886fbd40c 100644--- a/web/src/pages/dataset/dataset-setting/configuration/naive.tsx+++ b/web/src/pages/dataset/dataset-setting/configuration/naive.tsx@@ -3,6 +3,7 @@ import {AutoQuestionsFormField,} from '@/components/auto-keywords-form-field';import { ChildrenDelimiterForm } from '@/components/children-delimiter-form';+import { CompilationTemplateFormField } from '@/components/compilation-template-form-field';import { DelimiterFormField } from '@/components/delimiter-form-field';import { ExcelToHtmlFormField } from '@/components/excel-to-html-form-field';import { LayoutRecognizeFormField } from '@/components/layout-recognize-form-field';@@ -22,6 +23,7 @@ export function NaiveConfiguration() {return (<MainContainer><ConfigurationFormContainer>+ <CompilationTemplateFormField horizontal></CompilationTemplateFormField><LayoutRecognizeFormField testId="ds-settings-parser-pdf-parser-select"></LayoutRecognizeFormField><MaxTokenNumberFormFieldinitialValue={512}diff --git a/web/src/pages/dataset/dataset-setting/form-schema.ts b/web/src/pages/dataset/dataset-setting/form-schema.tsindex acb0eaf109..b226ecfe07 100644--- a/web/src/pages/dataset/dataset-setting/form-schema.ts+++ b/web/src/pages/dataset/dataset-setting/form-schema.ts@@ -92,6 +92,7 @@ export const formSchema = zpath: ['entity_types'],},),+ compilation_template_group_id: z.array(z.string()).optional(),metadata: z.any().optional(),built_in_metadata: z.array(diff --git a/web/src/pages/dataset/dataset-setting/index.tsx b/web/src/pages/dataset/dataset-setting/index.tsxindex 072e84f878..d64808614a 100644--- a/web/src/pages/dataset/dataset-setting/index.tsx+++ b/web/src/pages/dataset/dataset-setting/index.tsx@@ -1,6 +1,4 @@import { DataFlowSelect } from '@/components/data-pipeline-select';-import GraphRagItems from '@/components/parse-configuration/graph-rag-form-fields';-import RaptorFormFields from '@/components/parse-configuration/raptor-form-fields';import { Button } from '@/components/ui/button';import {Card,@@ -22,10 +20,6 @@ import { createContext, useEffect, useState } from 'react';import { useForm, useWatch } from 'react-hook-form';import { useTranslation } from 'react-i18next';import { z } from 'zod';-import {- GenerateType,- IGenerateLogButtonProps,-} from '../dataset/generate-button/generate';import { ChunkMethodForm } from './chunk-method-form';import ChunkMethodLearnMore from './chunk-method-learn-more';import LinkDataSource, {@@ -111,6 +105,7 @@ export default function DatasetSettings() {additionalProperties: false,},built_in_metadata: [],+ compilation_template_group_id: [],enable_metadata: false,llm_id: '',},@@ -125,10 +120,6 @@ export default function DatasetSettings() {useFetchKnowledgeConfigurationOnMount(form);// const [pipelineData, setPipelineData] = useState<IDataPipelineNodeProps>();const [sourceData, setSourceData] = useState<IDataSourceNodeProps[]>();- const [graphRagGenerateData, setGraphRagGenerateData] =- useState<IGenerateLogButtonProps>();- const [raptorGenerateData, setRaptorGenerateData] =- useState<IGenerateLogButtonProps>();useEffect(() => {if (knowledgeDetails) {@@ -153,14 +144,6 @@ export default function DatasetSettings() {setSourceData(source_data);- setGraphRagGenerateData({- finish_at: knowledgeDetails.graphrag_task_finish_at,- task_id: knowledgeDetails.graphrag_task_id,- } as IGenerateLogButtonProps);- setRaptorGenerateData({- finish_at: knowledgeDetails.raptor_task_finish_at,- task_id: knowledgeDetails.raptor_task_id,- } as IGenerateLogButtonProps);form.setValue('parse_type',knowledgeDetails.pipeline_id ? ParseType.Pipeline : ParseType.BuiltIn,@@ -206,20 +189,6 @@ export default function DatasetSettings() {}};- const handleDeletePipelineTask = (type: GenerateType) => {- if (type === GenerateType.KnowledgeGraph) {- setGraphRagGenerateData({- finish_at: '',- task_id: '',- } as IGenerateLogButtonProps);- } else if (type === GenerateType.Raptor) {- setRaptorGenerateData({- finish_at: '',- task_id: '',- } as IGenerateLogButtonProps);- }- };-const parseType = useWatch({control: form.control,name: 'parse_type',@@ -327,7 +296,6 @@ export default function DatasetSettings() {/>)}- {/* <Divider /> */}{parseType === ParseType.BuiltIn && <ChunkMethodForm />}{/* <LinkDataPipeline@@ -341,24 +309,6 @@ export default function DatasetSettings() {unbindFunc={unbindFunc}handleAutoParse={handleAutoParse}/>- <Divider />- <div className="text-base font-medium text-text-primary">- {t('knowledgeConfiguration.globalIndex')}- </div>- <GraphRagItems- className="border-none p-0"- data={graphRagGenerateData as IGenerateLogButtonProps}- onDelete={() =>- handleDeletePipelineTask(GenerateType.KnowledgeGraph)- }- ></GraphRagItems>- <Divider />- <RaptorFormFields- data={raptorGenerateData as IGenerateLogButtonProps}- onDelete={() =>- handleDeletePipelineTask(GenerateType.Raptor)- }- ></RaptorFormFields></MainContainer></div>diff --git a/web/src/pages/dataset/dataset/generate-button/constants.ts b/web/src/pages/dataset/dataset/generate-button/constants.tsnew file mode 100644index 0000000000..83b7ae7730--- /dev/null+++ b/web/src/pages/dataset/dataset/generate-button/constants.ts@@ -0,0 +1,36 @@+import { ProcessingType } from '../../dataset-overview/dataset-common';++export const GenerateStatus = {+ running: 'running',+ completed: 'completed',+ start: 'start',+ failed: 'failed',+};++export enum GenerateType {+ KnowledgeGraph = 'KnowledgeGraph',+ Raptor = 'Raptor',+ Artifact = 'Artifact',+ ToSkills = 'ToSkills',+}++export enum TraceType {+ Graph = 'graph',+ Raptor = 'raptor',+ Artifact = 'artifact',+ Skill = 'skill',+}++export const GenerateTypeMap = {+ [GenerateType.KnowledgeGraph]: ProcessingType.knowledgeGraph,+ [GenerateType.Raptor]: ProcessingType.raptor,+ [GenerateType.Artifact]: ProcessingType.artifact,+ [GenerateType.ToSkills]: ProcessingType.skill,+};++export const IconKeyMap = {+ KnowledgeGraph: 'knowledgegraph',+ Raptor: 'dataflow-01',+ Artifact: 'book-open-01',+ ToSkills: 'spark',+};diff --git a/web/src/pages/dataset/dataset/generate-button/generate-log-button.tsx b/web/src/pages/dataset/dataset/generate-button/generate-log-button.tsxnew file mode 100644index 0000000000..f7bd610a26--- /dev/null+++ b/web/src/pages/dataset/dataset/generate-button/generate-log-button.tsx@@ -0,0 +1,116 @@+import { Button } from '@/components/ui/button';+import { Modal } from '@/components/ui/modal/modal';+import { cn } from '@/lib/utils';+import { formatDate } from '@/utils/date';+import { lowerFirst } from 'lodash';+import { Trash2 } from 'lucide-react';+import { useTranslation } from 'react-i18next';+import { GenerateType, GenerateTypeMap } from './constants';+import { useUnBindTask } from './hook';++export type IGenerateLogButtonProps = {+ finish_at: string;+ task_id: string;+};++export type IGenerateLogProps = IGenerateLogButtonProps & {+ id?: string;+ status: 0 | 1;+ message?: string;+ created_at?: string;+ updated_at?: string;+ type?: GenerateType;+ className?: string;+ onDelete?: () => void;+};++export function GenerateLogButton(props: IGenerateLogProps) {+ const { t } = useTranslation();+ const { message, finish_at, type, onDelete } = props;++ const { handleUnbindTask } = useUnBindTask();++ const handleDeleteFunc = async () => {+ const data = await handleUnbindTask({+ type: GenerateTypeMap[type as GenerateType],+ });+ Modal.destroy();+ if (data.code === 0) {+ onDelete?.();+ }+ };++ const typeLabel = type+ ? t(`knowledgeDetails.${lowerFirst(type)}`)+ : t('knowledgeDetails.raptor');++ const handleDelete = () => {+ Modal.show({+ visible: true,+ className: '!w-[560px]',+ title: t('common.delete') + ' ' + typeLabel,+ children: (+ <div+ className="text-sm text-text-secondary"+ dangerouslySetInnerHTML={{+ __html: t('knowledgeConfiguration.deleteGenerateModalContent', {+ type: typeLabel,+ }),+ }}+ ></div>+ ),+ onVisibleChange: () => {+ Modal.destroy();+ },+ footer: (+ <div className="flex justify-end gap-2">+ <Button+ type="button"+ variant={'outline'}+ onClick={() => Modal.destroy()}+ >+ {t('dataflowParser.changeStepModalCancelText')}+ </Button>+ <Button+ type="button"+ variant={'secondary'}+ className="!bg-state-error text-text-primary"+ onClick={() => {+ handleDeleteFunc();+ }}+ >+ {t('common.delete')}+ </Button>+ </div>+ ),+ });+ };++ return (+ <div+ className={cn('flex bg-bg-card rounded-md py-1 px-3', props.className)}+ >+ <div className="flex items-center justify-between w-full">+ {finish_at && (+ <>+ <div>+ {message || t('knowledgeDetails.generatedOn')}+ {formatDate(finish_at)}+ </div>+ <Trash2+ size={14}+ className="cursor-pointer"+ onClick={(e) => {+ handleDelete();+ e.stopPropagation();+ }}+ />+ </>+ )}+ {!finish_at && <div>{t('knowledgeDetails.notGenerated')}</div>}+ </div>+ </div>+ );+}++export default GenerateLogButton;diff --git a/web/src/pages/dataset/dataset/generate-button/generate.tsx b/web/src/pages/dataset/dataset/generate-button/generate.tsxdeleted file mode 100644index cfc5c4f87d..0000000000--- a/web/src/pages/dataset/dataset/generate-button/generate.tsx+++ /dev/null@@ -1,355 +0,0 @@-import { IconFontFill } from '@/components/icon-font';-import { Button } from '@/components/ui/button';-import {- DropdownMenu,- DropdownMenuContent,- DropdownMenuItem,- DropdownMenuTrigger,-} from '@/components/ui/dropdown-menu';-import { Modal } from '@/components/ui/modal/modal';-import {- Tooltip,- TooltipContent,- TooltipTrigger,-} from '@/components/ui/tooltip';-import { cn } from '@/lib/utils';-import { toFixed } from '@/utils/common-util';-import { formatDate } from '@/utils/date';-import { UseMutateAsyncFunction } from '@tanstack/react-query';-import { t } from 'i18next';-import { lowerFirst } from 'lodash';-import { CirclePause, Trash2, WandSparkles } from 'lucide-react';-import { useMemo, useState } from 'react';-import { useTranslation } from 'react-i18next';-import { ProcessingType } from '../../dataset-overview/dataset-common';-import { replaceText } from '../../process-log-modal';-import {- ITraceInfo,- generateStatus,- useDatasetGenerate,- useTraceGenerate,- useUnBindTask,-} from './hook';--export enum GenerateType {- KnowledgeGraph = 'KnowledgeGraph',- Raptor = 'Raptor',-}-export const GenerateTypeMap = {- [GenerateType.KnowledgeGraph]: ProcessingType.knowledgeGraph,- [GenerateType.Raptor]: ProcessingType.raptor,-};-const MenuItem: React.FC<{- name: GenerateType;- data: ITraceInfo;- pauseGenerate: ({- task_id,- type,- }: {- task_id: string;- type: GenerateType;- }) => void;- runGenerate: UseMutateAsyncFunction<- any,- Error,- {- type: GenerateType;- },- unknown- >;-}> = ({ name: type, runGenerate, data, pauseGenerate }) => {- const iconKeyMap = {- KnowledgeGraph: 'knowledgegraph',- Raptor: 'dataflow-01',- };- const status = useMemo(() => {- if (!data) {- return generateStatus.start;- }- if (data.progress >= 1) {- return generateStatus.completed;- } else if (!data.progress && data.progress !== 0) {- return generateStatus.start;- } else if (data.progress < 0) {- return generateStatus.failed;- } else if (data.progress < 1) {- return generateStatus.running;- }- }, [data]);-- const percent =- status === generateStatus.failed- ? 100- : status === generateStatus.running- ? data.progress * 100- : 0;-- return (- <DropdownMenuItem- className={cn(- 'border cursor-pointer p-2 rounded-md focus:bg-transparent',- {- 'hover:border-accent-primary hover:bg-[rgba(59,160,92,0.1)] focus:bg-[rgba(59,160,92,0.1)]':- status === generateStatus.start ||- status === generateStatus.completed,- 'hover:border-border hover:bg-[rgba(59,160,92,0)] focus:bg-[rgba(59,160,92,0)]':- status !== generateStatus.start &&- status !== generateStatus.completed,- },- )}- onSelect={(e) => {- e.preventDefault();- }}- onClick={(e) => {- e.stopPropagation();- }}- >- <div- className="flex items-start gap-2 flex-col w-full"- onClick={() => {- if (- status === generateStatus.start ||- status === generateStatus.completed- ) {- runGenerate({ type });- }- }}- >- <div className="flex justify-start text-text-primary items-center gap-2">- <IconFontFill- name={iconKeyMap[type]}- className="text-accent-primary"- />- {t(`knowledgeDetails.${lowerFirst(type)}`)}- </div>- {(status === generateStatus.start ||- status === generateStatus.completed) && (- <div className="text-text-secondary text-sm">- {t(`knowledgeDetails.generate${type}`)}- </div>- )}- {(status === generateStatus.running ||- status === generateStatus.failed) && (- <div className="flex justify-between items-center w-full px-2.5 py-1">- <div- className={cn(' bg-border-button h-1 rounded-full', {- 'w-[calc(100%-100px)]': status === generateStatus.running,- 'w-[calc(100%-50px)]': status === generateStatus.failed,- })}- >- <div- className={cn('h-1 rounded-full', {- 'bg-state-error': status === generateStatus.failed,- 'bg-accent-primary': status === generateStatus.running,- })}- style={{ width: `${toFixed(percent)}%` }}- ></div>- </div>- {status === generateStatus.running && (- <span>{(toFixed(percent) as string) + '%'}</span>- )}- {status === generateStatus.failed && (- <span- className="text-state-error"- onClick={(e) => {- e.stopPropagation();- runGenerate({ type });- }}- >- <IconFontFill name="reparse" className="text-accent-primary" />- </span>- )}- {status !== generateStatus.failed && (- <span- className="text-state-error"- onClick={(e) => {- e.stopPropagation();- pauseGenerate({ task_id: data.id, type });- }}- >- <CirclePause />- </span>- )}- </div>- )}- {status !== generateStatus.start &&- status !== generateStatus.completed && (- <div className="w-full whitespace-pre-line text-wrap rounded-lg h-fit max-h-[350px] overflow-y-auto scrollbar-auto px-2.5 py-1">- {replaceText(data?.progress_msg || '')}- </div>- )}- </div>- </DropdownMenuItem>- );-};--type GenerateProps = {- disabled?: boolean;-};-const Generate: React.FC<GenerateProps> = (props) => {- const { disabled = false } = props;- const [open, setOpen] = useState(false);- const { graphRunData, raptorRunData } = useTraceGenerate({ open });- const { runGenerate, pauseGenerate } = useDatasetGenerate();- const handleOpenChange = (isOpen: boolean) => {- setOpen(isOpen);- console.log('Dropdown is now', isOpen ? 'open' : 'closed');- };-- return (- <DropdownMenu open={open} onOpenChange={handleOpenChange}>- <DropdownMenuTrigger asChild disabled={disabled}>- <div>- <Tooltip>- <TooltipTrigger asChild>- <Button- disabled={disabled}- className={cn(disabled && '!cursor-not-allowed')}- variant="transparent"- size="icon"- onClick={() => {- if (!disabled) {- handleOpenChange(!open);- }- }}- >- <WandSparkles />- </Button>- </TooltipTrigger>-- <TooltipContent>{t('knowledgeDetails.generate')}</TooltipContent>- </Tooltip>- </div>- </DropdownMenuTrigger>- <DropdownMenuContent className="w-[380px] p-5 flex flex-col gap-2 ">- {Object.values(GenerateType).map((name) => {- const data = (- name === GenerateType.KnowledgeGraph ? graphRunData : raptorRunData- ) as ITraceInfo;- return (- <div key={name}>- <MenuItem- name={name}- runGenerate={runGenerate}- data={data}- pauseGenerate={pauseGenerate}- />- </div>- );- })}- </DropdownMenuContent>- </DropdownMenu>- );-};--export default Generate;--export type IGenerateLogButtonProps = {- finish_at: string;- task_id: string;-};--export type IGenerateLogProps = IGenerateLogButtonProps & {- id?: string;- status: 0 | 1;- message?: string;- created_at?: string;- updated_at?: string;- type?: GenerateType;- className?: string;- onDelete?: () => void;-};-export const GenerateLogButton = (props: IGenerateLogProps) => {- const { t } = useTranslation();- const { message, finish_at, type, onDelete } = props;-- const { handleUnbindTask } = useUnBindTask();-- const handleDeleteFunc = async () => {- const data = await handleUnbindTask({- type: GenerateTypeMap[type as GenerateType],- });- Modal.destroy();- console.log('handleUnbindTask', data);- if (data.code === 0) {- onDelete?.();- }- };-- const handleDelete = () => {- Modal.show({- visible: true,- className: '!w-[560px]',- title:- t('common.delete') +- ' ' +- (type === GenerateType.KnowledgeGraph- ? t('knowledgeDetails.knowledgeGraph')- : t('knowledgeDetails.raptor')),- children: (- <div- className="text-sm text-text-secondary"- dangerouslySetInnerHTML={{- __html: t('knowledgeConfiguration.deleteGenerateModalContent', {- type:- type === GenerateType.KnowledgeGraph- ? t('knowledgeDetails.knowledgeGraph')- : t('knowledgeDetails.raptor'),- }),- }}- ></div>- ),- onVisibleChange: () => {- Modal.destroy();- },- footer: (- <div className="flex justify-end gap-2">- <Button- type="button"- variant={'outline'}- onClick={() => Modal.destroy()}- >- {t('dataflowParser.changeStepModalCancelText')}- </Button>- <Button- type="button"- variant={'secondary'}- className="!bg-state-error text-text-primary"- onClick={() => {- handleDeleteFunc();- }}- >- {t('common.delete')}- </Button>- </div>- ),- });- };-- return (- <div- className={cn('flex bg-bg-card rounded-md py-1 px-3', props.className)}- >- <div className="flex items-center justify-between w-full">- {finish_at && (- <>- <div>- {message || t('knowledgeDetails.generatedOn')}- {formatDate(finish_at)}- </div>- <Trash2- size={14}- className="cursor-pointer"- onClick={(e) => {- console.log('delete');- handleDelete();- e.stopPropagation();- }}- />- </>- )}- {!finish_at && <div>{t('knowledgeDetails.notGenerated')}</div>}- </div>- </div>- );-};diff --git a/web/src/pages/dataset/dataset/generate-button/hook.ts b/web/src/pages/dataset/dataset/generate-button/hook.tsindex a79dd47a8a..34bb5dc2dc 100644--- a/web/src/pages/dataset/dataset/generate-button/hook.ts+++ b/web/src/pages/dataset/dataset/generate-button/hook.ts@@ -6,23 +6,24 @@ import {traceIndex,} from '@/services/knowledge-service';import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';-import { t } from 'i18next';-import { useEffect, useState } from 'react';+import { useTranslation } from 'react-i18next';import { useParams } from 'react-router';import { ProcessingType } from '../../dataset-overview/dataset-common';-import { GenerateType, GenerateTypeMap } from './generate';-export const generateStatus = {- running: 'running',- completed: 'completed',- start: 'start',- failed: 'failed',-};+import { GenerateType, GenerateTypeMap, TraceType } from './constants';enum DatasetKey {generate = 'generate',pauseGenerate = 'pauseGenerate',}+const PollIntervalMs = 5000;++const DatasetGenerateKeys = {+ trace: (type: GenerateType, id?: string, open?: boolean) =>+ [type, id, open] as const,+ traceById: (type: GenerateType, id?: string) => [type, id] as const,+};+export interface ITraceInfo {begin_at: string;chunk_ids: string;@@ -43,69 +44,71 @@ export interface ITraceInfo {update_time: number;}+const useTraceQuery = (+ type: GenerateType,+ traceType: TraceType,+ open: boolean,+ id?: string,+) => {+ return useQuery<ITraceInfo>({+ queryKey: DatasetGenerateKeys.trace(type, id, open),+ gcTime: 0,+ refetchInterval: (query) => {+ const progress = query.state.data?.progress;+ return progress != null && progress >= 0 && progress < 1+ ? PollIntervalMs+ : false;+ },+ retry: 3,+ retryDelay: 1000,+ enabled: open && !!id,+ queryFn: async () => {+ const { data } = await traceIndex(id!, traceType);+ return data?.data ?? {};+ },+ });+};+export const useTraceGenerate = ({ open }: { open: boolean }) => {const { id } = useParams();- const [isLoopGraphRun, setLoopGraphRun] = useState(false);- const [isLoopRaptorRun, setLoopRaptorRun] = useState(false);- const { data: graphRunData, isFetching: graphRunloading } =- useQuery<ITraceInfo>({- queryKey: [GenerateType.KnowledgeGraph, id, open],- // initialData: {},- gcTime: 0,- refetchInterval: isLoopGraphRun ? 5000 : false,- retry: 3,- retryDelay: 1000,- enabled: open,- queryFn: async () => {- const { data } = await traceIndex(id, 'graph');- return data?.data || {};- },- });-- const { data: raptorRunData, isFetching: raptorRunloading } =- useQuery<ITraceInfo>({- queryKey: [GenerateType.Raptor, id, open],- // initialData: {},- gcTime: 0,- refetchInterval: isLoopRaptorRun ? 5000 : false,- retry: 3,- retryDelay: 1000,- enabled: open,- queryFn: async () => {- const { data } = await traceIndex(id, 'raptor');- return data?.data || {};- },- });+ const { data: graphRunData, isFetching: graphRunLoading } = useTraceQuery(+ GenerateType.KnowledgeGraph,+ TraceType.Graph,+ open,+ id,+ );+ const { data: raptorRunData, isFetching: raptorRunLoading } = useTraceQuery(+ GenerateType.Raptor,+ TraceType.Raptor,+ open,+ id,+ );- useEffect(() => {- setLoopGraphRun(- !!(- (graphRunData?.progress || graphRunData?.progress === 0) &&- graphRunData?.progress < 1 &&- graphRunData?.progress >= 0- ),- );- }, [graphRunData?.progress]);+ const { data: artifactRunData, isFetching: artifactRunLoading } =+ useTraceQuery(GenerateType.Artifact, TraceType.Artifact, open, id);+ const { data: skillRunData, isFetching: skillRunLoading } = useTraceQuery(+ GenerateType.ToSkills,+ TraceType.Skill,+ open,+ id,+ );- useEffect(() => {- setLoopRaptorRun(- !!(- (raptorRunData?.progress || raptorRunData?.progress === 0) &&- raptorRunData?.progress < 1 &&- raptorRunData?.progress >= 0- ),- );- }, [raptorRunData?.progress]);return {graphRunData,- graphRunloading,+ graphRunLoading,raptorRunData,- raptorRunloading,+ raptorRunLoading,+ artifactRunData,+ artifactRunLoading,+ skillRunData,+ skillRunLoading,};};export const useUnBindTask = () => {const { id } = useParams();+ const { t } = useTranslation();+const { mutateAsync: handleUnbindTask } = useMutation({mutationKey: [DatasetKey.pauseGenerate],mutationFn: async ({@@ -122,9 +125,6 @@ export const useUnBindTask = () => {});if (data.code === 0) {message.success(t('message.operated'));- // queryClient.invalidateQueries({- // queryKey: [type],- // });}return data;},@@ -135,6 +135,8 @@ export const useDatasetGenerate = () => {const queryClient = useQueryClient();const { id } = useParams();const { handleUnbindTask } = useUnBindTask();+ const { t } = useTranslation();+const {data,isPending: loading,@@ -143,21 +145,24 @@ export const useDatasetGenerate = () => {mutationKey: [DatasetKey.generate],mutationFn: async ({ type }: { type: GenerateType }) => {const indexType =- type === GenerateType.KnowledgeGraph ? 'graph' : 'raptor';- const { data } = await runIndex(id, indexType);+ type === GenerateType.KnowledgeGraph+ ? TraceType.Graph+ : type === GenerateType.Artifact+ ? TraceType.Artifact+ : type === GenerateType.ToSkills+ ? TraceType.Skill+ : TraceType.Raptor;+ const { data } = await runIndex(id!, indexType);if (data.code === 0) {message.success(t('message.operated'));queryClient.invalidateQueries({- queryKey: [type],+ queryKey: DatasetGenerateKeys.traceById(type, id),});}return data;},});- // const pauseGenerate = useCallback(() => {- // // TODO: pause generate- // console.log('pause generate');- // }, []);+const { mutateAsync: pauseGenerate } = useMutation({mutationKey: [DatasetKey.pauseGenerate],mutationFn: async ({@@ -178,9 +183,8 @@ export const useDatasetGenerate = () => {wipe: type === GenerateType.KnowledgeGraph ? false : undefined,});if (data.code === 0 && unbindData.code === 0) {- // message.success(t('message.operated'));queryClient.invalidateQueries({- queryKey: [type],+ queryKey: DatasetGenerateKeys.traceById(type, id),});}return data;diff --git a/web/src/pages/dataset/dataset/generate-button/use-generate-status.ts b/web/src/pages/dataset/dataset/generate-button/use-generate-status.tsnew file mode 100644index 0000000000..e58833cee9--- /dev/null+++ b/web/src/pages/dataset/dataset/generate-button/use-generate-status.ts@@ -0,0 +1,33 @@+import { useMemo } from 'react';++import { GenerateStatus } from './constants';+import { ITraceInfo } from './hook';++export function useGenerateStatus(data?: ITraceInfo) {+ const status = useMemo(() => {+ if (!data) {+ return GenerateStatus.start;+ }+ if (data.progress >= 1) {+ return GenerateStatus.completed;+ } else if (!data.progress && data.progress !== 0) {+ return GenerateStatus.start;+ } else if (data.progress < 0) {+ return GenerateStatus.failed;+ } else if (data.progress < 1) {+ return GenerateStatus.running;+ }+ return GenerateStatus.start;+ }, [data]);++ const percent = useMemo(() => {+ if (status === GenerateStatus.failed) {+ return 100;+ } else if (status === GenerateStatus.running) {+ return data!.progress * 100;+ }+ return 0;+ }, [status, data]);++ return { status, percent };+}diff --git a/web/src/pages/dataset/dataset/index.tsx b/web/src/pages/dataset/dataset/index.tsxindex cfe388e810..c00e352179 100644--- a/web/src/pages/dataset/dataset/index.tsx+++ b/web/src/pages/dataset/dataset/index.tsx@@ -19,7 +19,6 @@ import {useSelectedIds,} from '@/hooks/logic-hooks/use-row-selection';import { useFetchDocumentList } from '@/hooks/use-document-request';-import { useFetchKnowledgeBaseConfiguration } from '@/hooks/use-knowledge-request';import { LucidePlus } from 'lucide-react';import { useEffect } from 'react';import { useTranslation } from 'react-i18next';@@ -28,7 +27,6 @@ import { useManageMetadata } from '../components/metedata/hooks/use-manage-modalimport { ManageMetadataModal } from '../components/metedata/manage-modal';import { useKnowledgeBaseContext } from '../contexts/knowledge-base-context';import { DatasetTable } from './dataset-table';-import Generate from './generate-button/generate';import { ReparseDialog } from './reparse-dialog';import { useBulkOperateDataset } from './use-bulk-operate-dataset';import { useCreateEmptyDocument } from './use-create-empty-document';@@ -57,8 +55,6 @@ export default function Dataset() {checkValue,} = useFetchDocumentList();- const { data: dataSetData } = useFetchKnowledgeBaseConfiguration();-const { filters, onOpenChange, filterGroup } = useSelectDatasetFilters();const {@@ -120,9 +116,6 @@ export default function Dataset() {<div className="text-base font-normal">{t('knowledgeDetails.metadata.manageMetadata')}</div>- {/* <div className="text-sm text-text-secondary">- {t('knowledgeDetails.metadata.manageMetadataForDataset')}- </div> */}</div>),documentIds: selectedRowKeys,@@ -164,38 +157,6 @@ export default function Dataset() {</p></div>}- preChildren={<Generate disabled={!(dataSetData.chunk_count > 0)} />}- // preChildren={- // <Button- // variant={'ghost'}- // className="border border-border-button"- // onClick={() =>- // showManageMetadataModal({- // type: MetadataType.Manage,- // isCanAdd: false,- // isEditField: false,- // isDeleteSingleValue: true,- // title: (- // <div className="flex flex-col gap-2">- // <div className="text-base font-normal">- // {t('knowledgeDetails.metadata.manageMetadata')}- // </div>- // <div className="text-sm text-text-secondary">- // {t(- // 'knowledgeDetails.metadata.manageMetadataForDataset',- // )}- // </div>- // </div>- // ),- // })- // }- // >- // <div className="flex gap-1 items-center">- // <Pen size={14} />- // {t('knowledgeDetails.metadata.metadata')}- // </div>- // </Button>- // }><DropdownMenu><DropdownMenuTrigger asChild>diff --git a/web/src/pages/dataset/sidebar/index.tsx b/web/src/pages/dataset/sidebar/index.tsxindex 15c25cb39c..6df9c2f9f3 100644--- a/web/src/pages/dataset/sidebar/index.tsx+++ b/web/src/pages/dataset/sidebar/index.tsx@@ -1,20 +1,17 @@-import { isEmpty } from 'lodash';-import { useMemo } from 'react';import { useTranslation } from 'react-i18next';import {+ LucideBookText,LucideFolderOpen,LucideLogs,LucideSettings,LucideTextSearch,} from 'lucide-react';-import { IconFontFill } from '@/components/icon-font';import { RAGFlowAvatar } from '@/components/ragflow-avatar';import { Button } from '@/components/ui/button';import { useSecondPathName } from '@/hooks/route-hook';-import { useFetchKnowledgeGraph } from '@/hooks/use-knowledge-request';import { cn, formatBytes } from '@/lib/utils';import { Routes } from '@/routes';import { formatPureDate } from '@/utils/date';@@ -30,7 +27,6 @@ type PropType = {export function SideBar({ dataset: data }: PropType) {const pathName = useSecondPathName();const { id } = useParams();- const { data: routerData } = useFetchKnowledgeGraph();const { t } = useTranslation();const items = useMemo(() => {@@ -55,18 +51,15 @@ export function SideBar({ dataset: data }: PropType) {label: t(`knowledgeDetails.configuration`),key: Routes.DataSetSetting,},+ {+ icon: <LucideBookText className="size-[1em]" />,+ label: t(`knowledgeDetails.compilation`),+ key: Routes.Compilation,+ },];- if (!isEmpty(routerData?.graph)) {- list.push({- icon: <IconFontFill name="knowledgegraph" className="size-[1em]" />,- label: t(`knowledgeDetails.knowledgeGraph`),- key: Routes.KnowledgeGraph,- });- }-return list;- }, [t, routerData]);+ }, [t]);return (<aside className="flex flex-col w-64 relative">diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/add-field-modal.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/add-field-modal.tsxnew file mode 100644index 0000000000..ffd944006f--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/add-field-modal.tsx@@ -0,0 +1,108 @@+import { SelectWithSearch } from '@/components/originui/select-with-search';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Button } from '@/components/ui/button';+import { Form } from '@/components/ui/form';+import { Modal } from '@/components/ui/modal/modal';+import { Textarea } from '@/components/ui/textarea';+import { ICompilationTemplateSection } from '@/interfaces/database/compilation-template';+import { startCase } from 'lodash';+import { useCallback } from 'react';+import { useTranslation } from 'react-i18next';++import { FieldLabelKeyMap } from '@/pages/user-setting/compilation-templates/edit-template/utils';++import { useAddFieldForm } from '../hooks/use-add-field-form';++type AddFieldModalProps = {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ sectionName: string;+ builtinSection?: ICompilationTemplateSection;+ initialField?: Record<string, string>;+ onAdd: (field: Record<string, string>) => void;+};++export function AddFieldModal({+ open,+ onOpenChange,+ sectionName,+ builtinSection,+ initialField,+ onAdd,+}: AddFieldModalProps) {+ const { t } = useTranslation();+ const {+ form,+ fieldKeys,+ hasTypeField,+ typeOptions,+ handleTypeChange,+ handleSubmit,+ } = useAddFieldForm({+ open,+ builtinSection,+ initialField,+ });++ const nonTypeKeys = fieldKeys.filter((key) => key !== 'type');++ const handleClose = useCallback(() => {+ onOpenChange(false);+ }, [onOpenChange]);++ const getFieldLabel = useCallback(+ (key: string) => {+ return FieldLabelKeyMap[key] ? t(FieldLabelKeyMap[key]) : startCase(key);+ },+ [t],+ );++ return (+ <Modal+ open={open}+ onOpenChange={onOpenChange}+ title={`${initialField ? t('setting.editFieldModalTitle') : t('setting.addFieldModalTitle')} - ${startCase(sectionName)}`}+ size="default"+ footer={+ <div className="flex justify-end gap-2">+ <Button type="button" variant="outline" onClick={handleClose}>+ {t('common.cancel')}+ </Button>+ <Button type="button" onClick={handleSubmit(onAdd)}>+ {t('common.confirm')}+ </Button>+ </div>+ }+ >+ <Form {...form}>+ <div className="space-y-4">+ {hasTypeField && (+ <RAGFlowFormItem name="type" label={getFieldLabel('type')}>+ {(field) => (+ <SelectWithSearch+ {...field}+ options={typeOptions}+ allowClear+ onChange={(value) => {+ field.onChange(value);+ handleTypeChange(value);+ }}+ placeholder={t('setting.selectFieldType')}+ />+ )}+ </RAGFlowFormItem>+ )}++ {nonTypeKeys.map((key) => (+ <RAGFlowFormItem key={key} name={key} label={getFieldLabel(key)}>+ <Textarea+ placeholder={t('setting.descriptionPlaceholder')}+ rows={3}+ />+ </RAGFlowFormItem>+ ))}+ </div>+ </Form>+ </Modal>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/basic-info-step.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/basic-info-step.tsxnew file mode 100644index 0000000000..d668293295--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/basic-info-step.tsx@@ -0,0 +1,34 @@+import { AvatarUpload } from '@/components/avatar-upload';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Input } from '@/components/ui/input';+import { Textarea } from '@/components/ui/textarea';+import { useTranslation } from 'react-i18next';++export function BasicInfoStep() {+ const { t } = useTranslation();++ return (+ <div className="max-w-2xl space-y-6 p-5 mx-auto w-full">+ <RAGFlowFormItem+ name="name"+ label={t('setting.groupName')}+ required+ horizontal+ >+ <Input placeholder={t('common.namePlaceholder')} />+ </RAGFlowFormItem>++ <RAGFlowFormItem+ name="description"+ label={t('setting.groupDescription')}+ horizontal+ >+ <Textarea placeholder={t('common.descriptionPlaceholder')} rows={3} />+ </RAGFlowFormItem>++ <RAGFlowFormItem name="avatar" label={t('setting.avatar')} horizontal>+ <AvatarUpload tips={t('knowledgeConfiguration.photoTip')} />+ </RAGFlowFormItem>+ </div>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/blueprints-step.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/blueprints-step.tsxnew file mode 100644index 0000000000..ff6d5f9a9a--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/blueprints-step.tsx@@ -0,0 +1,160 @@+import MarkdownEditor from '@/components/markdown-editor';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Button } from '@/components/ui/button';+import { Textarea } from '@/components/ui/textarea';+import { TreeDataItem, TreeView } from '@/components/ui/tree-view';+import { useFetchWikiPresets } from '@/hooks/use-compilation-template-request';+import { IWikiPreset } from '@/interfaces/database/compilation-template';+import { groupBy } from 'lodash';+import { useCallback, useMemo, useState } from 'react';+import { UseFormReturn, useWatch } from 'react-hook-form';+import { useTranslation } from 'react-i18next';++import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';++type WikiPresetTreeItem = TreeDataItem & {+ _preset?: IWikiPreset;+};++type BlueprintsStepProps = {+ form: UseFormReturn<FormSchemaType>;+ selectedTemplateIndex: number;+ onBack: () => void;+ onSave: () => void;+ isLoading: boolean;+};++function BlueprintsEmptyState() {+ const { t } = useTranslation();++ return (+ <div className="flex-1 flex flex-col items-center p-8 text-center">+ <h3 className="text-2xl font-semibold text-text-primary mb-4">+ {t('setting.blueprints')}+ </h3>+ <p className="text-text-secondary max-w-xl mb-2">+ {t('setting.blueprintsPlaceholderDescription')}+ </p>+ <p className="text-text-secondary max-w-xl">+ {t('setting.blueprintsPlaceholderSkip')}+ </p>+ </div>+ );+}++const buildTreeFromPresets = (presets: IWikiPreset[]): WikiPresetTreeItem[] => {+ const grouped = groupBy(presets, (preset) => preset.topic);++ return Object.entries(grouped).map(([topic, items]) => ({+ id: topic,+ name: topic,+ children: items.map((preset, index) => ({+ id: preset.id,+ name: `${topic} ${index + 1}`,+ _preset: preset,+ })),+ }));+};++export function BlueprintsStep({+ form,+ selectedTemplateIndex,+ onBack,+ onSave,+ isLoading,+}: BlueprintsStepProps) {+ const { t } = useTranslation();+ const { data: presets = [] } = useFetchWikiPresets();+ const [selectedItemId, setSelectedItemId] = useState<string | undefined>();++ const treeData = useMemo(() => buildTreeFromPresets(presets), [presets]);++ const instructionPath =+ `templates.${selectedTemplateIndex}.config.instruction` as const;+ const pageExamplePath =+ `templates.${selectedTemplateIndex}.config.page_example` as const;++ const pageExample = useWatch({+ control: form.control,+ name: pageExamplePath,+ });++ const handleSelect = useCallback(+ (item?: TreeDataItem) => {+ if (!item || item.children) return;+ const presetItem = item as WikiPresetTreeItem;+ const preset = presetItem._preset;+ if (!preset) return;++ setSelectedItemId(item.id);+ form.setValue(instructionPath, preset.instruction, {+ shouldValidate: false,+ });+ form.setValue(pageExamplePath, preset.page_example, {+ shouldValidate: false,+ });+ },+ [form, instructionPath, pageExamplePath],+ );++ const handlePageExampleChange = useCallback(+ (value: string) => {+ form.setValue(pageExamplePath, value, { shouldValidate: false });+ },+ [form, pageExamplePath],+ );++ return (+ <section className="flex-1 flex flex-col min-h-0">+ <div className="flex-1 min-h-0 flex">+ <div className="w-72 shrink-0 border-r border-border-button overflow-y-auto">+ <div className="text-text-secondary text-base px-5 pb-3 pt-10">+ {t('setting.blueprints')}+ </div>+ <TreeView+ data={treeData}+ initialSelectedItemId={selectedItemId}+ onSelectChange={handleSelect}+ expandAll+ />+ </div>++ <div className="flex-1 min-h-0 flex flex-col">+ {selectedItemId ? (+ <div className="flex-1 min-h-0 flex flex-col p-5 gap-4 overflow-y-auto">+ <RAGFlowFormItem+ name={instructionPath}+ label={t('setting.instruction')}+ >+ <Textarea rows={6} />+ </RAGFlowFormItem>++ <div className="flex-1 min-h-0 flex flex-col">+ <MarkdownEditor+ content={String(pageExample ?? '')}+ onChange={handlePageExampleChange}+ />+ </div>+ </div>+ ) : (+ <BlueprintsEmptyState />+ )}++ <footer className="shrink-0 px-5 py-4 border-t border-border-button flex items-center justify-between">+ <Button type="button" variant="outline" onClick={onBack}>+ {t('common.back')}+ </Button>+ <Button+ type="button"+ onClick={onSave}+ loading={isLoading}+ disabled={isLoading}+ >+ {t('common.save')}+ </Button>+ </footer>+ </div>+ </div>+ </section>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/field-card.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/field-card.tsxnew file mode 100644index 0000000000..d0762d3a51--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/field-card.tsx@@ -0,0 +1,54 @@+import { Button } from '@/components/ui/button';+import { Card, CardContent } from '@/components/ui/card';+import { Pencil, Trash2 } from 'lucide-react';++type FieldCardProps = {+ title?: string;+ field: Record<string, string>;+ onEdit: () => void;+ onDelete: () => void;+};++export function FieldCard({ title, field, onEdit, onDelete }: FieldCardProps) {+ return (+ <Card className="border-border-button bg-transparent group">+ <CardContent className="p-4 space-y-3">+ <div className="flex items-start justify-between gap-2">+ <div className="space-y-2 space-x-2 flex-1 min-w-0">+ {title && (+ <span className="text-sm font-medium text-text-primary">+ {title}+ </span>+ )}+ </div>+ <div className="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity shrink-0">+ <Button+ type="button"+ variant="ghost"+ size="icon-xs"+ onClick={onEdit}+ className="text-text-secondary hover:text-text-primary"+ >+ <Pencil className="size-4" />+ </Button>+ <Button+ type="button"+ variant="ghost"+ size="icon-xs"+ onClick={onDelete}+ className="text-text-secondary hover:text-state-error"+ >+ <Trash2 className="size-4" />+ </Button>+ </div>+ </div>++ {field.description && (+ <p className="text-sm text-text-secondary line-clamp-3">+ {field.description}+ </p>+ )}+ </CardContent>+ </Card>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/json-preview-sheet.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/json-preview-sheet.tsxnew file mode 100644index 0000000000..94a8a1ba27--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/json-preview-sheet.tsx@@ -0,0 +1,62 @@+import { useTranslation } from 'react-i18next';++import JsonEditor from '@/components/json-edit';+import { Button } from '@/components/ui/button';+import {+ Sheet,+ SheetContent,+ SheetHeader,+ SheetTitle,+ SheetTrigger,+} from '@/components/ui/sheet';+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@/components/ui/tooltip';+import { Braces } from 'lucide-react';++interface JsonPreviewSheetProps {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ value: Record<string, unknown>;+}++export function JsonPreviewSheet({+ open,+ onOpenChange,+ value,+}: JsonPreviewSheetProps) {+ const { t } = useTranslation();++ return (+ <Sheet open={open} onOpenChange={onOpenChange} modal={false}>+ <Tooltip>+ <TooltipTrigger asChild>+ <SheetTrigger asChild>+ <Button variant="ghost" size="icon" className="size-8">+ <Braces className="size-4" />+ </Button>+ </SheetTrigger>+ </TooltipTrigger>+ <TooltipContent>{t('setting.jsonPreview')}</TooltipContent>+ </Tooltip>+ <SheetContent+ className="w-1/2 max-w-[700px] flex flex-col"+ onInteractOutside={(e) => e.preventDefault()}+ >+ <SheetHeader>+ <SheetTitle>{t('setting.jsonPreview')}</SheetTitle>+ </SheetHeader>+ <div className="flex-1 min-h-0 mt-4">+ <JsonEditor+ value={value}+ height="100%"+ options={{ mode: 'tree', modes: ['tree', 'code'] }}+ defaultExpanded+ />+ </div>+ </SheetContent>+ </Sheet>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/section-field-grid.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/section-field-grid.tsxnew file mode 100644index 0000000000..ee4f5f49b4--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/section-field-grid.tsx@@ -0,0 +1,104 @@+import { Card, CardContent } from '@/components/ui/card';+import { ICompilationTemplateSection } from '@/interfaces/database/compilation-template';+import { cn } from '@/lib/utils';+import { Plus } from 'lucide-react';+import { useMemo } from 'react';+import {+ ArrayPath,+ useFieldArray,+ useFormContext,+ useWatch,+} from 'react-hook-form';+import { useTranslation } from 'react-i18next';++import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';+import { getTypeOptionsFromBuiltinSection } from '@/pages/user-setting/compilation-templates/edit-template/utils';++import { FieldCard } from './field-card';++type SectionFieldGridProps = {+ fieldsPath: ArrayPath<FormSchemaType>;+ sectionName: string;+ builtinSection?: ICompilationTemplateSection;+ onOpenAddField: () => void;+ onEditField: (index: number) => void;+};++export function SectionFieldGrid({+ fieldsPath,+ sectionName,+ builtinSection,+ onOpenAddField,+ onEditField,+}: SectionFieldGridProps) {+ const { t } = useTranslation();+ const form = useFormContext<FormSchemaType>();+ const { fields, remove } = useFieldArray({+ control: form.control,+ name: fieldsPath,+ });++ const isTypedSection = sectionName === 'entity' || sectionName === 'relation';++ const availableTypes = useMemo(+ () => getTypeOptionsFromBuiltinSection(builtinSection),+ [builtinSection],+ );++ const currentFields = useWatch({+ control: form.control,+ name: fieldsPath,+ }) as Record<string, string>[] | undefined;++ const allTypesUsed = useMemo(() => {+ if (!isTypedSection || availableTypes.length === 0) return false;+ const availableSet = new Set(availableTypes.map((type) => type.value));+ const usedAvailableTypes = new Set(+ (currentFields ?? [])+ .map((field) => field.type)+ .filter(+ (type): type is string => Boolean(type) && availableSet.has(type),+ ),+ );+ return usedAvailableTypes.size >= availableTypes.length;+ }, [isTypedSection, availableTypes, currentFields]);++ return (+ <section className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">+ {fields.map((field, index) => {+ const fieldValue = currentFields?.[index] ?? {};+ return (+ <FieldCard+ key={field.id}+ title={isTypedSection ? fieldValue.type : undefined}+ field={fieldValue}+ onEdit={() => onEditField(index)}+ onDelete={() => remove(index)}+ />+ );+ })}++ {!allTypesUsed && (+ <Card+ role="button"+ tabIndex={0}+ onClick={onOpenAddField}+ onKeyDown={(e) => {+ if (e.key === 'Enter' || e.key === ' ') {+ onOpenAddField();+ }+ }}+ className={cn(+ 'border-border-button bg-transparent border-dashed flex flex-col items-center justify-center gap-2 min-h-[140px] cursor-pointer',+ 'hover:border-border-accent hover:text-text-primary text-text-secondary',+ )}+ >+ <CardContent className="flex flex-col items-center justify-center gap-2 p-4">+ <Plus className="size-6" />+ <span className="text-sm font-medium">{t('setting.addField')}</span>+ </CardContent>+ </Card>+ )}+ </section>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/template-configuration.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/template-configuration.tsxnew file mode 100644index 0000000000..c3cb2b0b88--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/template-configuration.tsx@@ -0,0 +1,255 @@+import { ModelTreeSelectFormField } from '@/components/model-tree-select';+import { SelectWithSearch } from '@/components/originui/select-with-search';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Button } from '@/components/ui/button';+import { Input } from '@/components/ui/input';+import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';+import { Textarea } from '@/components/ui/textarea';+import { ICompilationTemplateBuiltin } from '@/interfaces/database/compilation-template';+import { startCase } from 'lodash';+import { useCallback } from 'react';+import { UseFormReturn, useWatch } from 'react-hook-form';+import { useTranslation } from 'react-i18next';++import { CompilationTemplateKind } from '@/constants/compilation';+import { TreeTemplateFields } from '@/pages/user-setting/compilation-templates/edit-template/components/tree-template-fields';+import { useTemplateKindChange } from '@/pages/user-setting/compilation-templates/edit-template/hooks/use-template-kind-change';+import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';+import { SectionTitleKeyMap } from '@/pages/user-setting/compilation-templates/edit-template/utils';++import { useActiveSectionTab } from '../hooks/use-active-section-tab';+import { useAvailableKindOptions } from '../hooks/use-available-kind-options';+import { useBuiltinTemplate } from '../hooks/use-builtin-template';+import { useFieldArrayHandlers } from '../hooks/use-field-array-handlers';+import { useFieldModal } from '../hooks/use-field-modal';+import { useTemplatePreviewSheets } from '../hooks/use-template-preview-sheets';+import { useTemplateSectionData } from '../hooks/use-template-section-data';++import { AddFieldModal } from './add-field-modal';+import { SectionFieldGrid } from './section-field-grid';+import { TemplatePreviewHeader } from './template-preview-header';++type TemplateConfigurationProps = {+ form: UseFormReturn<FormSchemaType>;+ builtins: ICompilationTemplateBuiltin[];+ kindOptions: { label: string; value: string }[];+ selectedTemplateIndex: number;+ onNext: () => void;+ onBack: () => void;+ isArtifacts?: boolean;+ isLoading?: boolean;+};++export function TemplateConfiguration({+ form,+ builtins,+ kindOptions,+ selectedTemplateIndex,+ onNext,+ onBack,+ isArtifacts = false,+ isLoading = false,+}: TemplateConfigurationProps) {+ const { t } = useTranslation();++ const {+ addFieldModalOpen,+ editingFieldIndex,+ setEditingFieldIndex,+ handleModalOpenChange,+ handleOpenAddField,+ handleOpenEditField,+ } = useFieldModal();++ const kind = useWatch({+ control: form.control,+ name: `templates.${selectedTemplateIndex}.kind`,+ });++ const availableKindOptions = useAvailableKindOptions(+ form,+ kindOptions,+ selectedTemplateIndex,+ );++ const { builtinTemplate, sectionNames } = useBuiltinTemplate(builtins, kind);++ const {+ jsonSheetOpen,+ setJsonSheetOpen,+ workflowSheetOpen,+ setWorkflowSheetOpen,+ allFormValues,+ templateName,+ } = useTemplatePreviewSheets(form, selectedTemplateIndex);++ const { activeSectionTab, setActiveSectionTab } =+ useActiveSectionTab(sectionNames);++ const handleKindChange = useTemplateKindChange({+ form,+ index: selectedTemplateIndex,+ builtins,+ });++ const { activeFieldsPath, builtinSection, editingField } =+ useTemplateSectionData(+ form,+ selectedTemplateIndex,+ activeSectionTab,+ builtinTemplate,+ editingFieldIndex,+ );++ const { handleAddField } = useFieldArrayHandlers(+ form,+ activeFieldsPath,+ editingFieldIndex,+ setEditingFieldIndex,+ );++ const renderSectionTabs = useCallback(+ (sectionName: string) => {+ return (+ sectionName === activeSectionTab && (+ <SectionFieldGrid+ key={activeFieldsPath}+ fieldsPath={activeFieldsPath}+ sectionName={sectionName}+ builtinSection={builtinSection}+ onOpenAddField={handleOpenAddField}+ onEditField={handleOpenEditField}+ />+ )+ );+ },+ [+ activeFieldsPath,+ activeSectionTab,+ builtinSection,+ handleOpenAddField,+ handleOpenEditField,+ ],+ );++ return (+ <>+ <TemplatePreviewHeader+ templateName={templateName}+ jsonSheetOpen={jsonSheetOpen}+ onJsonSheetOpenChange={setJsonSheetOpen}+ workflowSheetOpen={workflowSheetOpen}+ onWorkflowSheetOpenChange={setWorkflowSheetOpen}+ allFormValues={allFormValues}+ />+ <div className="flex-1 min-h-0 overflow-y-auto p-5">+ <div className="max-w-4xl mx-auto space-y-6">+ <RAGFlowFormItem+ name={`templates.${selectedTemplateIndex}.name`}+ label={t('setting.templateName')}+ >+ <Input placeholder={t('common.namePlaceholder')} />+ </RAGFlowFormItem>++ <RAGFlowFormItem+ name={`templates.${selectedTemplateIndex}.description`}+ label={t('setting.templateDescription')}+ >+ <Textarea+ placeholder={t('common.descriptionPlaceholder')}+ rows={2}+ />+ </RAGFlowFormItem>++ <ModelTreeSelectFormField+ name={`templates.${selectedTemplateIndex}.llm_id`}+ label={t('setting.llmForExtraction')}+ required+ />++ <RAGFlowFormItem+ name={`templates.${selectedTemplateIndex}.kind`}+ label={t('knowledgeCompilation.builtinTemplates')}+ required+ >+ {(field) => (+ <SelectWithSearch+ value={field.value}+ onChange={(value) => handleKindChange(field, value)}+ disabled={field.disabled}+ options={availableKindOptions}+ placeholder={t('common.selectPlaceholder')}+ />+ )}+ </RAGFlowFormItem>++ <RAGFlowFormItem+ name={`templates.${selectedTemplateIndex}.config.global_rules`}+ label={t('setting.globalRules')}+ >+ <Textarea+ placeholder={t('setting.globalRulesPlaceholder')}+ rows={4}+ />+ </RAGFlowFormItem>++ {kind === CompilationTemplateKind.Tree ? (+ <TreeTemplateFields index={selectedTemplateIndex} />+ ) : (+ sectionNames.length > 0 &&+ activeSectionTab && (+ <Tabs+ value={activeSectionTab}+ onValueChange={setActiveSectionTab}+ className="w-full"+ >+ <TabsList className="w-full justify-start">+ {sectionNames.map((sectionName) => (+ <TabsTrigger+ key={sectionName}+ value={sectionName}+ className="flex-1"+ >+ {t(+ SectionTitleKeyMap[sectionName] ??+ startCase(sectionName),+ )}+ </TabsTrigger>+ ))}+ </TabsList>++ {sectionNames.map((sectionName) => (+ <TabsContent+ key={sectionName}+ value={sectionName}+ className="mt-4"+ >+ {renderSectionTabs(sectionName)}+ </TabsContent>+ ))}+ </Tabs>+ )+ )}+ </div>+ </div>++ <footer className="shrink-0 px-5 py-4 border-t border-border-button flex items-center justify-between">+ <Button type="button" variant="outline" onClick={onBack}>+ {t('common.back')}+ </Button>+ <Button type="button" loading={isLoading} onClick={onNext}>+ {isArtifacts ? t('common.next') : t('common.save')}+ </Button>+ </footer>++ <AddFieldModal+ open={addFieldModalOpen}+ onOpenChange={handleModalOpenChange}+ sectionName={activeSectionTab}+ builtinSection={builtinSection}+ initialField={editingField}+ onAdd={handleAddField}+ />+ </>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/template-preview-header.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/template-preview-header.tsxnew file mode 100644index 0000000000..2909fa6bf0--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/template-preview-header.tsx@@ -0,0 +1,43 @@+import { useTranslation } from 'react-i18next';++import { JsonPreviewSheet } from './json-preview-sheet';+import { WorkflowPreviewSheet } from './workflow-preview-sheet';++interface TemplatePreviewHeaderProps {+ templateName: string | undefined;+ jsonSheetOpen: boolean;+ onJsonSheetOpenChange: (open: boolean) => void;+ workflowSheetOpen: boolean;+ onWorkflowSheetOpenChange: (open: boolean) => void;+ allFormValues: Record<string, unknown>;+}++export function TemplatePreviewHeader({+ templateName,+ jsonSheetOpen,+ onJsonSheetOpenChange,+ workflowSheetOpen,+ onWorkflowSheetOpenChange,+ allFormValues,+}: TemplatePreviewHeaderProps) {+ const { t } = useTranslation();++ return (+ <section className="shrink-0 flex justify-between items-center px-5 py-4 border-b border-border-button">+ <span className="text-lg font-medium text-text-primary">+ {templateName || t('setting.templateName')}+ </span>+ <div className="flex items-center gap-2">+ <JsonPreviewSheet+ open={jsonSheetOpen}+ onOpenChange={onJsonSheetOpenChange}+ value={allFormValues}+ />+ <WorkflowPreviewSheet+ open={workflowSheetOpen}+ onOpenChange={onWorkflowSheetOpenChange}+ />+ </div>+ </section>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/template-sidebar.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/template-sidebar.tsxnew file mode 100644index 0000000000..81c98b4732--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/template-sidebar.tsx@@ -0,0 +1,182 @@+import { Button } from '@/components/ui/button';+import { cn } from '@/lib/utils';+import { Plus, Trash2 } from 'lucide-react';+import { useCallback, type KeyboardEvent, type MouseEvent } from 'react';+import {+ FieldArrayWithId,+ UseFieldArrayReturn,+ UseFormReturn,+} from 'react-hook-form';+import { useTranslation } from 'react-i18next';++import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';+import { DefaultTemplateValues } from '@/pages/user-setting/compilation-templates/edit-template/utils';++import { useTemplateAddButton } from '../hooks/use-template-add-button';++type TemplateSidebarProps = {+ form: UseFormReturn<FormSchemaType>;+ fields: FieldArrayWithId<FormSchemaType, 'templates'>[];+ append: UseFieldArrayReturn<FormSchemaType, 'templates'>['append'];+ remove: UseFieldArrayReturn<FormSchemaType, 'templates'>['remove'];+ kindOptions: { label: string; value: string }[];+ selectedTemplateIndex: number;+ onSelectTemplate: (index: number) => void;+};++type TemplateSidebarItemProps = {+ field: FieldArrayWithId<FormSchemaType, 'templates'>;+ index: number;+ template: FormSchemaType['templates'][number] | undefined;+ isActive: boolean;+ canRemove: boolean;+ onSelectTemplate: (index: number) => void;+ onRemoveTemplate: (index: number) => void;+};++function TemplateSidebarItem({+ field,+ index,+ template,+ isActive,+ canRemove,+ onSelectTemplate,+ onRemoveTemplate,+}: TemplateSidebarItemProps) {+ const { t } = useTranslation();++ const handleClick = useCallback(() => {+ onSelectTemplate(index);+ }, [index, onSelectTemplate]);++ const handleKeyDown = useCallback(+ (e: KeyboardEvent<HTMLDivElement>) => {+ if (e.key === 'Enter' || e.key === ' ') {+ onSelectTemplate(index);+ }+ },+ [index, onSelectTemplate],+ );++ const handleRemoveClick = useCallback(+ (e: MouseEvent<HTMLButtonElement>) => {+ e.stopPropagation();+ onRemoveTemplate(index);+ },+ [index, onRemoveTemplate],+ );++ return (+ <div+ key={field.id}+ role="button"+ tabIndex={0}+ onClick={handleClick}+ onKeyDown={handleKeyDown}+ className={cn(+ 'group flex items-center justify-between px-3 py-2 rounded-md text-sm cursor-pointer',+ isActive+ ? 'bg-bg-card text-text-primary'+ : 'text-text-secondary hover:bg-bg-card hover:text-text-primary',+ )}+ >+ <div className="flex items-center min-w-0 flex-1">+ <span className="truncate">+ {template?.name || `${t('setting.template')} #${index + 1}`}+ </span>+ {template?.kind && (+ <span className="ml-2 shrink-0 text-text-secondary">+ {t(`knowledgeCompilation.kind.${template.kind}`)}+ </span>+ )}+ </div>++ {canRemove && (+ <Button+ type="button"+ variant="ghost"+ size="icon-xs"+ onClick={handleRemoveClick}+ className="opacity-0 group-hover:opacity-100 focus:opacity-100 text-text-secondary hover:text-state-error"+ >+ <Trash2 className="size-4" />+ </Button>+ )}+ </div>+ );+}++export function TemplateSidebar({+ form,+ fields,+ append,+ remove,+ kindOptions,+ selectedTemplateIndex,+ onSelectTemplate,+}: TemplateSidebarProps) {+ const { t } = useTranslation();+ const { templates, isAddButtonHidden } = useTemplateAddButton(+ form,+ kindOptions,+ );++ const handleAddTemplate = useCallback(() => {+ const firstTemplateLlmId = form.getValues('templates.0.llm_id');+ const nextIndex = fields.length;+ append({+ ...DefaultTemplateValues,+ name: `${t('setting.template')} #${nextIndex + 1}`,+ llm_id: firstTemplateLlmId || '',+ });+ onSelectTemplate(nextIndex);+ }, [append, fields.length, form, onSelectTemplate, t]);++ const handleRemoveTemplate = useCallback(+ (index: number) => {+ remove(index);+ if (selectedTemplateIndex === index) {+ onSelectTemplate(Math.max(0, index - 1));+ } else if (selectedTemplateIndex > index) {+ onSelectTemplate(selectedTemplateIndex - 1);+ }+ },+ [onSelectTemplate, remove, selectedTemplateIndex],+ );++ return (+ <aside className="h-full flex flex-col">+ <div className="flex items-center justify-between px-4 py-3 border-b border-border-button">+ <span className="text-sm font-medium text-text-primary">+ {t('setting.templates')}+ </span>+ {!isAddButtonHidden && (+ <Button+ type="button"+ variant="ghost"+ size="icon-xs"+ onClick={handleAddTemplate}+ className="text-text-secondary hover:text-text-primary"+ >+ <Plus className="size-4" />+ </Button>+ )}+ </div>++ <div className="flex-1 overflow-y-auto p-2 space-y-1">+ {fields.map((field, index) => (+ <TemplateSidebarItem+ key={field.id}+ field={field}+ index={index}+ template={templates[index]}+ isActive={selectedTemplateIndex === index}+ canRemove={fields.length > 1}+ onSelectTemplate={onSelectTemplate}+ onRemoveTemplate={handleRemoveTemplate}+ />+ ))}+ </div>+ </aside>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/workflow-preview-sheet.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/workflow-preview-sheet.tsxnew file mode 100644index 0000000000..a34a147145--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/components/workflow-preview-sheet.tsx@@ -0,0 +1,56 @@+import { useTranslation } from 'react-i18next';++import { Button } from '@/components/ui/button';+import {+ Sheet,+ SheetContent,+ SheetHeader,+ SheetTitle,+ SheetTrigger,+} from '@/components/ui/sheet';+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@/components/ui/tooltip';+import { Workflow } from 'lucide-react';++interface WorkflowPreviewSheetProps {+ open: boolean;+ onOpenChange: (open: boolean) => void;+}++export function WorkflowPreviewSheet({+ open,+ onOpenChange,+}: WorkflowPreviewSheetProps) {+ const { t } = useTranslation();++ return (+ <Sheet open={open} onOpenChange={onOpenChange} modal={false}>+ <Tooltip>+ <TooltipTrigger asChild>+ <SheetTrigger asChild>+ <Button variant="ghost" size="icon" className="size-8">+ <Workflow className="size-4" />+ </Button>+ </SheetTrigger>+ </TooltipTrigger>+ <TooltipContent>{t('setting.processFlow')}</TooltipContent>+ </Tooltip>+ <SheetContent+ className="w-1/2 max-w-[700px] flex flex-col"+ onInteractOutside={(e) => e.preventDefault()}+ >+ <SheetHeader>+ <SheetTitle>{t('setting.processFlow')}</SheetTitle>+ </SheetHeader>+ <div className="flex-1 min-h-0 mt-4 flex items-center justify-center">+ <span className="text-text-disabled">+ {t('setting.processFlowComingSoon')}+ </span>+ </div>+ </SheetContent>+ </Sheet>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-active-section-tab.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-active-section-tab.tsnew file mode 100644index 0000000000..75c2b0f93e--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-active-section-tab.ts@@ -0,0 +1,13 @@+import { useEffect, useState } from 'react';++export const useActiveSectionTab = (sectionNames: string[]) => {+ const [activeSectionTab, setActiveSectionTab] = useState<string>('');++ useEffect(() => {+ setActiveSectionTab((prev) =>+ sectionNames.includes(prev) ? prev : (sectionNames[0] ?? ''),+ );+ }, [sectionNames]);++ return { activeSectionTab, setActiveSectionTab };+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-add-field-form.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-add-field-form.tsnew file mode 100644index 0000000000..6d175e0b0d--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-add-field-form.ts@@ -0,0 +1,115 @@+import { ICompilationTemplateSection } from '@/interfaces/database/compilation-template';+import {+ createEmptyField,+ getFieldKeyOrder,+ getTypeOptionsFromBuiltinSection,+} from '@/pages/user-setting/compilation-templates/edit-template/utils';+import { useCallback, useEffect, useMemo } from 'react';+import { useForm } from 'react-hook-form';++type UseAddFieldFormOptions = {+ open: boolean;+ builtinSection?: ICompilationTemplateSection;+ initialField?: Record<string, string>;+};++export const useAddFieldForm = ({+ open,+ builtinSection,+ initialField,+}: UseAddFieldFormOptions) => {+ const form = useForm<Record<string, string>>({+ defaultValues: {},+ });++ const fieldKeys = useMemo(() => {+ const firstField = builtinSection?.fields?.[0];+ const keys = firstField+ ? Object.keys(firstField)+ : ['type', 'description', 'rule'];+ return getFieldKeyOrder(keys);+ }, [builtinSection]);++ const hasTypeField = fieldKeys.includes('type');++ const typeOptions = useMemo(+ () => getTypeOptionsFromBuiltinSection(builtinSection),+ [builtinSection],+ );++ const buildField = useCallback(+ (typeValue: string) => {+ const matched = builtinSection?.fields?.find(+ (field) => field.type === typeValue,+ );+ if (matched) {+ const normalized: Record<string, string> = {};+ fieldKeys.forEach((key) => {+ normalized[key] = (matched as Record<string, string>)[key] ?? '';+ });+ return normalized;+ }+ const empty = createEmptyField(fieldKeys);+ if (hasTypeField) {+ empty.type = typeValue;+ }+ return empty;+ },+ [builtinSection, fieldKeys, hasTypeField],+ );++ useEffect(() => {+ if (!open) return;++ if (initialField) {+ const normalized: Record<string, string> = {};+ fieldKeys.forEach((key) => {+ normalized[key] = initialField[key] ?? '';+ });+ form.reset(normalized);+ return;+ }++ const firstType = typeOptions[0]?.value ?? '';+ form.reset(buildField(firstType));+ }, [buildField, fieldKeys, form, initialField, open, typeOptions]);++ const handleTypeChange = useCallback(+ (value: string) => {+ if (initialField) {+ form.setValue('type', value, {+ shouldDirty: true,+ shouldTouch: true,+ });+ return;+ }++ const nextField = buildField(value);+ Object.entries(nextField).forEach(([key, val]) => {+ form.setValue(key, val, {+ shouldDirty: true,+ shouldTouch: true,+ });+ });+ },+ [buildField, form, initialField],+ );++ const handleSubmit = useCallback(+ (onAdd: (field: Record<string, string>) => void) => {+ return form.handleSubmit((values) => {+ onAdd(values);+ });+ },+ [form],+ );++ return {+ form,+ fieldKeys,+ hasTypeField,+ typeOptions,+ handleTypeChange,+ handleSubmit,+ };+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-available-kind-options.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-available-kind-options.tsnew file mode 100644index 0000000000..19b119369f--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-available-kind-options.ts@@ -0,0 +1,53 @@+import { CompilationTemplateKind } from '@/constants/compilation';+import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';+import { useMemo } from 'react';+import { UseFormReturn, useWatch } from 'react-hook-form';++export const useAvailableKindOptions = (+ form: UseFormReturn<FormSchemaType>,+ kindOptions: { label: string; value: string }[],+ selectedTemplateIndex: number,+) => {+ const kind = useWatch({+ control: form.control,+ name: `templates.${selectedTemplateIndex}.kind`,+ });++ const templates = useWatch({ control: form.control, name: 'templates' });++ const availableKindOptions = useMemo(() => {+ const otherSelectedKinds = new Set(+ templates+ ?.filter((_, index) => index !== selectedTemplateIndex)+ .map((template) => template.kind)+ .filter((value): value is string => Boolean(value)) ?? [],+ );++ const hasOtherNonArtifactsKind = Array.from(otherSelectedKinds).some(+ (value) => value !== CompilationTemplateKind.Artifacts,+ );+ const hasOtherArtifactsKind = otherSelectedKinds.has(+ CompilationTemplateKind.Artifacts,+ );++ return kindOptions.filter((option) => {+ if (option.value === kind) return true;+ if (otherSelectedKinds.has(option.value)) return false;+ if (+ hasOtherNonArtifactsKind &&+ option.value === CompilationTemplateKind.Artifacts+ ) {+ return false;+ }+ if (+ hasOtherArtifactsKind &&+ option.value !== CompilationTemplateKind.Artifacts+ ) {+ return false;+ }+ return true;+ });+ }, [kindOptions, kind, selectedTemplateIndex, templates]);++ return availableKindOptions;+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-builtin-template.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-builtin-template.tsnew file mode 100644index 0000000000..35a3f401eb--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-builtin-template.ts@@ -0,0 +1,35 @@+import { useMemo } from 'react';++import {+ ICompilationTemplateBuiltin,+ ICompilationTemplateSection,+} from '@/interfaces/database/compilation-template';+import {+ isConfigMetaKey,+ sortSectionNames,+} from '@/pages/user-setting/compilation-templates/edit-template/utils';++export const useBuiltinTemplate = (+ builtins: ICompilationTemplateBuiltin[],+ kind: string,+) => {+ const builtinTemplate = useMemo(+ () => builtins.find((template) => template.kind === kind),+ [builtins, kind],+ );++ const sectionNames = useMemo(() => {+ const names = Object.keys(builtinTemplate?.config ?? {}).filter((key) => {+ if (isConfigMetaKey(key)) return false;+ const section = builtinTemplate?.config?.[key];+ return (+ section &&+ typeof section === 'object' &&+ Array.isArray((section as ICompilationTemplateSection).fields)+ );+ });+ return sortSectionNames(names);+ }, [builtinTemplate]);++ return { builtinTemplate, sectionNames };+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-create-next-compilation-template-group.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-create-next-compilation-template-group.tsnew file mode 100644index 0000000000..defd2d96ba--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-create-next-compilation-template-group.ts@@ -0,0 +1,66 @@+import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';+import {+ useCreateCompilationTemplateGroup,+ useFetchCompilationTemplateGroup,+ useUpdateCompilationTemplateGroup,+} from '@/hooks/use-compilation-template-group-request';+import { useFetchBuiltinCompilationTemplates } from '@/hooks/use-compilation-template-request';+import { useFetchDefaultModelDictionary } from '@/hooks/use-llm-request';+import { useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';++import { useCompilationTemplateGroupForm } from '@/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-form';+import { useCompilationTemplateGroupSubmit } from '@/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-submit';++export const useCreateNextCompilationTemplateGroup = () => {+ const { t } = useTranslation();+ const { id } = useParams<{ id: string }>();+ const { navigateToCompilationTemplates } = useNavigatePage();++ const isCreate = !id || id === 'create';++ const { data: detail } = useFetchCompilationTemplateGroup(id);+ const { data: builtins, kindOptions: builtinKindOptions } =+ useFetchBuiltinCompilationTemplates();+ const defaultModelDictionary = useFetchDefaultModelDictionary();++ const { createGroup, loading: createLoading } =+ useCreateCompilationTemplateGroup();+ const { updateGroup, loading: updateLoading } =+ useUpdateCompilationTemplateGroup();++ const kindOptions = useMemo(+ () =>+ builtinKindOptions.map((option) => ({+ ...option,+ label: t(`knowledgeCompilation.kind.${option.value}`),+ })),+ [builtinKindOptions, t],+ );++ const { form } = useCompilationTemplateGroupForm({+ detail,+ defaultLlmId: defaultModelDictionary.llm_id,+ isCreate,+ });++ const { onSubmit } = useCompilationTemplateGroupSubmit({+ isCreate,+ id,+ createGroup,+ updateGroup,+ onSuccess: navigateToCompilationTemplates,+ });++ return {+ id,+ form,+ kindOptions,+ builtins,+ onSubmit,+ isCreate,+ isLoading: isCreate ? createLoading : updateLoading,+ navigateToCompilationTemplates,+ };+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-field-array-handlers.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-field-array-handlers.tsnew file mode 100644index 0000000000..cc687e0119--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-field-array-handlers.ts@@ -0,0 +1,39 @@+import { useCallback } from 'react';+import { ArrayPath, UseFormReturn } from 'react-hook-form';++import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';++export const useFieldArrayHandlers = (+ form: UseFormReturn<FormSchemaType>,+ activeFieldsPath: ArrayPath<FormSchemaType>,+ editingFieldIndex: number | null,+ setEditingFieldIndex: (index: number | null) => void,+) => {+ const handleAddField = useCallback(+ (field: Record<string, string>) => {+ const currentFields =+ (form.getValues(activeFieldsPath) as+ | Record<string, string>[]+ | undefined) ?? [];+ if (editingFieldIndex !== null) {+ const newFields = [...currentFields];+ newFields[editingFieldIndex] = field;+ form.setValue(activeFieldsPath, newFields, {+ shouldValidate: false,+ shouldDirty: true,+ shouldTouch: true,+ });+ } else {+ form.setValue(activeFieldsPath, [...currentFields, field], {+ shouldValidate: false,+ shouldDirty: true,+ shouldTouch: true,+ });+ }+ setEditingFieldIndex(null);+ },+ [activeFieldsPath, editingFieldIndex, form, setEditingFieldIndex],+ );++ return { handleAddField };+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-field-modal.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-field-modal.tsnew file mode 100644index 0000000000..b4f31c5ece--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-field-modal.ts@@ -0,0 +1,35 @@+import { useCallback, useState } from 'react';++export const useFieldModal = () => {+ const [addFieldModalOpen, setAddFieldModalOpen] = useState(false);+ const [editingFieldIndex, setEditingFieldIndex] = useState<number | null>(+ null,+ );++ const handleModalOpenChange = useCallback(+ (open: boolean) => {+ setAddFieldModalOpen(open);+ if (!open) setEditingFieldIndex(null);+ },+ [setAddFieldModalOpen],+ );++ const handleOpenAddField = useCallback(() => {+ setEditingFieldIndex(null);+ setAddFieldModalOpen(true);+ }, []);++ const handleOpenEditField = useCallback((index: number) => {+ setEditingFieldIndex(index);+ setAddFieldModalOpen(true);+ }, []);++ return {+ addFieldModalOpen,+ editingFieldIndex,+ setEditingFieldIndex,+ handleModalOpenChange,+ handleOpenAddField,+ handleOpenEditField,+ };+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-add-button.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-add-button.tsnew file mode 100644index 0000000000..a0e3d6b682--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-add-button.ts@@ -0,0 +1,29 @@+import { CompilationTemplateKind } from '@/constants/compilation';+import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';+import { UseFormReturn, useWatch } from 'react-hook-form';++export const useTemplateAddButton = (+ form: UseFormReturn<FormSchemaType>,+ kindOptions: { label: string; value: string }[],+) => {+ const templates =+ useWatch({ control: form.control, name: 'templates' }) ?? [];++ const hasTemplateWithoutKind = templates.some((template) => !template.kind);+ const hasArtifactsTemplate = templates.some(+ (template) => template.kind === CompilationTemplateKind.Artifacts,+ );+ const selectedKinds = new Set(+ templates+ .map((template) => template.kind)+ .filter((kind): kind is string => Boolean(kind)),+ );+ const allKindsSelected =+ kindOptions.length > 0 &&+ kindOptions.every((option) => selectedKinds.has(option.value));++ const isAddButtonHidden =+ hasTemplateWithoutKind || hasArtifactsTemplate || allKindsSelected;++ return { templates, isAddButtonHidden };+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-preview-sheets.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-preview-sheets.tsnew file mode 100644index 0000000000..524d6eb76d--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-preview-sheets.ts@@ -0,0 +1,28 @@+import { useState } from 'react';+import { UseFormReturn, useWatch } from 'react-hook-form';++import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';++export function useTemplatePreviewSheets(+ form: UseFormReturn<FormSchemaType>,+ selectedTemplateIndex: number,+) {+ const [jsonSheetOpen, setJsonSheetOpen] = useState(false);+ const [workflowSheetOpen, setWorkflowSheetOpen] = useState(false);++ const allFormValues = useWatch({ control: form.control });++ const templateName = useWatch({+ control: form.control,+ name: `templates.${selectedTemplateIndex}.name`,+ });++ return {+ jsonSheetOpen,+ setJsonSheetOpen,+ workflowSheetOpen,+ setWorkflowSheetOpen,+ allFormValues,+ templateName,+ };+}diff --git a/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-section-data.ts b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-section-data.tsnew file mode 100644index 0000000000..07c6a2bb6c--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/hooks/use-template-section-data.ts@@ -0,0 +1,40 @@+import { useMemo } from 'react';+import { ArrayPath, UseFormReturn } from 'react-hook-form';++import {+ ICompilationTemplateBuiltin,+ ICompilationTemplateSection,+} from '@/interfaces/database/compilation-template';+import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema';++export const useTemplateSectionData = (+ form: UseFormReturn<FormSchemaType>,+ selectedTemplateIndex: number,+ activeSectionTab: string,+ builtinTemplate: ICompilationTemplateBuiltin | undefined,+ editingFieldIndex: number | null,+) => {+ const activeSectionPath = `templates.${selectedTemplateIndex}.config.${activeSectionTab}`;+ const activeFieldsPath =+ `${activeSectionPath}.fields` as ArrayPath<FormSchemaType>;++ const builtinSection = useMemo(() => {+ return builtinTemplate?.config?.[activeSectionTab] as+ | ICompilationTemplateSection+ | undefined;+ }, [activeSectionTab, builtinTemplate?.config]);++ const editingField = useMemo(() => {+ if (editingFieldIndex === null) return undefined;+ return ((form.getValues(activeFieldsPath) as+ | Record<string, string>[]+ | undefined) ?? [])[editingFieldIndex];+ }, [activeFieldsPath, editingFieldIndex, form]);++ return {+ activeSectionPath,+ activeFieldsPath,+ builtinSection,+ editingField,+ };+};diff --git a/web/src/pages/user-setting/compilation-templates/create-next/index.tsx b/web/src/pages/user-setting/compilation-templates/create-next/index.tsxnew file mode 100644index 0000000000..3484aecf10--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/create-next/index.tsx@@ -0,0 +1,170 @@+import BackButton from '@/components/back-button';+import { CustomTimeline } from '@/components/originui/timeline';+import { Button } from '@/components/ui/button';+import { Form } from '@/components/ui/form';+import {+ ResizableHandle,+ ResizablePanel,+ ResizablePanelGroup,+} from '@/components/ui/resizable';+import { CompilationTemplateKind } from '@/constants/compilation';+import { Routes } from '@/routes';+import { useCallback, useMemo, useState } from 'react';+import { useFieldArray, useWatch } from 'react-hook-form';+import { useTranslation } from 'react-i18next';++import { BasicInfoStep } from './components/basic-info-step';+import { BlueprintsStep } from './components/blueprints-step';+import { TemplateConfiguration } from './components/template-configuration';+import { TemplateSidebar } from './components/template-sidebar';+import { useCreateNextCompilationTemplateGroup } from './hooks/use-create-next-compilation-template-group';++export default function CreateNextCompilationTemplate() {+ const { t } = useTranslation();+ const [activeStep, setActiveStep] = useState(1);+ const [selectedTemplateIndex, setSelectedTemplateIndex] = useState(0);++ const { form, kindOptions, builtins, onSubmit, isCreate, isLoading } =+ useCreateNextCompilationTemplateGroup();++ const { fields, append, remove } = useFieldArray({+ control: form.control,+ name: 'templates',+ });++ const selectedKind = useWatch({+ control: form.control,+ name: `templates.${selectedTemplateIndex}.kind`,+ });++ const isArtifacts = selectedKind === CompilationTemplateKind.Artifacts;++ const timelineNodes = useMemo(+ () => [+ {+ id: 'basic-info',+ title: t('setting.basicInfo'),+ content: t('setting.basicInfoDescription'),+ },+ {+ id: 'configuration',+ title: t('setting.templateWizardConfiguration'),+ content: t('setting.templateWizardConfigurationDescription'),+ },+ ...(isArtifacts+ ? [+ {+ id: 'blueprints',+ title: t('setting.blueprints'),+ content: t('setting.blueprintsDescription'),+ },+ ]+ : []),+ ],+ [isArtifacts, t],+ );++ const handleNext = useCallback(async () => {+ if (activeStep === 1) {+ const valid = await form.trigger(['name', 'description']);+ if (valid) setActiveStep(2);+ } else if (activeStep === 2) {+ const valid = await form.trigger(`templates.${selectedTemplateIndex}`);+ if (!valid) return;+ if (isArtifacts) {+ setActiveStep(3);+ } else {+ form.handleSubmit(onSubmit)();+ }+ }+ }, [activeStep, form, isArtifacts, onSubmit, selectedTemplateIndex]);++ const handleBack = useCallback(() => {+ setActiveStep(1);+ }, []);++ return (+ <section className="h-full flex flex-col bg-bg-base">+ <header className="shrink-0 px-5 py-4 border-b border-border-button flex gap-3">+ <BackButton+ to={`${Routes.UserSetting}${Routes.CompilationTemplates}`}+ />+ <h2 className="font-medium text-text-secondary">+ {isCreate+ ? t('setting.addTemplateGroup')+ : t('setting.editTemplateGroup')}+ </h2>+ </header>++ <div className="shrink-0 px-5 py-4 border-b border-border-button">+ <CustomTimeline+ nodes={timelineNodes}+ activeStep={activeStep}+ onStepChange={(step) => {+ // Allow clicking back to completed steps only.+ if (step < activeStep) {+ setActiveStep(step);+ }+ }}+ orientation="horizontal"+ />+ </div>++ <Form {...form}>+ <form className="flex-1 min-h-0 flex">+ {activeStep === 2 ? (+ <ResizablePanelGroup direction="horizontal" className="flex-1">+ <ResizablePanel defaultSize={25} minSize={20} maxSize={40}>+ <TemplateSidebar+ form={form}+ fields={fields}+ append={append}+ remove={remove}+ kindOptions={kindOptions}+ selectedTemplateIndex={selectedTemplateIndex}+ onSelectTemplate={setSelectedTemplateIndex}+ />+ </ResizablePanel>+ <ResizableHandle withHandle />+ <ResizablePanel className="min-h-0 flex flex-col">+ <TemplateConfiguration+ form={form}+ builtins={builtins}+ kindOptions={kindOptions}+ selectedTemplateIndex={selectedTemplateIndex}+ onNext={handleNext}+ onBack={handleBack}+ isArtifacts={isArtifacts}+ isLoading={isLoading}+ />+ </ResizablePanel>+ </ResizablePanelGroup>+ ) : (+ <div className="flex-1 min-h-0 flex flex-col">+ {activeStep === 1 && (+ <>+ <BasicInfoStep />+ <footer className="shrink-0 px-5 py-4 border-t border-border-button flex items-center justify-end">+ <Button type="button" onClick={handleNext}>+ {t('common.next')}+ </Button>+ </footer>+ </>+ )}++ {activeStep === 3 && isArtifacts && (+ <BlueprintsStep+ form={form}+ selectedTemplateIndex={selectedTemplateIndex}+ onBack={() => setActiveStep(2)}+ onSave={form.handleSubmit(onSubmit)}+ isLoading={isLoading}+ />+ )}+ </div>+ )}+ </form>+ </Form>+ </section>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/components/fields-section.tsx b/web/src/pages/user-setting/compilation-templates/edit-template/components/fields-section.tsxnew file mode 100644index 0000000000..0227fd34c9--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/components/fields-section.tsx@@ -0,0 +1,174 @@+import { Collapse } from '@/components/collapse';+import { SelectWithSearch } from '@/components/originui/select-with-search';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Button } from '@/components/ui/button';+import { Card, CardContent } from '@/components/ui/card';+import { Textarea } from '@/components/ui/textarea';+import { ICompilationTemplateSection } from '@/interfaces/database/compilation-template';+import { startCase } from 'lodash';+import { Plus, Trash2 } from 'lucide-react';+import { useMemo } from 'react';+import {+ ArrayPath,+ Path,+ useFieldArray,+ useFormContext,+} from 'react-hook-form';+import { useTranslation } from 'react-i18next';++import { useFieldTypeChange } from '../hooks/use-field-type-change';+import { FormSchemaType } from '../schema';+import { createEmptyField, FieldLabelKeyMap } from '../utils';++type FieldsSectionProps = {+ name: Path<FormSchemaType>;+ title: string;+ fieldKeys: string[];+ defaultOpen?: boolean;+ builtinSection?: ICompilationTemplateSection;+};++export function FieldsSection({+ name,+ title,+ fieldKeys,+ defaultOpen = false,+ builtinSection,+}: FieldsSectionProps) {+ const { t } = useTranslation();+ const form = useFormContext<FormSchemaType>();+ const fieldsPath = `${name}.fields` as ArrayPath<FormSchemaType>;++ const { fields, append, remove } = useFieldArray({+ name: fieldsPath,+ control: form.control,+ });++ const typeOptions = useMemo(() => {+ const typeSet = new Set<string>();+ builtinSection?.fields?.forEach((field) => {+ if (field.type) typeSet.add(field.type);+ });+ return Array.from(typeSet)+ .sort()+ .map((value) => ({ label: value, value }));+ }, [builtinSection]);++ return (+ <Collapse defaultOpen={defaultOpen} title={title}>+ <section className="space-y-4">+ <RAGFlowFormItem+ name={`${name}.description`}+ label={t('setting.description')}+ >+ <Textarea+ placeholder={t('setting.descriptionPlaceholder')}+ rows={3}+ />+ </RAGFlowFormItem>++ <section className="space-y-3">+ {fields.map((field, index) => (+ <Card+ key={field.id}+ className="border-border-button bg-transparent transition-colors has-[button:hover]:border-state-error"+ >+ <CardContent className="p-4 space-y-4">+ <div className="flex items-center justify-between">+ <span className="text-sm text-text-secondary">+ {t('setting.field')} #{index + 1}+ </span>+ {fields.length > 1 && (+ <Button+ type="button"+ variant="ghost"+ size="icon-xs"+ onClick={() => remove(index)}+ className="text-text-secondary hover:text-state-error"+ >+ <Trash2 className="size-4" />+ </Button>+ )}+ </div>++ {fieldKeys.map((key) => (+ <FieldFormItem+ key={key}+ fieldKey={key}+ fieldName={`${fieldsPath}.${index}.${key}`}+ typeOptions={typeOptions}+ builtinSection={builtinSection}+ fieldsPath={fieldsPath}+ index={index}+ />+ ))}+ </CardContent>+ </Card>+ ))}+ </section>++ <Button+ type="button"+ variant="outline"+ onClick={() => append(createEmptyField(fieldKeys))}+ >+ <Plus className="size-4 mr-2" />+ {t('setting.addField')}+ </Button>+ </section>+ </Collapse>+ );+}++type FieldFormItemProps = {+ fieldKey: string;+ fieldName: string;+ typeOptions: { label: string; value: string }[];+ builtinSection?: ICompilationTemplateSection;+ fieldsPath: ArrayPath<FormSchemaType>;+ index: number;+};++function FieldFormItem({+ fieldKey,+ fieldName,+ typeOptions,+ builtinSection,+ fieldsPath,+ index,+}: FieldFormItemProps) {+ const { t } = useTranslation();+ const form = useFormContext<FormSchemaType>();+ const handleTypeChange = useFieldTypeChange({+ form,+ builtinSection,+ fieldsPath: fieldsPath as `templates.${number}.config.${string}.fields`,+ index,+ });++ return (+ <RAGFlowFormItem+ name={fieldName}+ label={+ FieldLabelKeyMap[fieldKey]+ ? t(FieldLabelKeyMap[fieldKey])+ : startCase(fieldKey)+ }+ required+ >+ {fieldKey === 'type' ? (+ (field) => (+ <SelectWithSearch+ options={typeOptions}+ value={field.value}+ onChange={(value) => handleTypeChange(field, value)}+ disabled={field.disabled}+ placeholder={t('common.selectPlaceholder')}+ />+ )+ ) : (+ <Textarea placeholder={t('setting.descriptionPlaceholder')} rows={2} />+ )}+ </RAGFlowFormItem>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/components/template-card.tsx b/web/src/pages/user-setting/compilation-templates/edit-template/components/template-card.tsxnew file mode 100644index 0000000000..eaa73c157a--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/components/template-card.tsx@@ -0,0 +1,213 @@+import { Collapse } from '@/components/collapse';+import { ModelTreeSelectFormField } from '@/components/model-tree-select';+import { SelectWithSearch } from '@/components/originui/select-with-search';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Button } from '@/components/ui/button';+import { Card, CardContent } from '@/components/ui/card';+import { Input } from '@/components/ui/input';+import { Textarea } from '@/components/ui/textarea';+import {+ ICompilationTemplateBuiltin,+ ICompilationTemplateSection,+} from '@/interfaces/database/compilation-template';+import { Trash2 } from 'lucide-react';+import { useCallback, useMemo } from 'react';+import { UseFormReturn, useWatch } from 'react-hook-form';+import { useTranslation } from 'react-i18next';++import { CompilationTemplateKind } from '@/constants/compilation';+import { useTemplateKindChange } from '../hooks/use-template-kind-change';+import { FormSchemaType } from '../schema';+import {+ DefaultFieldKeys,+ getFieldKeyOrder,+ isConfigMetaKey,+ SectionTitleKeyMap,+ sortSectionNames,+} from '../utils';+import { FieldsSection } from './fields-section';+import { TreeTemplateFields } from './tree-template-fields';++type TemplateCardProps = {+ index: number;+ form: UseFormReturn<FormSchemaType>;+ kindOptions: { label: string; value: string }[];+ builtins: ICompilationTemplateBuiltin[];+ onRemove: (index: number) => void;+ canRemove: boolean;+};++export function TemplateCard({+ index,+ form,+ kindOptions,+ builtins,+ onRemove,+ canRemove,+}: TemplateCardProps) {+ const { t } = useTranslation();++ const kind = useWatch({+ control: form.control,+ name: `templates.${index}.kind`,+ });++ const builtinTemplate = useMemo(+ () => builtins.find((template) => template.kind === kind),+ [builtins, kind],+ );++ const sectionNames = useMemo(() => {+ const names = Object.keys(builtinTemplate?.config ?? {}).filter(+ (key) => !isConfigMetaKey(key),+ );+ return sortSectionNames(names);+ }, [builtinTemplate]);++ const handleRemove = useCallback(() => {+ onRemove(index);+ }, [index, onRemove]);++ const handleRemoveClick = useCallback(+ (e: React.MouseEvent<HTMLButtonElement>) => {+ e.stopPropagation();+ handleRemove();+ },+ [handleRemove],+ );++ const handleKindChange = useTemplateKindChange({+ form,+ index,+ builtins,+ });++ return (+ <Card className="border-border-button">+ <CardContent className="p-4">+ <Collapse+ title={+ <div>+ <span className="text-sm font-medium text-text-primary">+ {t('setting.template')} #{index + 1}+ </span>+ <span className="ml-2 text-xs text-text-secondary">+ {kindOptions.find((option) => option.value === kind)?.label}+ </span>+ </div>+ }+ rightContent={+ canRemove && (+ <Button+ type="button"+ variant="ghost"+ size="icon-xs"+ onClick={handleRemoveClick}+ className="text-text-secondary hover:text-state-error"+ >+ <Trash2 className="size-4" />+ </Button>+ )+ }+ defaultOpen+ >+ <div className="space-y-4">+ {kind !== CompilationTemplateKind.Tree && (+ <RAGFlowFormItem+ name={`templates.${index}.name`}+ label={t('setting.templateName')}+ >+ <Input placeholder={t('common.namePlaceholder')} />+ </RAGFlowFormItem>+ )}++ <RAGFlowFormItem+ name={`templates.${index}.description`}+ label={t('setting.templateDescription')}+ >+ <Textarea+ placeholder={t('common.descriptionPlaceholder')}+ rows={2}+ />+ </RAGFlowFormItem>++ <ModelTreeSelectFormField+ name={`templates.${index}.llm_id`}+ label={t('setting.llmForExtraction')}+ required+ />++ <RAGFlowFormItem+ name={`templates.${index}.kind`}+ label={t('knowledgeCompilation.builtinTemplates')}+ required+ >+ {(field) => (+ <SelectWithSearch+ value={field.value}+ onChange={(value) => handleKindChange(field, value)}+ disabled={field.disabled}+ options={kindOptions}+ placeholder={t('common.selectPlaceholder')}+ />+ )}+ </RAGFlowFormItem>++ {kind === CompilationTemplateKind.Artifacts && (+ <RAGFlowFormItem+ name={`templates.${index}.config.example`}+ label={t('setting.example')}+ >+ <Textarea+ placeholder={t('setting.examplePlaceholder')}+ rows={4}+ />+ </RAGFlowFormItem>+ )}++ {kind === CompilationTemplateKind.Tree ? (+ <TreeTemplateFields index={index} />+ ) : (+ sectionNames.map((sectionName, sectionIndex) => {+ const builtinSection = builtinTemplate?.config?.[sectionName];++ const firstField = (+ builtinSection as ICompilationTemplateSection | undefined+ )?.fields?.[0];+ const firstFieldKeys = firstField+ ? Object.keys(firstField)+ : DefaultFieldKeys;+ const fieldKeys = getFieldKeyOrder(firstFieldKeys);++ return (+ <FieldsSection+ key={sectionName}+ name={+ `templates.${index}.config.${sectionName}` as `templates.${number}.config.${string}`+ }+ title={t(SectionTitleKeyMap[sectionName] ?? sectionName)}+ fieldKeys={fieldKeys}+ defaultOpen={sectionIndex === 0}+ builtinSection={+ builtinSection as ICompilationTemplateSection | undefined+ }+ />+ );+ })+ )}++ <RAGFlowFormItem+ name={`templates.${index}.config.global_rules`}+ label={t('setting.globalRules')}+ >+ <Textarea+ placeholder={t('setting.globalRulesPlaceholder')}+ rows={4}+ />+ </RAGFlowFormItem>+ </div>+ </Collapse>+ </CardContent>+ </Card>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/components/tree-template-fields.tsx b/web/src/pages/user-setting/compilation-templates/edit-template/components/tree-template-fields.tsxnew file mode 100644index 0000000000..d18f49a05f--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/components/tree-template-fields.tsx@@ -0,0 +1,52 @@+import { Collapse } from '@/components/collapse';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { SliderInputFormField } from '@/components/slider-input-form-field';+import { SwitchFormField } from '@/components/switch-fom-field';+import { Textarea } from '@/components/ui/textarea';+import { useTranslation } from 'react-i18next';++type TreeTemplateFieldsProps = {+ index: number;+};++export function TreeTemplateFields({ index }: TreeTemplateFieldsProps) {+ const { t } = useTranslation();++ return (+ <Collapse defaultOpen title={t('setting.raptorTreeSettings')}>+ <div className="space-y-4">+ <RAGFlowFormItem+ name={`templates.${index}.config.raptor.prompt`}+ label={t('setting.summarizationPrompt')}+ >+ <Textarea+ placeholder={t('setting.descriptionPlaceholder')}+ rows={6}+ />+ </RAGFlowFormItem>++ <SliderInputFormField+ name={`templates.${index}.config.raptor.max_token`}+ label={t('setting.maxToken')}+ max={2048}+ min={0}+ step={1}+ />+ <SliderInputFormField+ name={`templates.${index}.config.raptor.threshold`}+ label={t('setting.threshold')}+ step={0.01}+ max={1}+ min={0}+ />++ <SwitchFormField+ name={`templates.${index}.config.raptor.rechunk`}+ label={t('setting.rechunkByTreeLeaves')}+ tooltip={t('setting.rechunkByTreeLeavesTip')}+ vertical={false}+ />+ </div>+ </Collapse>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-data.ts b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-data.tsnew file mode 100644index 0000000000..4de5f26ac8--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-data.ts@@ -0,0 +1,49 @@+import {+ useCreateCompilationTemplateGroup,+ useFetchCompilationTemplateGroup,+ useUpdateCompilationTemplateGroup,+} from '@/hooks/use-compilation-template-group-request';+import { useFetchBuiltinCompilationTemplates } from '@/hooks/use-compilation-template-request';+import { useFetchDefaultModelDictionary } from '@/hooks/use-llm-request';+import { useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';++export const useCompilationTemplateGroupData = () => {+ const { id } = useParams<{ id: string }>();+ const isCreate = id === 'create';+ const { t } = useTranslation();++ const { data: detail } = useFetchCompilationTemplateGroup(id);+ const { data: builtins, kindOptions: builtinKindOptions } =+ useFetchBuiltinCompilationTemplates();+ const defaultModelDictionary = useFetchDefaultModelDictionary();++ const { createGroup, loading: createLoading } =+ useCreateCompilationTemplateGroup();+ const { updateGroup, loading: updateLoading } =+ useUpdateCompilationTemplateGroup();++ const kindOptions = useMemo(+ () =>+ builtinKindOptions.map((option) => ({+ ...option,+ label: t(`knowledgeCompilation.kind.${option.value}`),+ })),+ [builtinKindOptions, t],+ );++ const isLoading = createLoading || updateLoading;++ return {+ id,+ isCreate,+ detail,+ builtins,+ kindOptions,+ defaultModelDictionary,+ createGroup,+ updateGroup,+ isLoading,+ };+};diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-form.ts b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-form.tsnew file mode 100644index 0000000000..01b4524ff3--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-form.ts@@ -0,0 +1,55 @@+import { zodResolver } from '@hookform/resolvers/zod';+import { useEffect, useMemo } from 'react';+import { useForm } from 'react-hook-form';+import { useTranslation } from 'react-i18next';++import { ICompilationTemplateGroup } from '@/interfaces/database/compilation-template';++import { buildFormSchema, FormSchemaType } from '../schema';+import { DefaultValues, transformGroupDetailToForm } from '../utils';++type UseCompilationTemplateGroupFormOptions = {+ detail?: ICompilationTemplateGroup;+ defaultLlmId?: string;+ isCreate: boolean;+};++export const useCompilationTemplateGroupForm = ({+ detail,+ defaultLlmId,+ isCreate,+}: UseCompilationTemplateGroupFormOptions) => {+ const { t } = useTranslation();++ const defaultValues = useMemo<FormSchemaType>(() => {+ if (!isCreate) return DefaultValues;+ return {+ ...DefaultValues,+ templates: [+ {+ ...DefaultValues.templates[0],+ name: `${t('setting.template')} #1`,+ },+ ],+ };+ }, [isCreate, t]);++ const form = useForm<FormSchemaType>({+ resolver: zodResolver(buildFormSchema(t)),+ defaultValues,+ });++ useEffect(() => {+ if (detail) {+ form.reset(transformGroupDetailToForm(detail));+ } else if (+ isCreate &&+ defaultLlmId &&+ !form.getValues('templates.0.llm_id')+ ) {+ form.setValue('templates.0.llm_id', defaultLlmId);+ }+ }, [defaultLlmId, detail, form, isCreate]);++ return { form };+};diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-submit.ts b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-submit.tsnew file mode 100644index 0000000000..aeddb32d7f--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-submit.ts@@ -0,0 +1,48 @@+import { useCallback } from 'react';++import {+ ICreateCompilationTemplateGroupRequestBody,+ IUpdateCompilationTemplateGroupRequestBody,+} from '@/interfaces/request/compilation-template';++import { FormSchemaType } from '../schema';+import { transformFormToPayload } from '../utils';++type UseCompilationTemplateGroupSubmitOptions = {+ isCreate: boolean;+ id?: string;+ createGroup: (+ params: ICreateCompilationTemplateGroupRequestBody,+ ) => Promise<{ code: number } & Record<string, unknown>>;+ updateGroup: (+ id: string,+ params: IUpdateCompilationTemplateGroupRequestBody,+ ) => Promise<{ code: number } & Record<string, unknown>>;+ onSuccess: () => void;+};++export const useCompilationTemplateGroupSubmit = ({+ isCreate,+ id,+ createGroup,+ updateGroup,+ onSuccess,+}: UseCompilationTemplateGroupSubmitOptions) => {+ const onSubmit = useCallback(+ async (values: FormSchemaType) => {+ const payload = transformFormToPayload(values);+ let result;+ if (isCreate) {+ result = await createGroup(payload);+ } else if (id) {+ result = await updateGroup(id, payload);+ }+ if (result?.code === 0) {+ onSuccess();+ }+ },+ [createGroup, id, isCreate, onSuccess, updateGroup],+ );++ return { onSubmit };+};diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-edit-compilation-template-group.ts b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-edit-compilation-template-group.tsnew file mode 100644index 0000000000..210ff89fed--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-edit-compilation-template-group.ts@@ -0,0 +1,51 @@+import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';+import { useWatch } from 'react-hook-form';++import { DefaultValues } from '../utils';+import { useCompilationTemplateGroupData } from './use-compilation-template-group-data';+import { useCompilationTemplateGroupForm } from './use-compilation-template-group-form';+import { useCompilationTemplateGroupSubmit } from './use-compilation-template-group-submit';++export const useEditCompilationTemplateGroup = () => {+ const {+ id,+ isCreate,+ detail,+ builtins,+ kindOptions,+ defaultModelDictionary,+ createGroup,+ updateGroup,+ isLoading,+ } = useCompilationTemplateGroupData();++ const { navigateToCompilationTemplates } = useNavigatePage();++ const { form } = useCompilationTemplateGroupForm({+ detail,+ defaultLlmId: defaultModelDictionary.llm_id,+ isCreate,+ });++ const watchedValues = useWatch({ control: form.control }) ?? DefaultValues;++ const { onSubmit } = useCompilationTemplateGroupSubmit({+ isCreate,+ id,+ createGroup,+ updateGroup,+ onSuccess: navigateToCompilationTemplates,+ });++ return {+ id,+ isCreate,+ form,+ watchedValues,+ kindOptions,+ builtins,+ onSubmit,+ isLoading,+ navigateToCompilationTemplates,+ };+};diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-field-type-change.ts b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-field-type-change.tsnew file mode 100644index 0000000000..3ea3229bf0--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-field-type-change.ts@@ -0,0 +1,66 @@+import {+ ICompilationTemplateField,+ ICompilationTemplateSection,+} from '@/interfaces/database/compilation-template';+import { useCallback } from 'react';+import { UseFormReturn } from 'react-hook-form';++import { FormSchemaType } from '../schema';++type FieldLike = {+ value: string;+ onChange: (value: string) => void;+};++type UseFieldTypeChangeOptions = {+ form: UseFormReturn<FormSchemaType>;+ builtinSection?: ICompilationTemplateSection;+ fieldsPath: `templates.${number}.config.${string}.fields`;+ index: number;+};++const FIELD_SYNC_KEYS: Array<keyof ICompilationTemplateField> = [+ 'description',+ 'rule',+];++export const useFieldTypeChange = ({+ form,+ builtinSection,+ fieldsPath,+ index,+}: UseFieldTypeChangeOptions) => {+ return useCallback(+ (field: FieldLike, value: string) => {+ if (!value || value === field.value) {+ field.onChange(value);+ return;+ }++ const matchedField = builtinSection?.fields?.find(+ (builtinField) => builtinField.type === value,+ );++ const currentField = form.getValues(`${fieldsPath}.${index}`);+ const nextField: Record<string, string> = {+ ...currentField,+ type: value,+ };++ if (matchedField) {+ FIELD_SYNC_KEYS.forEach((key) => {+ if (key in matchedField) {+ nextField[key] = matchedField[key] ?? '';+ }+ });+ }++ form.setValue(`${fieldsPath}.${index}`, nextField, {+ shouldValidate: false,+ shouldDirty: true,+ shouldTouch: true,+ });+ },+ [builtinSection, fieldsPath, form, index],+ );+};diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-template-kind-change.ts b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-template-kind-change.tsnew file mode 100644index 0000000000..d5d0ced5b3--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-template-kind-change.ts@@ -0,0 +1,42 @@+import { ICompilationTemplateBuiltin } from '@/interfaces/database/compilation-template';+import { UseFormReturn } from 'react-hook-form';++import { FormSchemaType } from '../schema';+import { buildConfigFromBuiltin } from '../utils';++type FieldLike = {+ value: string;+ onChange: (value: string) => void;+};++type UseTemplateKindChangeOptions = {+ form: UseFormReturn<FormSchemaType>;+ index: number;+ builtins: ICompilationTemplateBuiltin[];+};++export const useTemplateKindChange = ({+ form,+ index,+ builtins,+}: UseTemplateKindChangeOptions) => {+ return (field: FieldLike, value: string) => {+ if (value && value !== field.value) {+ const builtinTemplate = builtins.find(+ (template) => template.kind === value,+ );+ if (builtinTemplate) {+ form.setValue(+ `templates.${index}.config`,+ buildConfigFromBuiltin(+ builtinTemplate,+ value,+ form.getValues(`templates.${index}.llm_id`),+ ),+ { shouldValidate: false },+ );+ }+ }+ field.onChange(value);+ };+};diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/index.tsx b/web/src/pages/user-setting/compilation-templates/edit-template/index.tsxnew file mode 100644index 0000000000..aadd5fac41--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/index.tsx@@ -0,0 +1,183 @@+import BackButton from '@/components/back-button';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Button } from '@/components/ui/button';+import { Form } from '@/components/ui/form';+import { Input } from '@/components/ui/input';+import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';+import { Textarea } from '@/components/ui/textarea';+import { Routes } from '@/routes';+import { Plus } from 'lucide-react';+import { useMemo } from 'react';+import { useFieldArray, useWatch } from 'react-hook-form';+import { useTranslation } from 'react-i18next';+import JsonView from 'react18-json-view';++import { CompilationTemplateKind } from '@/constants/compilation';+import { TemplateCard } from './components/template-card';+import { useEditCompilationTemplateGroup } from './hooks/use-edit-compilation-template-group';+import { DefaultTemplateValues } from './utils';++export default function EditCompilationTemplate() {+ const { t } = useTranslation();+ const {+ isCreate,+ form,+ watchedValues,+ kindOptions,+ builtins,+ onSubmit,+ isLoading,+ navigateToCompilationTemplates,+ } = useEditCompilationTemplateGroup();++ const { fields, append, remove } = useFieldArray({+ control: form.control,+ name: 'templates',+ });++ const watchedTemplates = useWatch({+ control: form.control,+ name: 'templates',+ });++ const isAddTemplateDisabled = watchedTemplates?.some(+ (template) => template.kind === CompilationTemplateKind.Artifacts,+ );++ const hasNonArtifactsTemplate = watchedTemplates?.some(+ (template) =>+ template.kind && template.kind !== CompilationTemplateKind.Artifacts,+ );++ const availableKindOptions = useMemo(+ () =>+ hasNonArtifactsTemplate+ ? kindOptions.filter(+ (option) => option.value !== CompilationTemplateKind.Artifacts,+ )+ : kindOptions,+ [hasNonArtifactsTemplate, kindOptions],+ );++ const handleAddTemplate = () => {+ const firstTemplateLlmId = form.getValues('templates.0.llm_id');+ append({+ ...DefaultTemplateValues,+ llm_id: firstTemplateLlmId || '',+ });+ };++ return (+ <section className="h-full flex flex-col">+ <header className="shrink-0 px-5 py-4 border-b border-border-button flex flex-col items-start gap-2">+ <BackButton+ to={`${Routes.UserSetting}${Routes.CompilationTemplates}`}+ />+ <h2 className="text-xl font-medium text-text-primary">+ {isCreate+ ? t('setting.addTemplateGroup')+ : t('setting.editTemplateGroup')}+ </h2>+ </header>++ <div className="flex-1 min-h-0 flex">+ <Form {...form}>+ <form+ onSubmit={form.handleSubmit(onSubmit)}+ className="flex-1 min-w-0 flex flex-col min-h-0"+ >+ <div className="flex-1 min-h-0 overflow-y-auto p-5">+ <div className="max-w-2xl space-y-6 mx-auto">+ <RAGFlowFormItem+ name="name"+ label={t('setting.groupName')}+ required+ >+ <Input placeholder={t('common.namePlaceholder')} />+ </RAGFlowFormItem>++ <RAGFlowFormItem+ name="description"+ label={t('setting.groupDescription')}+ >+ <Textarea+ placeholder={t('common.descriptionPlaceholder')}+ rows={3}+ />+ </RAGFlowFormItem>++ <section className="space-y-4">+ {fields.map((field, index) => (+ <TemplateCard+ key={field.id}+ index={index}+ form={form}+ kindOptions={availableKindOptions}+ builtins={builtins}+ onRemove={remove}+ canRemove={fields.length > 1}+ />+ ))}+ </section>++ <Button+ type="button"+ variant="outline"+ onClick={handleAddTemplate}+ disabled={isAddTemplateDisabled}+ >+ <Plus className="size-4 mr-2" />+ {t('setting.addTemplate')}+ </Button>+ </div>+ </div>++ <div className="shrink-0 px-5 py-4 border-t border-border-button flex items-center justify-end gap-3">+ <Button+ type="button"+ variant="outline"+ onClick={navigateToCompilationTemplates}+ disabled={isLoading}+ >+ {t('common.cancel')}+ </Button>+ <Button type="submit" loading={isLoading} disabled={isLoading}>+ {t('common.confirm')}+ </Button>+ </div>+ </form>+ </Form>++ <aside className="flex-1 min-w-0 border-l border-border-button p-5 hidden lg:flex flex-col">+ <Tabs defaultValue="json" className="h-full flex flex-col min-h-0">+ <TabsList className="mb-3 self-start shrink-0">+ <TabsTrigger value="json">JSON</TabsTrigger>+ <TabsTrigger value="processFlow">+ {t('setting.processFlow')}+ </TabsTrigger>+ </TabsList>+ <TabsContent+ value="json"+ className="mt-0 flex-1 min-h-0 overflow-y-auto"+ >+ <JsonView+ src={watchedValues}+ displaySize+ collapseStringsAfterLength={100000000000}+ className="w-full h-full break-words p-2 bg-muted rounded-md"+ />+ </TabsContent>+ <TabsContent+ value="processFlow"+ className="mt-0 flex-1 min-h-0 overflow-y-auto"+ >+ <div className="w-full h-full flex items-center justify-center text-sm text-text-secondary">+ {t('setting.processFlowComingSoon')}+ </div>+ </TabsContent>+ </Tabs>+ </aside>+ </div>+ </section>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/schema.ts b/web/src/pages/user-setting/compilation-templates/edit-template/schema.tsnew file mode 100644index 0000000000..d17f80705a--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/schema.ts@@ -0,0 +1,41 @@+import { z } from 'zod';++export const buildSectionSchema = (t: (key: string) => string) =>+ z.object({+ description: z.string().optional(),+ fields: z+ .array(z.record(z.string().min(1, t('setting.fieldDescriptionRequired'))))+ .min(1),+ });++export const buildRaptorConfigSchema = (t: (key: string) => string) =>+ z.object({+ prompt: z.string().optional(),+ max_token: z.number().min(1, t('setting.maxTokenRequired')),+ threshold: z.number().min(0).max(1),+ rechunk: z.boolean().optional(),+ });++export const buildTemplateSchema = (t: (key: string) => string) =>+ z.object({+ name: z.string().optional(),+ description: z.string().optional(),+ llm_id: z.string().min(1, t('setting.llmForExtractionRequired')),+ kind: z.string().min(1, t('setting.templateKindRequired')),+ config: z.record(+ z.union([buildRaptorConfigSchema(t), buildSectionSchema(t), z.string()]),+ ),+ });++export const buildFormSchema = (t: (key: string) => string) =>+ z.object({+ name: z.string().min(1, t('setting.groupNameRequired')),+ description: z.string().optional(),+ avatar: z.string().optional(),+ templates: z.array(buildTemplateSchema(t)).min(1),+ });++export type TemplateSchemaType = z.infer<+ ReturnType<typeof buildTemplateSchema>+>;+export type FormSchemaType = z.infer<ReturnType<typeof buildFormSchema>>;diff --git a/web/src/pages/user-setting/compilation-templates/edit-template/utils.ts b/web/src/pages/user-setting/compilation-templates/edit-template/utils.tsnew file mode 100644index 0000000000..d896a5d48d--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/edit-template/utils.ts@@ -0,0 +1,259 @@+import { isEqual } from 'lodash';++import {+ ICompilationTemplate,+ ICompilationTemplateBuiltin,+ ICompilationTemplateGroup,+ ICompilationTemplateRaptorConfig,+ ICompilationTemplateSection,+} from '@/interfaces/database/compilation-template';+import { ICompilationTemplateConfigRequest } from '@/interfaces/request/compilation-template';++import { CompilationTemplateKind } from '@/constants/compilation';++import { FormSchemaType, TemplateSchemaType } from './schema';++export const DefaultFieldKeys = ['type', 'description', 'rule'];++export const FieldKeyOrders = [+ DefaultFieldKeys,+ ['statement', 'subject'],+ ['definition_excerpt', 'term'],+];++export const getFieldKeyOrder = (keys: string[]): string[] => {+ const sortedKeys = [...keys].sort();+ return (+ FieldKeyOrders.find((order) => isEqual([...order].sort(), sortedKeys)) ??+ keys+ );+};++export const DefaultTemplateValues: TemplateSchemaType = {+ name: '',+ description: '',+ llm_id: '',+ kind: '',+ config: {+ kind: '',+ llm_id: '',+ global_rules: '',+ example: '',+ instruction: '',+ page_example: '',+ },+};++export const DefaultValues: FormSchemaType = {+ name: '',+ description: '',+ avatar: '',+ templates: [DefaultTemplateValues],+};++export const isConfigMetaKey = (key: string) =>+ [+ 'kind',+ 'llm_id',+ 'global_rules',+ 'example',+ 'instruction',+ 'page_example',+ ].includes(key);++export const createEmptyField = (keys: string[]) =>+ Object.fromEntries(keys.map((key) => [key, '']));++export const normalizeSection = (+ section?: ICompilationTemplateSection,+): ICompilationTemplateSection => {+ const fields = section?.fields ?? [];+ return {+ description: section?.description ?? '',+ fields:+ fields.length > 0+ ? fields.map((field) =>+ Object.fromEntries(+ Object.entries(field).map(([key, value]) => [key, value ?? '']),+ ),+ )+ : [createEmptyField(DefaultFieldKeys)],+ };+};++export const buildConfigFromBuiltin = (+ builtinTemplate: ICompilationTemplateBuiltin,+ kind: string,+ llmId: string,+): TemplateSchemaType['config'] => {+ const sections: TemplateSchemaType['config'] = {+ kind,+ llm_id: llmId,+ global_rules:+ typeof builtinTemplate.config?.global_rules === 'string'+ ? builtinTemplate.config.global_rules+ : '',+ example:+ typeof builtinTemplate.config?.example === 'string'+ ? builtinTemplate.config.example+ : '',+ };++ if (kind === CompilationTemplateKind.Tree) {+ const builtinRaptor: ICompilationTemplateRaptorConfig =+ builtinTemplate.config?.raptor ?? {};+ return {+ ...sections,+ raptor: {+ prompt: builtinRaptor.prompt ?? '',+ max_token: builtinRaptor.max_token ?? 512,+ threshold: builtinRaptor.threshold ?? 0.1,+ rechunk: builtinRaptor.rechunk ?? false,+ },+ };+ }++ Object.entries(builtinTemplate.config ?? {}).forEach(([key, value]) => {+ if (isConfigMetaKey(key)) return;+ sections[key] = normalizeSection(+ value as ICompilationTemplateSection,+ ) as TemplateSchemaType['config'][string];+ });++ return sections;+};++export const transformDetailToForm = (+ detail: ICompilationTemplate,+): TemplateSchemaType => {+ const config = detail.config ?? {};+ const base: TemplateSchemaType['config'] = {+ kind: config.kind ?? '',+ llm_id: config.llm_id ?? '',+ global_rules: config.global_rules ?? '',+ example: typeof config.example === 'string' ? config.example : '',+ };++ if (detail.kind === CompilationTemplateKind.Tree) {+ const raptor: ICompilationTemplateRaptorConfig = config.raptor ?? {};+ return {+ name: detail.name ?? '',+ description: detail.description ?? '',+ llm_id: config.llm_id ?? '',+ kind: detail.kind ?? '',+ config: {+ ...base,+ raptor: {+ prompt: raptor.prompt ?? '',+ max_token: raptor.max_token ?? 512,+ threshold: raptor.threshold ?? 0.1,+ rechunk: raptor.rechunk ?? false,+ },+ },+ };+ }++ Object.entries(config).forEach(([key, value]) => {+ if (isConfigMetaKey(key)) return;+ base[key] = normalizeSection(+ value as ICompilationTemplateSection,+ ) as TemplateSchemaType['config'][string];+ });++ return {+ name: detail.name ?? '',+ description: detail.description ?? '',+ llm_id: config.llm_id ?? '',+ kind: detail.kind ?? '',+ config: base,+ };+};++export const transformGroupDetailToForm = (+ detail: ICompilationTemplateGroup,+): FormSchemaType => {+ const templates = (detail.templates ?? []).map((template) =>+ transformDetailToForm(template),+ );++ return {+ name: detail.name ?? '',+ description: detail.description ?? '',+ avatar: detail.avatar ?? '',+ templates: templates.length > 0 ? templates : [DefaultTemplateValues],+ };+};++export const transformTemplateToPayload = (template: TemplateSchemaType) => {+ const config: ICompilationTemplateConfigRequest = {+ kind: template.kind,+ llm_id: template.llm_id,+ };++ Object.entries(template.config).forEach(([key, value]) => {+ if (key === 'kind' || key === 'llm_id') return;+ if (key === 'instruction' || key === 'page_example') return;+ if (isConfigMetaKey(key)) {+ if (typeof value === 'string') config[key] = value;+ } else {+ config[key] = value as ICompilationTemplateConfigRequest[string];+ }+ });++ if (template.kind === CompilationTemplateKind.Artifacts) {+ const instruction = String(template.config.instruction ?? '').trim();+ const pageExample = String(template.config.page_example ?? '').trim();+ config.example = [instruction, pageExample].filter(Boolean).join('\n\n');+ }++ return {+ name: template.name,+ description: template.description,+ kind: template.kind,+ config,+ };+};++export const transformFormToPayload = (values: FormSchemaType) => {+ return {+ name: values.name,+ description: values.description,+ avatar: values.avatar || undefined,+ templates: values.templates.map((template) =>+ transformTemplateToPayload(template),+ ),+ };+};++export const SectionTitleKeyMap: Record<string, string> = {+ entity: 'setting.entitySpecification',+ relation: 'setting.relationSpecification',+ concept: 'setting.conceptSpecification',+ claim: 'setting.claimSpecification',+};++export const SectionPriority = ['entity', 'relation'];++export const sortSectionNames = (names: string[]): string[] => {+ const priority = SectionPriority.filter((name) => names.includes(name));+ const rest = names.filter((name) => !SectionPriority.includes(name));+ return [...priority, ...rest];+};++export const FieldLabelKeyMap: Record<string, string> = {+ type: 'setting.fieldType',+ description: 'setting.fieldDescription',+ rule: 'setting.fieldRule',+};++export const getTypeOptionsFromBuiltinSection = (+ builtinSection?: ICompilationTemplateSection,+) => {+ const typeSet = new Set<string>();+ builtinSection?.fields?.forEach((field) => {+ if (field.type) typeSet.add(field.type);+ });+ return Array.from(typeSet)+ .sort()+ .map((value) => ({ label: value, value }));+};diff --git a/web/src/pages/user-setting/compilation-templates/index.tsx b/web/src/pages/user-setting/compilation-templates/index.tsxnew file mode 100644index 0000000000..c91ae141da--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/index.tsx@@ -0,0 +1,110 @@+import { CardContainer } from '@/components/card-container';+import { Button } from '@/components/ui/button';+import { SearchInput } from '@/components/ui/input';+import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';+import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';+import {+ useDeleteCompilationTemplateGroup,+ useFetchCompilationTemplateGroupsByPage,+} from '@/hooks/use-compilation-template-group-request';+import { pick } from 'lodash';+import { Plus } from 'lucide-react';+import { useCallback } from 'react';+import { useTranslation } from 'react-i18next';++import { ProfileSettingWrapperCard } from '../components/user-setting-header';+import { TemplateCard } from './template-card';++export default function CompilationTemplates() {+ const { t } = useTranslation();+ const {+ groups,+ total,+ searchString,+ handleInputChange,+ pagination,+ setPagination,+ } = useFetchCompilationTemplateGroupsByPage();++ const { deleteGroup } = useDeleteCompilationTemplateGroup();+ const { navigateToCompilationTemplate } = useNavigatePage();++ const handlePageChange = useCallback(+ (page: number, pageSize?: number) => {+ setPagination({ page, pageSize });+ },+ [setPagination],+ );++ const handleAdd = useCallback(() => {+ navigateToCompilationTemplate('create')();+ }, [navigateToCompilationTemplate]);++ const handleDelete = useCallback(+ async (id: string) => {+ await deleteGroup(id);+ },+ [deleteGroup],+ );++ return (+ <ProfileSettingWrapperCard+ header={+ <header className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">+ <div>+ <h2 className="text-2xl font-medium text-text-primary">+ {t('setting.compilationTemplates')}+ </h2>++ <p className="mt-1 text-sm text-text-secondary">+ {t('setting.compilationTemplatesDescription')}+ </p>+ </div>++ <div className="flex items-center gap-4">+ <SearchInput+ className="w-52"+ value={searchString}+ onChange={handleInputChange}+ placeholder={t('common.search')}+ />++ <Button onClick={handleAdd}>+ <Plus />+ {t('setting.addTemplateGroup')}+ </Button>+ </div>+ </header>+ }+ >+ <div className="h-full flex flex-col">+ <div className="flex-1 min-h-0 overflow-x-hidden overflow-y-auto p-5">+ {groups.length > 0 ? (+ <CardContainer>+ {groups.map((item) => (+ <TemplateCard+ key={item.id}+ data={item}+ onClick={navigateToCompilationTemplate(item.id)}+ onDelete={handleDelete}+ />+ ))}+ </CardContainer>+ ) : (+ <div className="flex items-center justify-center h-full text-text-secondary text-sm">+ {t('setting.noTemplates')}+ </div>+ )}+ </div>++ <div className="p-5 pt-0">+ <RAGFlowPagination+ {...pick(pagination, 'current', 'pageSize')}+ total={total}+ onChange={handlePageChange}+ />+ </div>+ </div>+ </ProfileSettingWrapperCard>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/template-card.tsx b/web/src/pages/user-setting/compilation-templates/template-card.tsxnew file mode 100644index 0000000000..3e0cf74a20--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/template-card.tsx@@ -0,0 +1,75 @@+import { MoreButton } from '@/components/more-button';+import { RAGFlowAvatar } from '@/components/ragflow-avatar';+import { Badge } from '@/components/ui/badge';+import { Card, CardContent } from '@/components/ui/card';+import { CompilationTemplateScope } from '@/constants/compilation';+import { ICompilationTemplateGroup } from '@/interfaces/database/compilation-template';+import { Database, FileText, LucideIcon } from 'lucide-react';+import { useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { TemplateDropdown } from './template-dropdown';++type TemplateCardProps = {+ data: ICompilationTemplateGroup;+ onClick?: () => void;+ onDelete: (id: string) => void;+};++const ScopeIconMap: Record<string, LucideIcon> = {+ [CompilationTemplateScope.File]: FileText,+ [CompilationTemplateScope.Dataset]: Database,+};++function ScopeIcon({ scope }: { scope?: string }) {+ const Icon = scope ? ScopeIconMap[scope] : null;++ return Icon ? <Icon className="size-4 text-text-secondary shrink-0" /> : null;+}++export function TemplateCard({ data, onClick, onDelete }: TemplateCardProps) {+ const { t } = useTranslation();++ const kinds = useMemo(+ () => Array.from(new Set((data.templates ?? []).map((item) => item.kind))),+ [data.templates],+ );++ return (+ <Card className="group cursor-pointer h-full" onClick={onClick}>+ <CardContent className="p-4 flex gap-3">+ <RAGFlowAvatar+ avatar={data.avatar}+ name={data.name}+ className="w-8 h-8 shrink-0"+ />++ <div className="flex-1 min-w-0 flex flex-col gap-1">+ <section className="flex items-center justify-between gap-2">+ <div className="flex items-center gap-2 min-w-0 flex-1">+ <h3 className="text-base font-normal truncate text-text-primary">+ {data.name}+ </h3>+ <ScopeIcon scope={data.scope} />+ </div>++ <TemplateDropdown data={data} onDelete={onDelete}>+ <MoreButton />+ </TemplateDropdown>+ </section>++ <p className="text-sm text-text-secondary line-clamp-1">+ {data.description}+ </p>++ <div className="flex flex-wrap gap-2 mt-2">+ {kinds.map((kind) => (+ <Badge key={kind} variant="secondary">+ {t(`knowledgeCompilation.kind.${kind}`, kind)}+ </Badge>+ ))}+ </div>+ </div>+ </CardContent>+ </Card>+ );+}diff --git a/web/src/pages/user-setting/compilation-templates/template-dropdown.tsx b/web/src/pages/user-setting/compilation-templates/template-dropdown.tsxnew file mode 100644index 0000000000..99fbb150d7--- /dev/null+++ b/web/src/pages/user-setting/compilation-templates/template-dropdown.tsx@@ -0,0 +1,58 @@+import {+ ConfirmDeleteDialog,+ ConfirmDeleteDialogNode,+} from '@/components/confirm-delete-dialog';+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from '@/components/ui/dropdown-menu';+import { ICompilationTemplateGroup } from '@/interfaces/database/compilation-template';+import { Trash2 } from 'lucide-react';+import { PropsWithChildren, useCallback } from 'react';+import { useTranslation } from 'react-i18next';++type TemplateDropdownProps = PropsWithChildren<{+ data: ICompilationTemplateGroup;+ onDelete: (id: string) => void;+}>;++export function TemplateDropdown({+ children,+ data,+ onDelete,+}: TemplateDropdownProps) {+ const { t } = useTranslation();++ const handleDelete = useCallback(() => {+ onDelete(data.id);+ }, [data.id, onDelete]);++ return (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <div onClick={(e) => e.stopPropagation()}>{children}</div>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <ConfirmDeleteDialog+ title={t('setting.deleteTemplateGroupModalTitle')}+ content={{+ title: t('setting.deleteTemplateGroupModalContent'),+ node: <ConfirmDeleteDialogNode name={data.name} />,+ }}+ onOk={handleDelete}+ >+ <DropdownMenuItem+ className="text-state-error"+ onSelect={(e) => e.preventDefault()}+ onClick={(e) => e.stopPropagation()}+ >+ {t('common.delete')}+ <Trash2 className="size-4" />+ </DropdownMenuItem>+ </ConfirmDeleteDialog>+ </DropdownMenuContent>+ </DropdownMenu>+ );+}diff --git a/web/src/pages/user-setting/index.tsx b/web/src/pages/user-setting/index.tsxindex beef40eb4f..9230018a7e 100644--- a/web/src/pages/user-setting/index.tsx+++ b/web/src/pages/user-setting/index.tsx@@ -3,7 +3,7 @@ import { SideBar } from './sidebar';import { cn } from '@/lib/utils';-const UserSetting = () => {+function UserSetting() {return (<section className="pt-8 size-full grid grid-cols-[4rem_minmax(0,1fr)] md:grid-cols-[303px_minmax(0,1fr)] grid-rows-1 min-w-0"><SideBar />@@ -17,6 +17,6 @@ const UserSetting = () => {</div></section>);-};+}export default UserSetting;diff --git a/web/src/pages/user-setting/sidebar/index.tsx b/web/src/pages/user-setting/sidebar/index.tsxindex 1bd02df06f..145a212565 100644--- a/web/src/pages/user-setting/sidebar/index.tsx+++ b/web/src/pages/user-setting/sidebar/index.tsx@@ -12,6 +12,7 @@ import { cn } from '@/lib/utils';import { Routes } from '@/routes';import { TFunction } from 'i18next';import {+ Columns3Cog,LucideBox,LucideLogOut,LucideMessagesSquare,@@ -46,6 +47,11 @@ const menuItems = (t: TFunction) => [label: 'MCP',key: Routes.Mcp,},+ {+ icon: <Columns3Cog className="size-[1em]" />,+ label: t('setting.compilationTemplates'),+ key: Routes.CompilationTemplates,+ },{icon: <LucideUsers className="size-[1em]" />,label: t('setting.team'),diff --git a/web/src/routes.tsx b/web/src/routes.tsxindex 974d9ddd8f..cddf1bcf4b 100644--- a/web/src/routes.tsx+++ b/web/src/routes.tsx@@ -43,6 +43,9 @@ export enum Routes {Plan = '/plan',Model = '/model',Prompt = '/prompt',+ CompilationTemplates = '/compilation-templates',+ CompilationTemplate = `${CompilationTemplates}/:id`,+ CompilationTemplatesCreateNext = '/compilation-templates/create-next',DataSource = '/data-source',DataSourceDetailPage = '/data-source-detail-page',ChatChannel = '/chat-channel',@@ -60,6 +63,7 @@ export enum Routes {Result = '/result',ResultView = `${Chunk}${Result}`,KnowledgeGraph = '/knowledge-graph',+ Compilation = '/compilation',AgentLogPage = '/agent-log-page',AgentShare = '/agent/share',ChatShare = `${Chats}/share`,@@ -299,6 +303,11 @@ const routeConfigOptions = [path: `${Routes.UserSetting}${Routes.ChatChannel}`,Component: () => import('@/pages/user-setting/chat-channel'),},+ {+ path: `${Routes.UserSetting}${Routes.CompilationTemplates}`,+ Component: () =>+ import('@/pages/user-setting/compilation-templates'),+ },],},{@@ -309,10 +318,32 @@ const routeConfigOptions = [},],},+ {+ path: Routes.CompilationTemplate,+ layout: false,+ Component: () =>+ import('@/pages/user-setting/compilation-templates/edit-template'),+ },+ {+ path: Routes.CompilationTemplatesCreateNext,+ layout: false,+ Component: () =>+ import('@/pages/user-setting/compilation-templates/create-next'),+ },+ {+ path: `${Routes.CompilationTemplatesCreateNext}/:id`,+ layout: false,+ Component: () =>+ import('@/pages/user-setting/compilation-templates/create-next'),+ },{path: `${Routes.SearchShare}`,Component: () => import('@/pages/next-search/share'),},+ {+ path: `${Routes.DatasetBase}${Routes.Compilation}/:id`,+ Component: () => import('@/pages/dataset/compilation'),+ },{path: Routes.Agent,children: [diff --git a/web/src/services/compilation-template-group-service.ts b/web/src/services/compilation-template-group-service.tsnew file mode 100644index 0000000000..8a46cf1d52--- /dev/null+++ b/web/src/services/compilation-template-group-service.ts@@ -0,0 +1,35 @@+import {+ ICreateCompilationTemplateGroupRequestBody,+ IUpdateCompilationTemplateGroupRequestBody,+} from '@/interfaces/request/compilation-template';+import api from '@/utils/api';+import request from '@/utils/next-request';+import { registerNextServer } from '@/utils/register-server';++const methods = {+ listGroups: {+ url: api.compilationTemplateGroups,+ method: 'get',+ },+} as const;++const compilationTemplateGroupService =+ registerNextServer<keyof typeof methods>(methods);++export const createCompilationTemplateGroup = (+ data: ICreateCompilationTemplateGroupRequestBody,+) => request.post(api.compilationTemplateGroups, data);++export const updateCompilationTemplateGroup = (+ id: string,+ data: IUpdateCompilationTemplateGroupRequestBody,+) => request.put(api.compilationTemplateGroup(id), data);++export const getCompilationTemplateGroup = (id: string) =>+ request.get(api.compilationTemplateGroup(id));++export const deleteCompilationTemplateGroup = (id: string) =>+ request.delete(api.compilationTemplateGroup(id));++export { compilationTemplateGroupService };+export default compilationTemplateGroupService;diff --git a/web/src/services/compilation-template-service.ts b/web/src/services/compilation-template-service.tsnew file mode 100644index 0000000000..3d9004698f--- /dev/null+++ b/web/src/services/compilation-template-service.ts@@ -0,0 +1,39 @@+import {+ ICreateCompilationTemplateRequestBody,+ IUpdateCompilationTemplateRequestBody,+} from '@/interfaces/request/compilation-template';+import api from '@/utils/api';+import request from '@/utils/next-request';+import { registerNextServer } from '@/utils/register-server';++const methods = {+ listTemplates: {+ url: api.compilationTemplates,+ method: 'get',+ },+} as const;++const compilationTemplateService =+ registerNextServer<keyof typeof methods>(methods);++export const deleteCompilationTemplate = (id: string) =>+ request.delete(api.compilationTemplate(id));++export const getCompilationTemplate = (id: string) =>+ request.get(api.compilationTemplate(id));++export const createCompilationTemplate = (+ data: ICreateCompilationTemplateRequestBody,+) => request.post(api.compilationTemplates, data);++export const updateCompilationTemplate = (+ id: string,+ data: IUpdateCompilationTemplateRequestBody,+) => request.put(api.compilationTemplate(id), data);++export const listBuiltinCompilationTemplates = () =>+ request.get(`${api.compilationTemplates}/builtins`);++export const listWikiPresets = () => request.get(api.wikiPresets);++export default compilationTemplateService;diff --git a/web/src/services/dataset-skill-service.ts b/web/src/services/dataset-skill-service.tsnew file mode 100644index 0000000000..963b029822--- /dev/null+++ b/web/src/services/dataset-skill-service.ts@@ -0,0 +1,11 @@+import api from '@/utils/api';+import request from '@/utils/next-request';++const datasetSkillService = {+ getTree: (params: { datasetId: string }) =>+ request.get(api.getDatasetSkillTree(params.datasetId)),+ getPage: (params: { datasetId: string; skillKwd: string }) =>+ request.get(api.getDatasetSkillPage(params.datasetId, params.skillKwd)),+};++export default datasetSkillService;diff --git a/web/src/services/document-structure-service.ts b/web/src/services/document-structure-service.tsnew file mode 100644index 0000000000..bd4b2fafe4--- /dev/null+++ b/web/src/services/document-structure-service.ts@@ -0,0 +1,23 @@+import api from '@/utils/api';+import request from '@/utils/next-request';++export const getDocumentStructureGraph = (+ datasetId: string,+ documentId: string,+) => request.get(api.documentStructureGraph(datasetId, documentId));++export const deleteDocumentStructureGraph = (+ datasetId: string,+ documentId: string,+ templateId: string,+) =>+ request.delete(api.documentStructureGraph(datasetId, documentId), {+ data: { template_id: templateId },+ });++const documentStructureService = {+ getDocumentStructureGraph,+ deleteDocumentStructureGraph,+};++export default documentStructureService;diff --git a/web/src/services/knowledge-service.ts b/web/src/services/knowledge-service.tsindex 7c72b1d2c3..bebfffeb31 100644--- a/web/src/services/knowledge-service.ts+++ b/web/src/services/knowledge-service.ts@@ -1,10 +1,14 @@import { IRenameTag } from '@/interfaces/database/dataset';import {+ IFetchArtifactListRequestParams,+ IFetchArtifactTopicListRequestParams,IFetchDocumentListRequestBody,IFetchKnowledgeListRequestParams,+ IUpdateArtifactPageRequestBody,} from '@/interfaces/request/knowledge';import { ProcessingType } from '@/pages/dataset/dataset-overview/dataset-common';import api from '@/utils/api';+import nextRequest from '@/utils/next-request';import registerServer from '@/utils/register-server';import request from '@/utils/request';@@ -144,6 +148,7 @@ const chunkService = {page_size: params.page_size || params.size,keywords: params.keywords,available: getAvailableParam(params.available_int),+ chunk_ids: params.chunk_ids,},});@@ -385,6 +390,53 @@ export const getPipelineDetail = (datasetId: string, logId: string) =>export const getKnowledgeBasicInfo = (datasetId: string) =>request.get(api.getKnowledgeBasicInfo(datasetId));+export const listArtifacts = (+ datasetId: string,+ params?: IFetchArtifactListRequestParams,+) => request.get(api.artifactsList(datasetId), { params });++export const listArtifactTopics = (+ datasetId: string,+ params?: IFetchArtifactTopicListRequestParams,+) => request.get(api.artifactsTopicList(datasetId), { params });++export const getArtifactPage = (+ datasetId: string,+ pageType: string,+ slug: string,+) => request.get(api.getArtifactPage(datasetId, pageType, slug));++export const getArtifactGraph = (+ datasetId: string,+ params?: { node?: string },+) => request.get(api.getArtifactGraph(datasetId), { params });++export const updateArtifactPage = (+ datasetId: string,+ pageType: string,+ slug: string,+ data: IUpdateArtifactPageRequestBody,+) => request.put(api.getArtifactPage(datasetId, pageType, slug), { data });++export const listWikiCommits = (+ datasetId: string,+ pageType: string,+ slug: string,+ params?: { page?: number; page_size?: number },+) =>+ request.get(api.listWikiCommits(datasetId), {+ params: {+ ...params,+ slug: slug.startsWith(`${pageType}/`) ? slug : `${pageType}/${slug}`,+ },+ });++export const getWikiCommit = (datasetId: string, commitId: string) =>+ request.get(api.getWikiCommit(datasetId, commitId));++export const clearWiki = (datasetId: string) =>+ nextRequest.delete(api.clearWiki(datasetId), {});+export const checkEmbedding = (datasetId: string, data: Record<string, any>) =>request.post(api.checkEmbedding(datasetId), { data });diff --git a/web/src/utils/api.ts b/web/src/utils/api.tsindex 86d78097cc..f98d293f7c 100644--- a/web/src/utils/api.ts+++ b/web/src/utils/api.ts@@ -153,6 +153,27 @@ export default {getMeta: `${restAPIv1}/datasets/metadata/flattened`,getKnowledgeBasicInfo: (datasetId: string) =>`${restAPIv1}/datasets/${datasetId}/ingestions/summary`,+ artifactsList: (datasetId: string) =>+ `${restAPIv1}/datasets/${datasetId}/artifacts`,+ artifactsTopicList: (datasetId: string) =>+ `${restAPIv1}/datasets/${datasetId}/artifacts_topics`,+ getArtifactPage: (datasetId: string, pageType: string, slug: string) =>+ `${restAPIv1}/datasets/${datasetId}/artifacts/${pageType}/${slug}`,+ listWikiCommits: (datasetId: string) =>+ `${restAPIv1}/datasets/${datasetId}/commits`,+ getWikiCommit: (datasetId: string, commitId: string) =>+ `${restAPIv1}/datasets/${datasetId}/commits/${commitId}`,+ getArtifactGraph: (datasetId: string) =>+ `${restAPIv1}/datasets/${datasetId}/artifacts/graph`,+ clearWiki: (datasetId: string) =>+ `${restAPIv1}/datasets/${datasetId}/artifacts`,+ getDatasetSkillTree: (datasetId: string) =>+ `${restAPIv1}/datasets/${datasetId}/skills`,+ getDatasetSkillPage: (datasetId: string, skillKwd: string) =>+ `${restAPIv1}/datasets/${datasetId}/skills/${skillKwd+ .split('/')+ .map((s) => encodeURIComponent(s))+ .join('/')}`,// data pipeline logfetchDataPipelineLog: (datasetId: string) =>`${restAPIv1}/datasets/${datasetId}/ingestions`,@@ -189,6 +210,8 @@ export default {`${restAPIv1}/datasets/${datasetId}/documents/${documentId}/chunks`,chunkDetail: (datasetId: string, documentId: string, chunkId: string) =>`${restAPIv1}/datasets/${datasetId}/documents/${documentId}/chunks/${chunkId}`,+ documentStructureGraph: (datasetId: string, documentId: string) =>+ `${restAPIv1}/datasets/${datasetId}/documents/${documentId}/structure/graph`,retrievalTest: `${restAPIv1}/datasets/search`,// document@@ -329,6 +352,15 @@ export default {// explore+ // compilation templates+ compilationTemplates: `${restAPIv1}/compilation_templates`,+ compilationTemplate: (id: string) =>+ `${restAPIv1}/compilation_templates/${id}`,+ compilationTemplateGroups: `${restAPIv1}/compilation_template_groups`,+ compilationTemplateGroup: (id: string) =>+ `${restAPIv1}/compilation_template_groups/${id}`,+ wikiPresets: `${restAPIv1}/compilation_templates/wiki_presets`,+// mcp serverlistMcpServer: `${restAPIv1}/mcp/servers`,getMcpServer: (id: string) => `${restAPIv1}/mcp/servers/${id}`,diff --git a/web/src/utils/file-util.ts b/web/src/utils/file-util.tsindex bf6284f382..852091c1f2 100644--- a/web/src/utils/file-util.ts+++ b/web/src/utils/file-util.ts@@ -140,6 +140,11 @@ export const downloadFileFromBlob = (blob: Blob, name?: string) => {window.URL.revokeObjectURL(url);};+export const downloadMarkdownFile = (content: string, filename: string) => {+ const blob = new Blob([content], { type: FileMimeType.Md });+ downloadFileFromBlob(blob, filename);+};+export const downloadDocument = async ({id,filename,diff --git a/web/vite.config.ts b/web/vite.config.tsindex e81a5db1d2..9c8ec557d9 100644--- a/web/vite.config.ts+++ b/web/vite.config.ts@@ -64,12 +64,12 @@ export default defineConfig(({ mode }) => {ws: true,},'/api': {- target: 'http://127.0.0.1:9380/',+ target: 'http://127.0.0.1:9386/',changeOrigin: true,ws: true,},'/v1': {- target: 'http://127.0.0.1:9380/',+ target: 'http://127.0.0.1:9386/',changeOrigin: true,ws: true,},