Commit Graph

13 Commits

Author SHA1 Message Date
wizardchen 8d40959f88 fix lint and test failures 2026-07-01 17:31:42 +08:00
wizardchen 2f29054110 fix(knowledge): harden multi-tag data integrity and UX follow-ups
Clear tag relations on move/delete, validate tags on create, batch-load tags,
restore KB-scoped reference counts, dedupe SetKnowledgeTags, fix filter
double-fetch and ResizeObserver leaks, and regenerate Swagger for tag_ids.
2026-06-26 10:52:52 +08:00
Anky c007a897cf feat: support multi-tag for document knowledge (#1790)
* feat: support multi-tag for document knowledge

- Add knowledge_tag_relations join table for many-to-many tag-knowledge mapping
- Migrate existing single tag_id data to the new table
- Update Knowledge struct, filter, payload types (TagID -> Tags/TagIDs)
- Rewrite repository layer: SetKnowledgeTags, GetKnowledgeTags, ListIDsByTagIDs
- Update tag count references to query knowledge_tag_relations
- Update service/handler layers for multi-tag create/list/batch-update
- Frontend: multi-select tag sidebar, multi-tag chip display, tag toggle in popup
- FAQ tags remain single-tag model (unchanged)

* feat(knowledge): tag edit dialog with dynamic overflow and inline creation

- Add TagEditDialog component with search, multi-select, and confirm
- Replace inline t-popup tag selector with dialog-based editing
- Tags overflow with +N badge, visible count adapts to container width via ResizeObserver
- Date/card layout: fixed date width, tags flex to fill remaining space
- Add persistent new-tag input bar in dialog (Enter to create, auto-select)
- Tag creation emits callback to refresh parent tag list immediately
- Apply same overflow + dialog trigger to both card view and list view
- Add i18n keys: tagEditDialogTitle, tagEditSearch, tagSelectedCount, tagOverflowTip, tagNewPlaceholder

* fix: exclude soft-deleted knowledge from tag reference counts

CountReferences, BatchCountReferences, and DeleteUnusedTags now
JOIN with knowledges table to filter out soft-deleted records
when counting knowledge_tag_relations. Previously they queried
knowledge_tag_relations directly without the deleted_at check,
causing stale tag counts after knowledge deletion.

* fix: refresh tag counts after async knowledge deletion completes

Add a second delayed tag list refresh (2.5s) after tag deletion to capture
updated reference counts for remaining tags. The original immediate refresh
handles removing the deleted tag from the list, while this delayed refresh
ensures other tags' counts are correct after the async deletion finishes.

---------

Co-authored-by: lyingbug <xiayula2014@gmail.com>
2026-06-26 00:18:48 +08:00
wizardchen 0964b26558 feat(frontend): implement marquee selection for knowledge base
- Introduced a new `useMarqueeSelect` hook to enable marquee selection functionality in the knowledge base view.
- Integrated marquee selection with mouse events to allow users to select multiple items by dragging a selection box.
- Updated the `KnowledgeBase.vue` and `DocumentListView.vue` components to support the new selection feature, including visual indicators for selection mode.
- Enhanced user experience by providing a responsive selection interface that adapts to user interactions.
2026-06-10 11:02:57 +08:00
wizardchen f2cfc5fdc3 refactor(knowledge-processing): streamline cancel parse functionality and enhance user confirmation dialogs
- Refactored the cancel parse logic in `knowledge-processing-timeline.vue` to remove the dialog dependency, directly handling cancellation confirmation within the function.
- Introduced a `t-popconfirm` component for confirming cancellation actions in both `DocumentListView.vue` and `DocumentBatchBar.vue`, improving user experience with clear confirmation prompts.
- Updated the `KnowledgeBase.vue` to utilize new confirmation methods for reparse and delete actions, ensuring consistent user interactions across the application.
- Enhanced localization strings for better clarity in confirmation messages, supporting a more intuitive user experience.
2026-06-04 15:48:04 +08:00
wizardchen 44d6175559 feat: add knowledge parse cancellation with finalizing post-process state
Lets users stop an in-flight document parse to free up LLM / worker
resources without losing the chunks and index already written. The
core insight is that the previous parse_status=completed flipped as
soon as primary chunks landed, while the most expensive subtasks
(graph extract = N LLM calls per chunk, plus summary, question
generation) were still running in the background — so "completed"
wasn't actually terminal from a resource standpoint.

State machine

  pending -> processing -> finalizing -> completed
                              |
                              +-> cancelled (any of the three
                                            in-flight states)
                              +-> failed
                              +-> deleting

`finalizing` is the new post-process fan-out window. parse_status
only promotes to `completed` once pending_subtasks_count (a new
column tracking summary + question + per-chunk graph extract)
drains to zero via atomic FinalizeSubtask. Wiki ingest is
intentionally excluded from the counter — it's a KB-scoped
debounced batch and would otherwise pin parse_status in
`finalizing` for the wiki batch window.

Backend

- New ParseStatusFinalizing + pending_subtasks_count column with
  migration 000056.
- knowledgeRepository.SetFinalizing transitions processing -> finalizing
  conditionally so a racing cancel cannot be clobbered.
- knowledgeRepository.FinalizeSubtask atomically decrements the
  counter and self-promotes the row to completed when it hits zero.
- KnowledgePostProcess restructured to compute expected subtask
  count up front, flip to finalizing (or completed when no
  enrichment is enabled), and only then fan out subtasks. Subtask
  handlers (summary, question, graph extract) defer-decrement on
  terminal exit using the existing isFinalAsynqAttempt convention.
- New POST /api/v1/knowledge/{id}/cancel-parse handler accepting
  pending / processing / finalizing. Marks the row cancelled,
  zeroes the counter, best-effort dequeues asynq tasks via a new
  TaskInspector abstraction (asynq-mode walks pending/scheduled/
  retry queues; Lite-mode noop), and scrubs wiki ingest pending op.
- SpanTracker.AbortAttempt flat-sweeps every still-running span
  for the attempt via a new repo.CancelAllOpenSpans helper so the
  trace viewer's striped bars all flip to cancelled, even leaf
  generations whose parent stage already EndSpan'd (multimodal
  fan-out pattern). knowledge_post_process closes its postSpan
  via SkipSpan on the cancel/deleting entry guard so a worker
  that opens a span AFTER the cancel sweep doesn't leak it.
