Skip to content

✨ Feature(aidp): refactor knowledge base list and creation pages - #4029

Open
cj2026-bit wants to merge 38 commits into
developfrom
feat-knowledge-base-pages-refactor
Open

cj2026-bit wants to merge 38 commits into
developfrom
feat-knowledge-base-pages-refactor

Conversation

@cj2026-bit

Copy link
Copy Markdown
Collaborator

Problem

  1. The AIDP knowledge base page used a two-column layout: the knowledge base list on the left and the selected base's files on the right. The overview had no card view, no column setting and no usage guide, so the list was hard to scan and file management was buried in the same screen.
  2. Creation happened in a modal that exposed only name, description, permission, captioning and chunk tokens. The AIDP create contract accepts a chunking mode, retrieval parameters, an embedding model choice, a full knowledge graph configuration and a safety guard, none of which the UI could submit.
  3. The document download and delete entries disappeared from the AIDP file list during the v2.6.1 merge: the backend endpoints, the frontend service methods and both locales were intact, but nothing called them any more.

Fix

Overview (AIDP only)

  • Split the page into an overview and a full-page file view that replace each other inside the existing AIDP component. Entering a knowledge base clears the previous base documents and its upload watch; returning restores the search text, page, view mode and column setting.
  • Added a collapsible guide with the three documented steps, and an overview that defaults to cards and can switch to a table over the same server-paginated result set.
  • The table exposes a column visibility setting (name and actions always visible, restore defaults). Search stays the single existing name search; no column filters were added.
  • Display metadata is never fabricated: the personal/enterprise type comes from the AIDP is_private field, capacity only from a valid current_cap, the creator only from a real display name, and the backend now marks whether a document count is a confirmed statistic. Unknown values render as an em dash.

Creation page

  • New route /knowledges/create renders a dedicated two-step page. The first step groups basic information, permission and user groups, the safety guard, the knowledge graph, chunking, vector generation and retrieval; the second step optionally uploads files.
  • The next step only validates locally. The knowledge base is created once at the final submission and files are uploaded only after a successful create, so a failed upload never recreates it.
  • New fields are submitted end to end: chunk_mode (0 smart splitting / 1 legal clauses), a 256-4096 chunk token range, an overlap ratio converted to floor(tokens * percent / 100) integer tokens, similarity, knowledge base Top K, the embedding model, the graph model from the llm category, the multimodal model from the vlm category, the full graph configuration and the safety guard. Disabling a capability omits its hidden configuration instead of resubmitting it.
  • The backend validates the structured graph configuration, serializes it into the documented graph_config string, and rejects an overlap above half the chunk size.

Safety guard

  • sensitive_intercept_enalbe is submitted as integer 1/0 on create, forwarded explicitly when disabled on update (the metadata whitelist would otherwise drop the 0), and read back in the edit dialog. A response that omits the field is shown as unknown, never as a confirmed disabled state.

Restored file operations

  • The file table has an actions column again: download for read access and delete with confirmation for edit access, both hidden for read-only or unavailable knowledge bases.

Scope

  • The ES knowledge base path is untouched: no ES component, service, endpoint or locale entry was modified.

Verification

  • Backend: pytest test/ext_components/aidp/ — 597 passed.
  • Frontend: tsc --noEmit reports zero errors in the changed AIDP sources, types and locales (run against the same dependency versions as the main checkout).
  • Formal test assets: requirement, feature and 26 D1-D5 cases added; python test/tools/validate_test_assets.py --phase design --generate-excel passes.
  • Local end-to-end against the AIDP mock in full deployment mode:
    • Overview renders the guide, the card view, the table view with all eight columns, card counts and capacity placeholders; the file view opens, lists documents with the restored download/delete actions, and returning keeps the table view.
    • The creation page renders both steps with the documented defaults (1024 tokens, 12.5% overlap, smart splitting) and its validation blocks the next step while the name or the group selection is invalid.
    • Create API: the upstream payload carries chunk_mode, a serialized graph_config string whose no_think_mode is inverse to the thinking switch, llm_model_name, integer sensitive_intercept_enalbe, and keeps every legacy field and default.
    • Graph disabled: the payload omits graph_config and llm_model_name while still submitting the explicit 0 safety guard.
    • Update API: metadata_status: updated for the safety guard change.
    • Model queries return per category (llm, vlm, embedding).
  • Two browser-only defects were found and fixed during this verification: the new locale entries used single-brace placeholders, which i18next does not interpolate (cards rendered 文件 {count}); they now use {{count}}.

Not covered: the upstream safety guard contract is still under development on the AIDP side, so a real create/update/readback of that field can only be verified after it ships — the mock accepts the field but does not store it. Browser automation could not exercise the column settings popover, the search input and the upload step (the available in-app browser exposes no reliable locator or mouse API for Ant Design portaled widgets); those paths were reviewed in code and the surrounding flows were verified end to end.

cj2026-bit and others added 2 commits September 28, 2026 19:43
Split the AIDP knowledge base overview and its file management into two
views: a card or table overview with a collapsible three-step guide, an
independent name search, a column visibility setting and a full-page file
view that restores the previous search, page, view mode and column state.

Move creation to a dedicated two-step page under knowledges/create. The first
step owns the basic fields, permission and user groups, the safety guard, the
knowledge graph, the chunking mode, the models and the retrieval settings; the
next step validates locally only and the knowledge base is created once at the
final submission, before any file upload.

Restore the document download and delete entries that were dropped from the
AIDP file list during the v2.6.1 merge, keeping the documented read and edit
permission gates.

Backend: accept the new create and update fields, validate and serialize the
structured graph configuration, forward an explicit disabled safety guard, and
expose the optional display metadata (personal/enterprise flag, personal
capacity, creator name, document count reliability) on the list response.

Formal assets: requirement, feature and D1-D5 case documents for the change,
validated in the design phase.

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
Problem:
The new knowledge base cards rendered "文件 {count}" and "容量 {value}"
literally, and the same single-brace placeholders broke two validation
messages and the partial deletion summary. i18next only interpolates
{{name}} placeholders, so those strings were shown verbatim.

Fix:
Rewrote the five affected keys in both locales with {{...}} placeholders
and reformatted the locale files.

Verification:
- Browser check on /zh/knowledges: cards now render "文件 0" / "文件 2"
  and "容量 —" instead of the raw placeholders.
- Locale files pass prettier formatting.

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
Sonar reported 4.8% duplicated lines on the new code (threshold 3%). Two
blocks were responsible: the knowledge base and document lists carried a
line-for-line identical pagination block, and the creation page repeated the
same label-with-tooltip JSX six times.

- Extracted AidpPagination, now used by both lists, which also removes the
  duplicated "unreliable total" fallback rule.
- Replaced the repeated label blocks with a local fieldLabel() helper.
- Removed AidpCreateKbModal, which the dedicated creation page replaced.

Verification: tsc --noEmit reports no error in the changed files, and the
browser check on /zh/knowledges still renders the guide, card view, document
counts and the unknown-value placeholders.

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.57718% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ckend/ext_components/aidp/services/aidp_service.py 81.48% 11 Missing and 4 partials ⚠️
backend/ext_components/aidp/apps/aidp_mgmt_app.py 92.64% 2 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

cj2026-bit and others added 21 commits September 28, 2026 20:30
…aults

codecov/patch requires 90% coverage of the new lines. The new backend helpers
carried no unit tests, so patch coverage failed the gate while every build,
analysis and type check passed.

Added unit tests for the three units this change introduced:

- `_serialize_graph_config`: documented keys and defaults, unknown key
  filtering, domain and prompt-language rejection, the UTF-8 prompt byte limit
  and the candidate Top K / sub-graph hop ranges.