- Housekeeping and resetPendingTasks sweep finalizing rows
  identically to processing so a crash/restart can't strand them.
- DeleteKnowledge/DeleteKnowledgeList proactively dequeue
  downstream tasks via the same TaskInspector path.
- ChunkExtractService gets a cancel entry guard so the most
  expensive enrichment (graph extract) bails immediately when the
  parent knowledge is aborted.

Frontend

- New cancelKnowledgeParse API client + "Stop parsing" entry in
  both list view and card view more menus, gated on
  pending/processing/finalizing.
- Polling predicate refactored to a shared isParseInFlight helper
  that recognises `finalizing` (previously the doc list silently
  stopped polling once parse_status flipped from processing).
- Knowledge processing timeline: isPolling includes finalizing,
  new isHardTerminal short-circuits LIVE for cancelled/failed/
  completed so stranded child spans cannot pin LIVE on.
- DocumentListView.computeStatus distinguishes finalizing
  ("增强中") from completed and shows the previous "生成摘要中"
  copy when summary_status is still pending under finalizing.
  Added cancelled badge as well.
- i18n: statusFinalizing / statusCancelled / cancelParse* keys
  across zh-CN, en-US, ko-KR, ru-RU.

Docs / SDK

- docs/api/knowledge.md: documents the new finalizing state,
  cancel-parse semantics, and which statuses accept cancel.
- client (Go SDK): CancelKnowledgeParse with docstring listing
  the cancellable statuses.
2026-05-28 20:16:02 +08:00
wizardchen 6ac2f964ca feat(kb-list): replace type column with source and add description subtitle
Document list view relied on a redundant Type column (file extension is
already shown in the filename and icon) while hiding where a document
came from — external syncs from Feishu/Notion/Yuque, web URLs, manual
entries, and uploaded files were indistinguishable.

Swap Type for a Source column that resolves from `channel` first and
falls back to `type`, and surface `description` as a 12px subtitle under
the filename so the list view no longer requires hovering to read the
summary.
2026-05-06 16:41:20 +08:00
Claude f140c12518 feat(frontend): unify font rendering and add font picker in settings
The UI used hardcoded "PingFang SC" in 50+ components, while the global
font stack in App.vue used a different fallback chain. Outside of mainland
China this caused visibly different fonts in the sidebar, breadcrumbs,
search and agent views compared to settings and document panes.

- Introduce --app-font-family / --app-font-family-mono CSS variables in
  theme.css and route TDesign's --td-font-family through them
- Add a useFont composable that persists the user's choice in localStorage
  and applies it via document.documentElement.style before mount
- Replace hardcoded font-family declarations across the app with the new
  variables (TencentSans logo and the SVG attribute list are preserved)
- Add UI font and monospace font selectors in General Settings with
  i18n strings for en-US, zh-CN, ko-KR and ru-RU

https://claude.ai/code/session_01S1FVPf4jRfWXkTSnpMmMp7
2026-05-05 00:48:40 +08:00
wizardchen 9af5fb30ac fix(frontend): polish knowledge list sticky header and floating batch bar
- Detect sticky state via IntersectionObserver and flatten the table
  header's top corners when stuck so the rounded cut-outs no longer
  reveal the list container's background while scrolling.
- Lift the batch-action toolbar out of flex flow and float it 12px above
  the scroll container bottom so selecting rows no longer shrinks the
  visible list; strengthen its shadow to match the floating treatment.
2026-04-29 20:07:55 +08:00
wizardchen c62ff4c906 fix(frontend): knowledge document list layout, batch bar, and selection
- Platform route outlet: flex min-height so document area is not collapsed
- Card grid: stable :key=item.id; clamp selection anchor after list reload
- DocumentListView: TDesign checkbox, sticky header, neutral file icons
- DocumentBatchBar: column-footer placement; toned style vs floating pill
- Clear selection i18n: less ambiguous wording (e.g. 取消选择)
- Batch delete: poll list refresh after async queue; getKnowled returns Promise
- files.ts: use file icon for text types; align chat/upload icon usage
2026-04-29 15:20:41 +08:00
nullkey a40f191430 fix(knowledge-base): restore hover feedback on selected list rows
The previous list-view tone refinement set the selected-row hover
background to var(--td-brand-color-light), which is aliased to
var(--td-brand-color-1) — the same value used as the static selected
background. Hovering a selected row produced no visible change, leaving
users without feedback for what was clickable.

Use color-mix() to blend brand-color-1 with a touch of brand-color so
the hover delta is visible in both light and dark themes, without
reverting to the saturated brand-color-2 the original code used.
2026-04-29 14:28:56 +08:00
nullkey 48a764b866 refactor(knowledge-base): address review feedback
Backend
- BatchDeleteKnowledge handler now enqueues an asynq
  TypeKnowledgeListDelete task instead of calling DeleteKnowledgeList
  synchronously, matching the pattern used by ClearKnowledgeBaseContents.
  Avoids long HTTP timeouts on large batches and shares the existing
  async cleanup pipeline.
- Extract a small enqueueKnowledgeListDelete helper on KnowledgeHandler
  so BatchDeleteKnowledge and ClearKnowledgeBaseContents share the
  payload/marshal/enqueue boilerplate.

Frontend (DocumentListView)
- softer outer border and lighter row separators
- header background switched to the page tone with placeholder-color
  text, reducing institutional gray
- selected row uses an inset left accent bar and a quieter brand tint
  instead of a saturated background; hover stays neutral
- consolidate the .row-more-btn { opacity: 1 } rule that was duplicated
  across the hover and selected blocks
2026-04-29 12:01:38 +08:00
nullkey be8e53bf08 feat(knowledge-base): add document batch delete and list view
Add a list-view alongside the existing card grid (issue #957) and
multi-select batch delete (issue #1045) for documents inside a knowledge
base. The two views are toggled from the toolbar and the preference is
persisted in localStorage. Selection state is shared between views with
shift-range support and a sticky batch-action bar.

Backend
- POST /api/v1/knowledge/batch-delete: validates KB scope and editor
  permission, then delegates to the existing DeleteKnowledgeList service
  which already cascades vector/file/graph cleanup. Caps batch size at
  200 and uses a single GetKnowledgeBatch call for membership validation.

Frontend
- DocumentListView: table layout with sticky header, checkbox column
  (with indeterminate select-all), file-type icons, status badges,
  per-row action menu.
- DocumentBatchBar: floating pill bar with selected count and delete
  action; appears when items are selected.
- KnowledgeBase.vue: view-mode toggle, selection state, batch-delete
  confirmation dialog, hover/active checkbox overlay on existing cards.
- Extracted formatFileSize and getFileIcon to utils/files.ts to share
  with the new list view and avoid further drift from the existing
  inline copies.
- i18n keys added for zh-CN, en-US, ko-KR, ru-RU.

Closes #1045
Closes #957
2026-04-29 12:01:38 +08:00