- `_validate_chunking`: the half-of-chunk-size bound, negative overlap, and the
  non-positive or non-integer inputs it deliberately skips.
- `_apply_create_defaults`: chunk mode and graph defaults, graph fields dropped
  when the graph is disabled and serialized when it is enabled, and an explicit
  0 safety guard that must survive the merge.

Verification: `pytest test/ext_components/aidp/` — 628 passed (31 new).

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
React 19 already declares onResize as a DOM event handler on
ThHTMLAttributes, so the custom onResize?: (width: number) => void
member of ResizableTitleProps no longer composed with the base
interface and broke compilation with TS2430. Omit the inherited member
before adding the column-resize callback.

Verification: tsc --noEmit reports no error in the AIDP sources; the
refactored overview and creation pages were driven end to end in the
browser against the AIDP mock (table/menu interactions, create flow
submitting chunk_mode, is_exist_graph and an explicit 0 safety guard,
then redirecting into the new base's file view).

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
The card's more-actions wrapper div carried onClick={stopPropagation} as
a third bubble guard on top of the trigger button's own handler and the
menu item handler. A visible non-interactive element with a click
handler and no keyboard listener fails Sonar rule S1082, which pushed
the new reliability rating to B.

The inner guards already stop propagation, so the wrapper's handler is
removed; the card keeps its own keyboard activation.

Verification: browser regression - the dropdown still opens with
edit/delete/import and clicking a card still opens its file view;
tsc --noEmit is clean for the AIDP sources.

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
…dcrumb key

The file view opened with a "back to knowledge base list" button. The user
asked for the breadcrumb form already used by the creation page, so the
header now reads 知识库 / 上传文件: the base segment navigates back to the
overview and clears the kb query parameter, and the knowledge base name and
lifecycle tags stay below it.

The creation breadcrumb referenced aidpKnowledge.createBreadcrumbKnowledge,
a key that exists in neither locale, so the page rendered the raw key; both
pages now share the new breadcrumbKnowledgeBase entry.

Verification: browser - the file view shows 知识库 / 上传文件 with the base
name below, clicking 知识库 returns to the overview, the creation page no
longer leaks the raw key, and tsc --noEmit is clean for the AIDP sources.

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
Sidebar menu items push bare paths such as /knowledges. The [locale]
route then receives 'knowledges' as the locale and the page crashes
inside the i18n initializer (I18nProviderWrapper reads
resourcesCustom[locale] with the garbage segment), leaving a blank
screen on every sidebar entry.

Added a Next.js middleware that redirects any page path without a zh/en
prefix to its localized counterpart based on the NEXT_LOCALE cookie;
API routes, Next.js internals and public assets bypass it.

Verification: browser - /knowledges now redirects to /zh/knowledges and
renders the overview; /zh/knowledges renders directly; the /locales
JSON files and the frontend API proxy bypass the redirect; curl
confirms 307 for bare paths and direct 200 for prefixed and asset
paths.

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
The locale redirect already ships in origin/develop's frontend/proxy.ts
(Next.js 16's middleware-to-proxy migration). Keeping my middleware.ts
makes the build fail with 'Both middleware file and proxy file are
detected' as soon as the branch merges with develop.

Verification: local NODE_ENV=production npm run build compiles with
proxy.ts present and middleware.ts removed.

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
Sidebar menu entries push bare paths (/knowledges and friends). The
production proxy redirects those, but the dev server does not run it,
so every sidebar entry crashed the i18n initializer and rendered a
blank page (resourcesCustom["knowledges"] is undefined).

Prefix each pushed path with the active i18n language; paths that
already carry a locale pass through unchanged.

Verification: browser - clicking 知识库配置 in the sidebar stays on
/zh/knowledges and renders the overview; tsc --noEmit is clean.

Co-authored-by: ZCode <noreply@zcode.ai>
Generated-by: deepseek-flash
Deliver the AIDP knowledge base overview, creation and detail experiences, and remove the AIDP knowledge-base safety guard contract.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant