Commit Graph

1264 Commits (22cbcdfa5789b33dbb8d47532c21b24da2fdf5aa)

Author SHA1 Message Date
nullptr-error 22cbcdfa57
feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549)
* feat(sandbox): resolve workspace paths through WorkspaceLayout

Keep remote sessions on the /workspace contract, while file, shell, and
artifact code follow the session layout instead of hardcoded paths.

* fix(sandbox): fail closed on host layout lookup and restore the shell blacklist

Treat host vs remote as an explicit origin, refuse inspect outside ReadRoots,
and skip collection when the output tree is missing or equals the project root.

* fix(sandbox): close leftover fail-open holes in the layout path

Keep host copy, collection, and prompt text from falling back to /workspace when a lookup fails or an adapter returns unclean roots.

* fix(sandbox): satisfy golangci-lint on the layout helpers

Wrap new copy and test lines to 120 columns, and add the exported comments revive requires.

* fix(sandbox): gofmt the read_file layout copy wrap

* feat(sandbox): add host as an OS-enforced backend type

Host is not a named/pinnable config: each command is a fresh local process, unlike Docker, Cube, and E2B.

* feat(session): persist Lite host workspace directory

Empty means an auto-allocated folder. Standard edition leaves the column unused so the shared session model still loads. SQLite also gains the tenant skill tables Lite shell_exec already expects.

* feat(localsandbox): adapt the host OS sandbox to session interfaces

File tools stay outside Seatbelt and are bounded by PathGuard. A revoked project directory fails closed instead of allocating a replacement workspace.

* feat(sandbox): run unpinned Lite sessions on the host backend

Lite opts into host explicitly; web stays disabled when no named remote config exists. Host workspaces are not destroyed or auto-committed.

* feat(desktop): pick and persist host project directories

The native folder dialog is the authorization path; typed paths are rejected. settings.sandbox.host tells the client when this edition can use it.

* fix(sandbox): fail closed on Lite host layout lookup misses

Unpinned host sessions were described as /workspace when pin read or
sandbox resolve failed. Prompts and attachment staging now share the
same fallback so Lite never pretends the remote tree exists.

* fix(frontend): keep settings.sandbox.host in sync with the backend keys

TestDeploymentCapabilityKeysMatchFrontend requires the lists to match. Host stays fail-closed like docker so a missed probe does not show Lite-only UI.

* fix(lint): satisfy golangci-lint on the host sandbox wiring

Check c.Error, wrap lines over 120 columns, put context first on versionsWorkspace, and document exported adapter methods.

---------

Co-authored-by: hailongzhao <hailongzhao@tencent.com>
2026-09-22 19:35:03 +08:00
lyingbug 33c0333ec9
fix(chat): restore shared workspace images after stream completion (#3523)
* fix(chat): restore shared workspace images after stream completion

* test(chat): wrap shared image completion cases for lint

* fix(chat): wait for persisted completion and preserve streamed replies
2026-09-22 00:16:58 +08:00
wizardchen 58260d192c fix(upload): accept XMind files before parser engine discovery 2026-09-21 23:18:11 +08:00
ChenRussell 5036062355 fix(wiki): degrade gracefully when revision snapshot is missing
The page revision history feature (introduced in 0.7.2) only snapshots
a version when an edit supersedes it, so versions written before the
upgrade (e.g. upgrading from 0.7.1 straight to 0.8.0) and old snapshots
removed by retention return 404 when fetched by version. The revision
drawer treated this as an error and surfaced a "wiki page revision not
found" toast.

A missing snapshot is a legal state, not a failure: loadVersionSnapshot
returns null on 404 (cached), the diff pane falls back to showing the
version's full content when the baseline snapshot is missing, a hint
state replaces the diff when the selected version's own snapshot is
gone, and the toast uses localized messages.
2026-09-21 13:10:52 +08:00
LuckVd 07e6e2984a
fix(knowledge): hide mutation controls on read-only shared knowledge bases (#3103)
A user browsing an org-shared knowledge base with a viewer (read-only)
grant still saw upload/edit/delete/settings controls when they are an
admin of their own personal workspace: KnowledgeBase.vue's canEdit /
canManage fell back to authStore.hasRole('admin') (the LOCAL tenant
role) unless the org share list happened to contain the KB, and
KnowledgeBaseList.vue's canManageKBCard never consulted the share
permission at all. Every such click is rejected by the backend's
3-D permission cap (effective = min(share, org_role, tenant_role),
RequireKBAccess requires OrgRoleEditor for mutations), so the buttons
were dead ends that made read-only shares look writable (#3098).

Both surfaces now treat an explicit cross-tenant grant as the single
source of truth: the effective permission (org share list entry or
my_permission from GET /knowledge-bases/:id, already capped
server-side) is checked first, and only owner/admin/editor grants
enable editing (owner/admin for manage). The local admin/creator
fallbacks stay reserved for own-tenant knowledge bases, so no
previously working action is hidden. Shared cards that lost their
permission field through the pin/recents merges (isMine === false)
are treated as read-only instead of falling through to the local
admin role.

Fixes #3098

Co-authored-by: LuckVd <LuckVd@users.noreply.github.com>
2026-09-21 13:10:20 +08:00
Leo Dawn a3c7be10ca
fix(agent): scope the @Skill and @MCP pickers to the agent that will run (#3475)
* fix(agent): scope the @Skill and @MCP pickers to the agent that will run

Both pickers listed the caller's own workspace, but a shared agent invokes its
OWNER's skills and MCP services. The two never line up, so for every shared
agent:

  * @Skill was always empty, in every skills mode. GET /skills resolves the
    sandbox config with (tenant, id), and the agent's config id does not exist
    in the borrower's workspace - effectiveTenantSkills short-circuits before
    it reads a single skill row. The response still reported
    skills_available: true, so the category appeared with nothing under it.
  * @MCP in "selected" mode was empty for the same reason: the preset holds the
    owner's service ids, which match nothing in the borrower's catalog.
  * @MCP in "all" mode was worse than empty. isMCPAllowedByAgent returns true
    for every enabled service, so the picker offered the BORROWER's own
    services; resolvePerRequestMCPScope then intersected the mention against
    the agent's preset, found nothing, and dropped it with only a warning.

Resolve the agent when the request carries agent_id + agent_source_tenant_id
and read its resources where they live. Only an explicit source workspace takes
the share path, so an own-agent request is byte-for-byte unchanged; built-in
agent ids exist in every workspace, and falling back to a share lookup without
one would let an org member take over the caller's default agent, exactly as
session.Handler.resolveAgent already documents.

Both endpoints serve only what the agent can actually invoke:

  * skills: the sandbox config comes from the agent, never from the query, so a
    borrower cannot name another config in the owner's workspace and enumerate
    it; "selected" narrows to the configured names and a disabled picker never
    reaches the owner's inventory at all.
  * MCP: the agent's explicit preset and nothing else, because that is exactly
    what resolvePerRequestMCPScope accepts for a shared agent. "all" therefore
    offers nothing rather than offering services every mention would drop.
    Whether "all" should become mentionable is a separate decision about that
    guard, not about the picker.

The cross-workspace MCP rows use a narrowed response built field by field.
NewMCPServiceResponse reveals endpoint URL, headers, env vars and stdio command
to an Admin, and a borrower can be an Admin of their own workspace - that shape
must be narrow by construction, not by role.

On the client the two lists now follow the selected agent: their cache keys
carry it, and the chat input refetches on a switch behind a request token, so a
slow response for the agent the user just left cannot overwrite the picker with
another workspace's services.

* fix(agent): check the c.Error return on the shared-agent picker paths

golangci-lint judges pull requests on the lines they introduce, so the
repository's older bare c.Error calls are grandfathered while these three are
not. Match the _ = c.Error form already used in mcp_service.go.
2026-09-21 13:02:34 +08:00
lyingbug 9030f556f2
refactor(embedding): move the wire formats into protocol packages, and correct the vendor facts (#3500) 2026-09-21 11:55:38 +08:00
lyingbug d6c7665cb5
refactor(rerank): move the wire formats into protocol packages, and correct the vendor facts (#3488)
把 8 个手写 rerank client 收敛成 3 个协议包(internal/models/api/{cohererank,dashscoperank,nimrerank}),每个带一份从厂商文档逐字粘来的 golden fixture。LKEAP 和火山保留官方 SDK,但只实现 api.Reranker。rerank.NewReranker 改成 catalog.Resolve + 按协议分发,函数体里没有厂商名。生产代码净 -147 行。

三件原来每个 client 各管各、现在由共用层统一的事:分批(按厂商声明的上限,智谱 128 / NIM 512 等此前无人执行)、分数标度(NIM 与 GPUStack 返回 logit,其余为 0~1 概率,统一换算后再与 RerankThreshold 比较)、NIM 的 truncate(默认 NONE 会让超长 passage 整请求失败,此前从未发送)。

对照官方文档订正四处厂商事实:GPUStack 分数标度、千帆三项上限、阿里 500 条上限、qwen3-rerank 是第二种协议(隐藏并在构造期拒绝)。Novita / OpenRouter / LiteLLM 三家官方有 rerank 但未开类型,本次开放,零协议代码。

运行时行为变更:NVIDIA 起发 truncate: END;GPUStack 分数按 logit 换算(可按行覆盖);truncate_prompt_tokens 收窄为厂商声明制;qwen3-rerank 存量行从静默打错变为构造期报错。详见 PR 描述。

关联 #3486。
2026-09-21 10:36:26 +08:00
lyingbug c40a9dd194
refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470)
把集中式的 OpenAI 方言客户端重建为三层:协议层 internal/models/api/<protocol>(OpenAI Chat Completions / OpenAI Responses / Anthropic Messages / Google GenAI),目录层 internal/models/catalog,厂商层 internal/models/vendors/<id>(27 家,go:embed)。27 家厂商逐条对照官方文档核验,厂商事实以数据声明,协议层不出现厂商名。

既有行的运行时行为会变的四处:
1. extra_config.api 变为保留的协议选择器,非法取值被拒绝;
2. Azure 未填 api_version 的行改走 /openai/v1 GA 数据面;
3. api.openai.com 的一方流量改走 Responses 协议(中转/网关不受影响);
4. 7 家厂商的输出上限字段按文档纠正。

不需要数据库迁移。详见 PR 描述与 website-docs/03-features/06-models.md。
2026-09-20 21:28:23 +08:00
nullptr-error d4b9fd0c72
feat(session): in-place rewind with workspace checkpoint reset (#3469)
* refactor(session): extract shared workspace git reset helper

Fork bootstrap and in-place rewind both need the same /workspace reset
script. Move it out of fork_bootstrapper so rewind can reuse it without
copying ExecShellCommand plumbing.

* feat(message): add DeleteMessagesFrom for rewind truncation

Rewind needs a composite created_at+id cursor so same-millisecond
messages after the fork point are not left behind. Delete inside a
transaction and return the rows so callers can log the count.

* feat(session): add in-place rewind service

Truncate the current session at a user or assistant message and git-reset
the live sandbox when a reachable checkpoint exists. Reset failure is
fail-closed so messages are never deleted ahead of the workspace.

* feat(session): expose POST /sessions/:id/rewind

Wire SessionRewindService through the session handler and container so
the client can rewind in place. Busy sources map to 409; git reset
failures stay 500.

* feat(chat): add rewind API client and i18n copy

Expose rewindSession with the same 180s timeout as fork, and add
chat.rewind strings in all five locales so the confirm dialog is not
hardcoded Chinese.

* feat(chat): add rewind button with confirm dialog

Offer in-place rewind next to fork on user and assistant messages.
Confirm before truncating the thread, then reset locally and prefill
the original question when the cut point is a user message.

* fix(chat): confirm rewind with a compact popover

Replace the full-page confirm dialog with a small popconfirm above the
rewind button, and shorten the swagger description to satisfy line length.

* fix(chat): skip markdown images with an empty destination

Empty ![]() was rendered as <img src="">, which shows as a broken image in the reply.

* fix(chat): clip sandbox panel slide-in and rename open tooltip

Keep the enter animation inside the viewport so it cannot flash a document
scrollbar and jump the page. Rename the header toggle from sandbox terminal
to expand sidebar.

* fix(session): 回滚时完成截断、互斥发送并重拉历史

客户端中断不再让 git reset 成功后留下未删的消息;reset/删消息前复查 busy,并锁住当前会话输入。成功后重拉历史,避免切会话预填串台和 steer 分段截错。

* fix(session): 工作区 git 外置,并让未开箱 fork 的回滚对齐 SHA

checkpoint、回滚和 fork 共用 --git-dir=/var/lib/weknora/workspace.git,避免 rm -rf /workspace 丢掉历史。
未开箱分叉会话回滚时改写或清除 ForkBootstrap,避免第一次开箱仍 reset 到旧切点。

* fix(session): 回滚加会话锁,并堵住发送中回滚与脏 SHA

同一会话并发回滚互斥(进程内 + Redis),冲突返回 409。发送/流式中禁用回滚按钮;历史重拉成功后再改界面。未开箱 fork 的 checkpoint SHA 必须是 40 位 hex。工作区 git 只认外置 GIT_DIR,不再 mv/rm 根上的 .git。

* fix(session): 未开箱 fork 回滚成功时不要提示没有沙箱

ForkBootstrap 已对齐切点后返回 workspace_reset,前端走「已回滚」;清掉引导时改报 NO_CHECKPOINT。纯聊天仍用 NO_SANDBOX。

* fix(chat): stub composerLocked in steer interaction tests

handleSteerMsg now bails when rewind locks the composer. The VM harness
did not provide that ref, so CI threw ReferenceError on every steer case.

* fix(session): allow git-layout mkdir in pinned checkpoint test

SkipWorkspacePrep still omits the input/output bootstrap exec. The
checkpoint script now mkdirs WORK_TREE and GIT_DIR, so the old
"command must not contain mkdir" assertion was stale.

* fix(session): block send while rewind holds the session lock

BeginTurn now fails if the rewind key is held, so AgentQA cannot start
during git reset. Knowledge-chat and executeQA check the same lock
before persisting messages. composerLocked is still page-local.

* fix(session): close send/rewind races and fail closed without a checkpoint

Hold the turn lease before persist so rewind cannot truncate an in-flight
send. TryLockRewind fails while a turn is live; emptying the conversation
resets the workspace through the same git path as a SHA rewind.

* fix(session): wrap rewind reset call to satisfy line length lint

* fix(session): fail closed on a replaced sandbox and close leftover rewind holes

Do not truncate history when the live workspace cannot follow the checkpoint, retry deletes after a successful git reset, and keep send and rewind exclusive even without a sandbox manager.

* fix(session): address rewind review findings

Correctness:

- Adopt a pre-move /workspace/.git into SessionGitDir on first use. Sandboxes
  provisioned before the git dir moved out of the work tree still hold their
  checkpoints there, so every SHA recorded on those turns stopped resolving:
  rewind 500'd instead of truncating and fork's rollback failed on a bad
  object. Adoption is guarded on the new dir being absent and on the work-tree
  repo carrying the checkpointer's committer identity, so an agent's own
  `git init` in /workspace is left alone.
- Only fail a send closed when BeginSessionTurn reports a rewind lock. Every
  other lease error degrades to running without a lease, as before rewind
  existed; a Redis blip on the lease script was rejecting the user's message.
- Release an abandoned fork snapshot after the truncate lands, not before.
  Clearing the bootstrap column is a DB write a retry can redo; deleting the
  snapshot is not, and a delete that exhausted its retries left the fork with
  no workspace to boot from under a full transcript.
- Re-acquire the rewind lock when a renew call errors, not just when it
  reports the lease lost. Sitting the tick out let a short Redis outage expire
  the 2m key mid-reset and hand the session to a second rewind.
- Keep the history cursor when a post-rewind reload fails. Clearing it sent
  the next scroll-up back to the newest page, which the kept prefix already
  holds, instead of to older messages.

Efficiency:

- Add ListAssistantCheckpointsUpTo and use it to answer "which checkpoint does
  kept history still reach". Rewind was reading every message body and artifact
  row in the session to find one SHA.
- Take the send-side turn lease once per request. The handler already holds it
  before persisting; QARequest.TurnLeaseHeld lets the QA services skip their
  own, so IM/MCP still take one and HTTP send stops doubling every rewind check
  and lease round trip.
- Batch the suggestion delete behind DeleteByMessageIDs instead of one query
  per deleted message while the rewind lock is held.
- Resolve the rewind affordance for the whole transcript in one pass rather
  than two list scans per rendered row on every streamed token.

Cleanup:

- Drop the SANDBOX_REPLACED skip reason, which the service never produces (it
  fail-closes with a 409), along with its copy in all five locales.
- Drop GetMessagesBySession from rewindMessageStore; rewind never calls it.
- Drop the unused chat.rewind.confirmTitle copy from all five locales.
- Restore the chatHeader.toggleSandboxPanel wording this branch had changed
  unrelated to rewind.

---------

Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-20 21:01:00 +08:00
lyingbug 7fa6f028fc
feat(chat): rework the saved-answer Markdown editor (#3467)
* feat(chat): make the saved-answer Markdown editor usable

Saving a chat answer to a knowledge base dropped the raw answer — citation
tags and all — into a 760px drawer with a single column and a preview
toggle. Every `<kb doc=… chunk_id=… kb_id=…/>` had to be deleted by hand,
and the title arrived hard-cut with an ellipsis.

- strip `<kb/>` tags from the seeded draft and list the cited documents
  once at the bottom; keep `<web/>` citations as real Markdown links
- cut a long question on a clause boundary instead of at 40 chars + "..."
- compact title + knowledge-base row, full-height editor (no more
  calc(100vh - 360px)), and an edit / split / preview switch that starts
  on split whenever the drawer is wide enough for two panes
- opt-in maximize toggle on SettingDrawer for full-width editing
- native textarea in place of t-textarea, with Cmd/Ctrl+B/I/K/S/Enter,
  list continuation on Enter and Tab indenting
- confirm before discarding unsaved changes; show a character/line count

* style(chat): stop painting the Markdown editor green

Brand green was doing decorative work in the editor: a 4px green rule and
an 8% green wash on every blockquote in the preview, a green pill for the
active view, green toolbar hovers, and a green halo around the whole
editor while it had focus. Together they read as noise.

Green now means action only — the publish button, links, keyboard focus
rings. Blockquotes match the chat renderer's own neutral treatment
(2px --td-component-stroke, no fill), the view switch uses a raised
neutral pill, and toolbar hover/active use the container tokens.

* refactor(chat): fold the editor toolbar from 16 buttons to 10

Sixteen same-sized icons gave equal weight to "bold" and "insert
horizontal rule", and at the default drawer width the row already ran out
of space (the overflow scrollbar is hidden, so the last icons simply
vanished).

Headings collapse into one labelled "标题" menu and the block inserts
(quote, code block, table, image, rule) into "插入"; the actions people
reach for mid-sentence — bold/italic/strike/inline code, the three list
kinds, link — stay one click away. The cropped shortcut line in the
status bar becomes a keyboard button whose tooltip lists every binding,
including Cmd+Enter to publish, which was undocumented.

* refactor(chat): collapse the editor into four bands

The drawer stacked seven horizontal strips — header, subtitle, a labelled
title row, a labelled knowledge-base row, toolbar, canvas, status bar —
each with its own rule or tint, and none of them shared a left edge.

The document now has a head (a borderless title that reads as a title,
with "存入 <知识库>" as a sentence under it), one editor card, and a
footer. The header subtitle, the two field labels and the status strip
are gone: word/line counts moved next to the draft tag in the footer and
the shortcut sheet to the toolbar's right end. Title, destination and the
editor card all start on the same left edge.

* refactor(chat): move the destination onto the title row

"存入" was a verb invented for this one screen, and the row it sat on cost
the head a whole line. The destination is now the folder icon this product
already uses for a knowledge base in the @-mention list, followed by the
select, parked at the right end of the title row — so the head is one line
whose two ends line up with the editor card below it.

The narrow layout that stacks them again is now driven by the editor's
ResizeObserver instead of a `@container` query: the scoped-style pipeline
drops `@container` blocks (none of them reach the page), so the previous
rules — stacking and, worse, the toolbar wrap that keeps the last buttons
from silently overflowing — never actually applied.

* style(chat): let the destination select reach the right edge

The select's box sat flush with the editor card, but a 132px min-width
held it open past its content, so the folder icon, the name and the caret
stopped 43px short — the block read as floating rather than aligned. It
now shrinks to its content (up to 260px, then truncates), leaving only the
control's own 5px of inner padding, and stays right-aligned when the
narrow layout stacks it under the title.

* style(chat): keep the narrow toolbar on one row

A narrow drawer wrapped the toolbar into two rows and left the view switch
hanging beside the second one, and the head split into two rows as well.
The view switch now drops its three text labels on narrow (the tooltips
already carry them), which buys back enough room for the whole toolbar —
all ten controls — to stay on one row down to the 600px minimum width.
The head keeps title and destination on one line too, now that the
destination shrank to its content.

* style(chat): shrink the editor drawer's header

The header was sized for a title plus a subtitle; with the subtitle gone
it kept 65px for one 15px line — a 32px badge inside 14px of padding,
propped up by TDesign's 56px min-height. Down to 47px: 26px badge, 9px
padding, min-height released. Scoped to this drawer, so the other
SettingDrawer consumers keep their proportions.

* chore(chat): drop leftovers from the editor rework

- the per-button `btn-<key>` class on toolbar buttons: nothing styled or
  queried it
- `INDENT` was exported but only ever used inside markdownEditing
- a comment still pointed at the status bar that no longer exists
2026-09-20 16:16:28 +08:00
lyingbug 093c16cbb3
fix(agent): end the turn when the completion cap truncates an answer (#3449)
* fix(agent): end the turn when the completion cap truncates an answer

A round that came back with finish_reason=length and no tool calls used to
fall through analyzeResponse as non-terminal. With no tool calls to run,
appendToolResults pushed the half-written answer back into the history as a
plain assistant message with nothing telling the model to continue, so the
next round rewrote the answer from the top, hit the same cap, and repeated
until the round budget ran out or the user cancelled.

Three guards, each independently load-bearing:

- analyzeResponse gains a truncation case: deliver the partial text and end
  the turn. A cap hit that produced no text at all has nothing to hand over
  and defers to the existing bounded empty-content retry. No continuation
  nudge is sent — it only grows the prompt with the discarded fragment, and
  assistant prefill, the reliable form, is unavailable on most
  OpenAI-compatible endpoints.
- A consecutive-length breaker stops the loop when truncation keeps landing
  inside tool-call arguments, the one shape that still legitimately loops.
- The stuck-loop detector now counts an identical lack of content. A model
  burning its whole budget on reasoning returns empty every round, which used
  to land in the else branch and reset the counter, so the guard could never
  fire on the case that needed it most.

The answer event and its Done marker carry a truncated flag through the SSE
metadata, and the chat UI shows the same style of notice it already uses for
fallback answers.

Fixes #3446

* fix(agent): treat unterminated reasoning as no answer and keep the truncation marker

Review follow-up on three ways the truncation path could still mislead.

An inline <think> block that the cap cut off never gets its closing tag, so
the pair regex left it whole and the round looked like it had produced an
answer. The truncation case then skipped the empty-content retry it exists
for and emitted the chain of thought as the final answer. StripThinkBlocks
now drops a dangling <think> through end of input, which is what the
streaming splitter already does with the same text, so the two agree on what
counts as an answer.

The truncation marker only rode on the SSE metadata, and a finished
conversation is rebuilt from agent_steps rather than replayed from stream
events. A reloaded, shared or re-opened turn therefore lost the notice and
its half-written answer looked complete. AgentStep carries the flag now — it
is a jsonb column, so no migration — and the frontend marks the rebuilt
answer event and message from it.

The consecutive-length guard ran before the round was recorded, so a final
round of "let me look that up" plus a truncated tool call handed that
preamble over as the final answer, with its tool calls never refused and the
preamble never retracted from the answer area. The guard now records the
round and fails its tool calls the way every other truncated round does, and
a response carrying tool calls never donates its text as the answer.
2026-09-20 13:17:50 +08:00
lyingbug 9e0c28fbc9
feat(artifacts): let users delete generated files (#3447)
* feat(artifacts): let users delete generated files

技能生成的文件此前只能列出、预览和下载,没有任何删除入口,后端
handler/service/repository 三层都没有实现。DeleteSession 里那句注释
("a dedicated GC job or explicit hard-delete API is the right place to
reclaim storage") 留的就是这个位置。

Tombstone, not a row delete. message_artifacts 新增 deleted_at,删除只
打标记不删行。position 是下载接口寻址用的下标(msg.Artifacts[index]),
物理删掉中间一行会让它后面的文件整体前移,已有链接下到错的文件;而
ArtifactCollector 的去重集就是从这张表读的,行没了之后沙箱里 mtime 未变
的同名文件下一轮就会被重新采集回来,删了又出现。墓碑同时挡住这两条。
loadArtifactsByMessage 因此刻意保留墓碑,展示侧用 MessageArtifacts.Live
过滤;NewMessageArtifactRecords 带上 DeletedAt,任何一次消息重写都能把
墓碑原样写回去。

Bytes. 字节是真回收的,走 catalog.Release 引用计数:一份文件可能同时被
知识库条目和后续回答持有,只有所有持有者都放手才 DeleteFile。删多个版本
时同一个对象可能来自多条消息,每条消息的绑定都要释放,字节只删一次。
回收发生在打标记之后,且只针对本次调用真正认领到的行——并发的第二次删除
认领不到任何行,也就不会去动别人正在回收的对象。释放失败一律保留字节:
留个孤儿 blob 以后还能靠墓碑上的 url 回收,删错了则是别人的文档里的图片
凭空消失。

Scope. 会话内面板每个版本单独一行,删的就是点的那一版;产物库一行代表
一个文件(带版本数),默认连同该文件在这个会话里的所有版本一起删,否则
删完这一行还在、只是显示上一版。权限比下载严一档:下载认共享智能体的
只读访问,删除只认会话归属人。

Inline references. 正文里的 resource:// 引用渲染成置灰加删除线的卡片,
不可点击,和「模型引用了不存在的文件」的 --pending 态区分开。图片类产物
也降级成卡片:走 renderImage 只会拉取失败,留下一张永远加载不出来的图。
墓碑必须留在传给渲染器的产物列表里——句柄形式与知识库图片同形,过滤掉
之后句柄对不上本条回答,会被当成外部受保护图片去拉一个已经不存在的
blob,结果是裂图。组件里因此拆出 liveArtifacts 只给计数和文件列表用。

Also: 产物库是 offset 分页的无限列表,删一行会让后续页整体前移漏掉一条,
改成按已显示行数取下一页并按 key 去重;access.ResolveMessageArtifact 与
MessageReferencesFile 不再让墓碑授权访问;SessionArtifacts 过滤墓碑,
避免新回答把引用绑到已删文件上;版本澄清文案不再把已删版本算进版本数。

docs/swagger.* 未重新生成:仓库里那份已经落后若干功能,重生成会带进约
1000 行无关漂移,另开 PR 同步。

* fix(artifacts): close the delete holes found in review

Regeneration. loadKnownSet 把墓碑的 ContentHash 也放进了去重集,于是
knownSameContent 会把「删除后技能重新生成、字节恰好相同」当成 fork
checkout 那种 restore:不上传、不挂回本轮回答,文件再也回不来。墓碑现在
只登记 (path, mtime),不进 hash 也不进 byPath —— 前者才是「沙箱文件没动
过就别复活」需要的键,后者是「同内容恢复」的短路,两件事不该共用。
RecordRestoredArtifactMtime 也不再改墓碑:它的 mtime 就是那把锁。

Message file proxy. /sessions/:id/messages/:message_id/files 走
MessageReferencesFile,而正文检查在最前面且无条件为真。删除不会重写回答,
resource:// 句柄还留在正文里,于是这条代理会继续把已删文件交出去——包括
交给共享智能体的只读访客,也包括「字节因为知识库还持有而没被回收」的情形。
现在先看 artifacts:命中本条消息的墓碑直接 false,命中 live 直接 true,
其余(知识库图、附件)才回落到正文。同一文件挂在多个位置时只要还有一个
live 就仍然可取。

Cross-session bytes. CreateForked 复制产物行时连同存储 URL 一起复制,但
不会给副本重新 Bind,所以 catalog 的引用计数看不到分叉。在父会话里删除会
把分叉还在用的字节删掉。无 catalog 部署、以及存的是裸 provider 路径的行,
同样不在计数覆盖内。回收前新增一道 CountLiveArtifactsByURL:只要还有任何
未删除的行指向同一对象就保留字节,查不出来也保留。配套加了 url 的部分索引。

Atomicity. SoftDeleteSessionArtifacts 原来逐条 UPDATE 不带事务,删多版本
时中途失败会留下「一部分已隐藏、字节没回收、接口 500、用户重试 404」。
现在整批放进一个事务。writeMessageArtifacts 是整表替换,拿着删除前快照的
并发写会让墓碑复活而字节已在回收,现在按 position 把已存在的 deleted_at
合并回去——删除是唯一不允许被过期写覆盖的属性。

all_versions 两个路由改用同一个解析器(strconv.ParseBool),此前一个是
== "true"、另一个是 != "false",显式传 1/TRUE 在两边语义不同;缺省值仍
按路由区分。

测试:收集器三条(未动不复活 / 重新生成要回来 / live 的同内容恢复仍短路)、
access 三条(正文不能复活已删授权、多副本只要有 live 就可取、非产物引用
仍走正文)、service 七条(归属人校验、他人会话拒绝、并发认领为空、live
行仍在则保留字节、guard 失败保留字节、多版本按对象归并 owner、无
source_path 不扫全会话)、repository 三条(墓碑抗过期写、事务回滚、跨会话
URL 计数)、handler 一条(两个路由的 all_versions 解析矩阵)。其中
「重新生成要回来」在改回旧实现时确认会失败。

client/ 没有 artifacts 相关 API(只有一个 SSE 事件类型常量),无需同步。
2026-09-20 13:01:46 +08:00
wizardchen a163bab32f feat(knowledge): rework the parse timeline panel's layout and failure card
The processing-pipeline drawer presented a failed parse worst-side-up.
The error card printed the error code twice (headline plus a solid red
pill), gave the most prominent line to the generic "check the logs"
filler, and left the one line that explains the failure — the backend's
own message — last, smallest and greyest. Around it, the waterfall left
roughly half the panel blank, ruled its time axis at 0/124/247/371/494ms
(the raw total cut in four), flung a ROOT/STAGE label to the far right of
every name cell, and drew the stages that an upstream failure had
abandoned as pending rows with dashed stubs pinned to the track edge.

Error card
- Headline says which stage broke; the code appears once, as a quiet
  chip. The backend message is promoted to the card's primary line.
- Retry moves into the card, next to the reason, and loses the
  brand-green outline it wore against a red failure. It stays in the
  toolbar only when a failure carries no last_error.
- The headline no longer uses --td-error-color on the card's own error
  tint, which measured around 3:1 in both themes.

Waterfall
- Axis ticks round onto a 1/2/2.5/5 x 10^n step, and bars are positioned
  against the rounded axis maximum so bars and ruler cannot disagree.
  Gridlines mark each tick behind the bars.
- Kind labels are reserved for `generation` spans instead of stamping
  ROOT/STAGE/SPAN on every row via margin-left:auto.
- Depth is carried by indent guides rather than three near-identical row
  tints that read as banding.
- Stages abandoned by an upstream failure say "not run" and recede.

Layout and interaction
- The detail panel opens on load, on the failed span or the root, so the
  panel is not half empty and the rows are discoverably clickable. It
  stays closed once the user closes it.
- The waterfall is content-sized (capped at 60%) and the detail absorbs
  the remainder, instead of a fixed 50/50 that clipped rows mid-height.
- The dot-joined meta sentence becomes label/value stats; the panel name
  moves to an overline above the filename.

Axis math moves to utils/traceAxis.ts with unit tests. New i18n keys are
added to all five locales; three keys left unreferenced by this change
are removed.
2026-09-20 12:25:31 +08:00
hataa 3017145102
fix(frontend): stop seeding new answer events with prior-round text (#3386)
A new answer round with no tool_call between rounds (stream-stall retry,
length-truncation continuation, empty-answer nudge, finalize synthesis)
inherited the concatenated text of every prior round via the
message.content seed, duplicating it on every recompose with no way to
retract. Seed only when no other live answer event exists in the stream.

Fixes #3383
2026-09-20 12:02:09 +08:00
wizardchen 5c5d46d9fb fix(ui): add resource list title icons and highlight shared filter 2026-09-20 00:17:11 +08:00
lyingbug 014f95f139
fix(ui): 统一资源图标并调整会话分叉标识 (#3430)
* fix(ui): 统一资源空状态和共享筛选图标

* fix(ui): 将会话分叉标识移至右侧菜单位置
2026-09-19 20:59:12 +08:00
wizardchen e986579731 refactor(ui): 清理资源列表废弃组件和无效样式 2026-09-19 20:40:19 +08:00
wizardchen eec236b27f fix(ui): 优化资源卡片、标签分组与共享空间创建布局 2026-09-19 20:40:19 +08:00
lyingbug a46a3c5996
fix(ui): 优化对话布局、导航与产物和引用展示 (#3427)
* fix(ui): refine chat scrolling, outline, and panel interactions

* fix(ui): include reference styling, composer copy, and title motion
2026-09-19 19:25:52 +08:00
lyingbug 2a6a9c2517
fix(ui): 优化知识库文档交互与对话布局 (#3420)
* fix(knowledge): streamline document browsing and tag editing

* fix(chat): align panel headers and refine composer spacing
2026-09-19 11:58:49 +08:00
lyingbug 03d9d66a1f
feat(agent): size agent history by the window and calibrate token estimates (#3413)
* feat(agent): size agent history by the window and calibrate token estimates

Agent history was capped at history_turns (default 5) because compaction
could not survive a turn. With checkpoints persisted, load history by
tokens instead, and let compaction bound the session.

Budget. The loader drops the oldest turns that do not fit, and what it
drops is lost: neither replayed nor summarized. A budget equal to the
compaction threshold (the earlier attempt, since reverted) let the loader
trim first, so whenever one turn was larger than the system prompt plus
the new question the request never crossed the threshold; nothing was
summarized and the session became a sliding window with no checkpoint.
agent.HistoryTokenBudget is now the whole window: overflow reaches the
first round's compaction, which summarizes it into a new checkpoint.
A turn-by-turn regression test drives the real loader, budget and
compactor and fails as soon as a stored turn after the checkpoint is
missing from the loaded history; restoring the old budget fails it.

Summarizer input. History can now reach the window, so the part being
summarized can outgrow one request. An overflowing request degrades to a
raw archive that is never persisted, so every later turn would fail the
same way. Prepare keeps the newest messages that fit, the prompt states
how many were left out, and file paths still come from all of them.

Calibration. cl100k counts Chinese at about a token a character where
Qwen and DeepSeek spend about 0.6. The estimator now carries a scale
(clamped to 0.5-1.5, text only), learned from consecutive requests in a
turn: they share tools, system prompt and earlier messages, so the
provider's growth between them prices exactly the appended messages,
without mixing in how a provider renders tool schemas. The turn's scale
is stored on its usage (context_token_scale); the next turn's loader
prices history with it and hands it to the engine. Loading, the first
compaction check and compaction itself share one estimator, so they
agree; calibrating only the trigger would let the loader drop turns
again, which the regression test covers.

Also: history is priced as the engine sends it (redacted KB/Wiki results
cost one line); a checkpoint older than the rows read is matched by the
assistant rows' (created_at, id) order; a read ending on a turn's
question keeps that turn; a compaction discarded for freeing under 5%
still persists its checkpoint; a checkpoint write matching no row is an
error; a partial index backs the newest-checkpoint lookup. Agent mode no
longer reads history_turns: the field leaves AgentConfig, the editor
hides it in smart-reasoning mode, and quick-answer keeps its turn cap.

* fix(agent): address review of window-sized history loading

Summarization. The summarizer call had a fixed 60s total timeout. With
history loaded up to the window, a request could carry ~175k tokens and be
cut off while prefilling or writing normally; the degraded result left no
checkpoint, so the next turn reloaded the same history and failed the same
way. Summarization now streams and is cancelled only after no output for the
engine's stall timeout (120s by default, LLMCallTimeout overrides), with the
overall ceiling left to the transport, as for the engine's own rounds and as
in Codex and Pi. A stopped turn is not retried. When the summarizer still
fails, the raw archive is persisted as a checkpoint marked degraded so the
loop is broken, and the next compaction refines it as the previous summary.
The archive is held to the summary budget, newest messages first, so a
degraded compaction always frees room.

Loading. The loader priced turns as sent but returned and held them as
stored, so wiki pages stored in full and sent as one line could pile up in
memory. It now returns the as-sent history and releases each turn's stored
rows once replayed, keeping about a page of rows at a time.

Index. The partial checkpoint index is replaced by a composite
(session_id, created_at DESC, id DESC) index serving the backwards page,
the newest-checkpoint lookup and the recent-messages reads. It is built with
CREATE INDEX CONCURRENTLY so writes to messages are not blocked; the
migration holds that single statement, since a multi-statement query runs as
an implicit transaction. A PostgreSQL integration test, skipped without
WEKNORA_MIGRATION_TEST_POSTGRES_DSN, applies the chain, runs 000106 down and
up through golang-migrate, and checks both queries use the index without a
sort; the SQLite migration test checks the same plans.

Calibration. It no longer waits for a total token count, and a usage with
only a scale is persisted. A turn that measures nothing carries forward the
scale it started from, so the newest turn always has the latest one.
2026-09-18 22:51:31 +08:00
lyingbug db8e7611be
fix(security): close cross-workspace access paths in shared spaces (#3408)
* fix(security): close cross-workspace access paths in shared spaces

A review of how shared-space (organization) members reach each other's
resources found six paths that bypass the org-share permission model:

- presigned-preview signed any resource handle or storage path, turning a
  known resource:// handle into an anonymous /r/ URL that outlives share
  revocation. It now requires the path to belong to the caller's tenant,
  like /files.
- POST /initialization/initialize let a shared-KB editor rewrite the owner
  workspace's models (base URL, API key) in place. Only the KB's own
  workspace may call it, and rewriting a stored model needs the same
  authority as PUT /models/:id.
- KB JSON carried the legacy inline credentials (storage_config
  secret_id/secret_key, which initialization fills with the MinIO env
  keys, and vlm_config api_key) to every share receiver. They are withheld
  from JSON; their DB columns are unchanged.
- A chat without agent_source_tenant_id resolved shares before the
  caller's own agent, so a member sharing a same-ID built-in agent took
  over other workspaces' default agent. Own agents now win, built-in
  agents can no longer be shared (existing such shares no longer resolve),
  and embed channels drop a visitor-supplied source workspace.
- Any org-admin tenant (even a tenant Viewer inside it) could raise another
  workspace's KB share to editor/admin, and the route guard was bypassable
  via an unrelated :id. Share management is now: the sharer from the source
  tenant (Contributor+), source-tenant Admin+, or an org-admin tenant's
  Admin+ that may only remove or lower. share_id must belong to :id.
- Wiki write tools were registered for every wiki KB in the search targets,
  which only need read access, so a viewer share (e.g. via the built-in
  wiki fixer) could edit or delete another workspace's wiki pages. They now
  act only on KBs the caller may edit.

* fix(security): close the KB settings path and owner details for share receivers

Follow-up to the shared-space review:

- PUT /initialization/config shares the route guard that admits share
  editors, so an editor could still rebind the owner's KB models, chunking
  and storage, and storage backends resolved against the caller's workspace
  let it bind the owner's KB to its own backend. Another workspace now needs
  an admin share (the only share level the frontend offers settings to) and
  may not change the storage binding at all.
- GET /initialization/config showed model base URLs and bucket locations to
  any admin of the caller's own workspace, including share receivers. They
  now only see whether credentials are configured.
- Wiki write tools on the caller's own KBs had no role floor, so a tenant
  Viewer (and the IM, embed and MCP endpoint principals that run as Viewer)
  could write through an agent what the HTTP routes deny. Writes now need
  Contributor+, or the ingest capability for a scoped API key, following
  the RBAC rollout switch.
- resolveAgent logs the share lookup error instead of a nil own-agent error
  when a shared selector fails.

* fix(security): close the medium shared-space access findings

Follow-up to the high-risk fixes, from the same review:

- Wiki fixer moved into a shared KB's workspace ran with the caller's own
  config there: an unset MCP mode registered all of the owner's MCP
  services, and an "all" KB scope reached the owner's other KBs. The scoped
  run now uses the built-in config pinned to that one KB, without MCP,
  skills, sandbox or web search, and falls back to the KB's own model.
- An unset MCP mode means "all" at runtime but is shown as none in the share
  scope; shared runs now treat it as none.
- Quick-answer mode used the request's web_search_enabled alone, so a
  receiver could turn on search the agent disables and spend the owner's
  provider quota. It now requires the agent setting too, as agent mode does.
- summary_model_id picked any model of the workspace a run executes in. It
  is ignored for shared agents and the relocated wiki fixer.
- A workspace that left or was removed from an organization kept sharing its
  KBs and agents. Its shares are revoked on departure, and share queries and
  permission checks require the source workspace's membership and a live
  organization, which also covers rows left behind earlier.
- Sharing an agent exposes its KB scope to all members, so a Contributor
  could share colleagues' KBs (or "all") through an agent. The sharer must
  now be able to share each KB directly (creator or Admin+; "all" needs
  Admin+), also when a shared agent's scope is widened later.
- A scoped API key with manage_channels could mint an MCP endpoint token
  wider than itself. Endpoints it creates, updates or rotates must stay
  within its KB allow-list and capabilities.
- A shared agent's run indexed the receiver's Q&A into the owner's chat
  history KB; indexing now uses the session owner's configuration.
- Sharing an agent with skills keeps injecting the owner's skill
  environment values (product decision); the share panel now warns that
  members can read them. Preview of originals through read-only shares is
  kept as designed and documented.
2026-09-18 22:00:02 +08:00
lyingbug 68e6c03dc4
fix(skills): upgrade outdated sandbox skills without rolling back the catalog or taking them offline (#3406)
* fix(skills): keep retries and catalog installs from rewriting the skill definition

Every install path wrote its archive back to the workspace catalog. After a
skill was re-registered as v2, sandboxes still on v1 are pinned to v1's
archive, so retrying one of them (a failed retry, or a ready skill retried
with guidance) reinstalled v1 and also moved the catalog definition back to
v1 and deleted v2's archive.

Installs now carry where their archive came from. Only an upload or a source
pull is a new definition; a retry or a catalog install uses bytes the
workspace already stores and never rewrites the definition. A retry of a
pinned install keeps its pin and replays its own version, and bytes that
neither the definition nor the row holds are refused with a conflict.

The catalog listing also reports each installation's version so the UI can
show what an upgrade moves from and to.

* feat(frontend): upgrade outdated skill installs from the catalog, sandbox drawer and agent editor

An install whose archive differs from the catalog was flagged as outdated,
but nothing could move it to the catalog version: the install drawer hid
ready installs, and the manage drawer only offered a retry, which replays
the sandbox's own archive.

- Skill settings: cards with outdated installs show an upgrade button that
  opens the install drawer with every outdated sandbox preselected. The
  add wizard and install drawer also let outdated ready installs be picked,
  labelled with the version they move from and to.
- Sandbox skill drawer: an outdated skill shows a "new version" row whose
  upgrade button installs the catalog onto that one sandbox.
- Agent editor: skills on the chosen sandbox that are outdated show the
  version change and an upgrade button, both for admins only, matching the
  admin-only catalog install. The install progress entry, which opens a
  drawer backed by admin-only endpoints, is now admin-only too.
- A skill that is being upgraded is no longer pruned from the agent's
  selected skills while it is briefly not ready.

The outdated check is shared in utils/skillUpgrade.ts.

* feat(skills): keep the previous version serving while an upgrade runs or after it fails

An install rewrote the row to the new version and marked it installing as
soon as it started, and the agent is only offered ready rows. So an upgrade
took the skill away from every sandbox for its whole run, and a failed
upgrade kept it away, even though the image pointer only moves on success
and the previous version was in the image the whole time.

The row now records what it described when it was last ready (served:
version, description, instructions, digest, the archive its files come from,
and the snapshot that installed it). The agent's usable set, member env
acceptance and the @-mention list read TenantSkillEntity.ServedView, which
is that version marked ready while the row is installing or failed. A
successful install clears it and releases its archive; a failure or a stop
keeps it.

Keeping that consistent:
- The served archive counts as a reader when a bundle is released or
  replaced by a re-registered catalog, so v1's files stay readable while v2
  installs.
- The reaper and a failed removal put the served version back when the image
  never moved past it, instead of labelling v1's files with the upgrade's
  metadata. A stuck upgrade whose chain cannot be read is left alone, since
  v1 keeps serving meanwhile.
- The env declaration is stored after the pointer moves rather than before
  the snapshot, so an upgrade that fails late cannot drop the admin value of
  a variable the previous version still reads.

Migration 000104 adds tenant_skills.served. The console says "upgrading,
still running 1.1.0" or "upgrade failed, still running 1.1.0", the agent
editor keeps such skills selectable, and the upgrade texts no longer warn
that the skill goes offline.

* fix(skills): offer only the upgrade to installs the catalog has moved past

Review follow-up on the upgrade flow.

- An install that differs from the catalog, ready or failed, is now offered
  the upgrade and not the retries. The retry icon and the retry-with-guidance
  box both replay the archive the install is pinned to, so next to an
  Upgrade button they reinstalled the version the operator came to leave
  behind. A failed first install of v1 whose catalog has since moved to v2
  used to retry v1 from the drawer while the agent editor's Install went to
  v2; every entry now goes to v2, and the agent editor labels it "Upgrade".
  The drawer explains that the failed install is replaced by the catalog
  version.
- A catalog install or a retry reuses the definition that already holds its
  bytes instead of re-running the catalog upsert, which rewrote the row and
  bumped its updated_at every time the skill was installed somewhere. The
  upsert still runs for a definition that does not exist yet or whose object
  was lost.
2026-09-18 20:27:43 +08:00
MercuialC aaec920a9c
feat(audit): 知识库活动记录对 API Key 操作额外显示 Key 名称 (#3405)
* feat(audit): show API key name on knowledge-base activity

API-key operations currently look like the first tenant user or
"system". Snapshot the key id/name into activity details so the
feed can tell which key initiated the change, without restoring
key authorization onto async workers.

Fixes #3402

* fix(frontend): show activity API key on a second line

The 132px actor column truncates "user · API Key · name" into one
ellipsis. Keep the person on the first line and the key name below.

---------

Co-authored-by: MercuialC <MercuialC@users.noreply.github.com>
Co-authored-by: root <root@localhost.localdomain>
2026-09-18 19:39:34 +08:00
lyingbug 2be7bd4063
fix(agent): search bound knowledge bases before answering, and pass suggested-question origins (#3400)
* fix(agent): search bound knowledge bases before answering, and pass suggested-question origins

A user picked the suggested question "为什么在比较图形时需要谨慎处理?"
and the agent answered in round 1 with no tool call, claiming it had
searched the knowledge base and found nothing, then explained misleading
statistical charts. The question had been generated from "Corners Don't
Look Like That: Regarding Screenspace Ambient Occlusion" in a bound base,
where "comparing graphs" means SSAO falloff curves.

Two things let that happen: the grounding prompt said "Stable general
explanations need no lookup", and nothing told the agent where the
question came from - the base in question had no profile, only two
recent titles in the directory, and the click sent the text alone.

Prompt
- With knowledge tools available, search bound bases before answering a
  question about a topic, even one that reads like general knowledge;
  directory profiles and recent titles cannot prove a base lacks it.
- The general-explanation exemption applies only without bound bases.
- Say you searched or found nothing only when a search tool ran.

Question origin
- Suggested questions from FAQ/document chunks also return knowledge_id.
- Picking one on the home or chat page sends question_origin
  {knowledge_base_id, knowledge_id} with that question only.
- The service keeps the origin only when its base is inside the turn's
  resolved scope and the document belongs to that base; it never
  changes the scope (unlike knowledge_base_ids, which narrows it).
- The engine renders it in runtime_context as <question_origin> with the
  base and document handles and a note to search it before answering.

* fix(agent): keep question origins across file/tag scopes and bind them to the send

Review follow-up for the suggested-question origin.

- Scope check: the origin was kept only when its base was in the resolved
  KB list, which is empty for file-only and tag-only scopes even though
  their bases are searched. It is now checked against SearchTargets after
  they are built; the document is kept only when a target for that base
  covers it (unfiltered base, or a document scope listing it).
  resolveQuestionOriginInfo re-checks SearchTargets, looks up the name of
  a base that is not in kbInfos, and the renderer omits an unknown name.
- Frontend: the origin travelled through module-level "pending" state, so
  a send that returned early (agent not ready, upload in progress,
  steering) left it behind and a second pick overwrote it. It now rides
  with the one send: triggerSend(text, options) -> createSession ->
  send-msg -> sendMsg / changeFirstQuery.
- RetrieveKBOnlyWhenMentioned: suggestions are still generated from the
  agent's bases, but picking one retrieved nothing. The origin now
  selects its base, as an @mention would, when the agent may read it.
- API sync: question_origin in docs/api/chat.md and swagger;
  QuestionOrigin on the Go SDK's KnowledgeQARequest/AgentQARequest and
  knowledge_id on SuggestedQuestion.
2026-09-18 17:00:47 +08:00
lyingbug 9d508c1c7a
feat(frontend): show overall progress for knowledge file uploads (#3399)
* feat(frontend): show overall progress for knowledge file uploads

Batch uploads ran one file at a time with no feedback until the whole
batch finished, and nothing followed the asynchronous parse afterwards.
The knowledge base list still carried a progress panel whose event
emitter was removed with the old menu upload flow, so it never showed.

- Run uploads through a global queue (stores/uploadQueue.ts, wired to
  the API in stores/uploadTasks.ts): three concurrent transfers,
  per-file cancel that aborts the request, retry for failed or
  cancelled files, and polling of the created knowledge rows until
  parsing settles. finalizing counts as searchable.
- Add a floating panel (components/upload-tasks/) mounted in the
  platform shell: stage headline with a progress ring, bytes and ETA
  while uploading, a stacked bar for searchable / in progress / failed /
  duplicate, per-file status with hover actions (cancel, retry, open the
  document), an issues filter, grouping by batch, collapse, a confirm
  before closing mid-upload, and auto-dismiss after a clean finish.
- Warn before unloading the page while transfers are still running.
- Refresh an open knowledge base list as files land (throttled), but
  skip mid-batch reloads while the user has scrolled past the first
  page; the batch's final refresh always runs.
- Remove the orphaned list-page panel, the unused useKnowledgeBase
  requestMethod, the per-batch toasts and the i18n keys they leave
  unused.

* fix(frontend): harden the upload queue's wiring into the app

Review of the upload progress panel found the store misbehaving once
connected to real auth and page events:

- The owner watch used one getter returning a fresh array, so every
  setUser() fired it, even for the same person (opening the user menu,
  hovering the workspace submenu), and dismissed running uploads. Watch
  the user id and tenant id as separate sources.
- Starting a new batch after the previous run finished cleared it
  whole, including failed files still waiting for Retry. Only batches
  whose every file is searchable are dropped now.
- The knowledge base list page reloaded everything on each mid-batch
  refresh (about every 2s), closing open card menus. It now waits for
  the batch's final event; the detail page's mid-batch refreshes only
  reload files and folders, and tags and wiki probes wait for the end.
- A row missing from one successful status poll was marked deleted for
  good. It now takes three consecutive misses, reset when it reappears.
- Closing the panel aborted requests whose body was already sent, which
  the server still stores. Those are left to finish and trigger a list
  refresh when they land.
- Two identical files in one batch could both pass the server's hash
  dedup when uploaded in parallel. Same-size files for one knowledge
  base now never run at once, so the second sees the first's row.

Also: detect cancellation from the abort signal instead of the item
state, ignore a cancelled attempt that settles after its retry started,
bind the beforeunload guard to the panel's lifetime, and show the
subfolder next to file names from folder uploads.

The store body moves into uploadTasksCore.ts with the API, events and
identity injected, so the owner watch and enqueue policy are tested
alongside the queue.
2026-09-18 16:43:59 +08:00
Binks Riverton a9c85fd17e fix(frontend): keep pipeline offsets within chart bounds 2026-09-18 16:42:37 +08:00
wizardchen ad5d6a8fc2 fix(agent): make read_document queries keyword-based and bound its pages
read_document's in-document query was matched as one literal string, so a
keyword query such as "sunflower f(n,k)" found nothing in a 708-chunk
document even when both words were there. The zero-match result gave the
model no next step, and the UI rendered it as "0 / 708 chunks loaded",
which reads like a failed load.

Paging mode also had no size bound: the registry truncates
ToolResult.Output, but the model sees the result rendered from Data, so a
limit=100 page reached ~68k characters in the model context.

- A plain query is split on whitespace; a chunk matches when it contains
  every word, in any order. regex=true still matches one expression.
- A zero-match result carries a <hint> suggesting fewer/different words
  or reading a chunk from search_knowledge results.
- A page stops adding chunks at 80% of the output budget (counting
  per-chunk rendering overhead); next_offset resumes at the first chunk
  not returned, and an oversized first chunk is still returned.
- The UI summary shows in-document search results ("no matches" /
  "N matches") and, for offset paging, the chunk range instead of a page
  number that no longer holds.
2026-09-18 15:09:25 +08:00
Lvcy_cd a8aa19f721 fix(frontend): scale upload timeout with payload size
postUpload inherited the axios instance's 30s default, so any upload taking
longer than 30s was aborted client-side no matter what MAX_FILE_SIZE_MB was
set to. On a ~30 Mbps uplink that caps uploads at roughly 100MB even when the
deployment is configured for 200MB — and every layer underneath (reverse proxy,
frontend nginx, Go handler, docreader gRPC) had already accepted the configured
limit. The server only saw the request after the browser had given up, and
logged "failed to upload file to MinIO: context canceled" with a sub-second
latency.

Four of the five postUpload call sites worked around this by passing an explicit
timeout; knowledge-base file upload and chat temporary attachments did not.
Derive the default from the payload so correct behaviour no longer depends on
each caller remembering to opt in — an explicit config.timeout still wins.

The aborted request also surfaced as "network error, please check your
connection": axios timeouts arrive without error.response, so they landed in
the same branch as an unreachable server and sent people chasing a network
problem that did not exist. Report the two separately.
2026-09-18 15:07:27 +08:00
lyingbug 92e7c0ab37
refactor(agent): consolidate knowledge retrieval tools into search_knowledge, read_document, list_documents (#3381)
* refactor(agent): consolidate knowledge retrieval tools into search_knowledge, read_document, list_documents

The agent's retrieval surface had grown to five overlapping tools whose
behaviour was scattered across long descriptions, interleaved "tips" in
tool output (most of which modelcontext discarded before the model saw
them), and a grep_chunks implementation that ran an unindexed regex scan
over the chunks table ordered by created_at, so large knowledge bases lost
recall and paid a full-table scan on every call.

Tool surface
- search_knowledge replaces knowledge_search and grep_chunks: one query,
  mode = hybrid | semantic | keyword, optional knowledge_base_ids, limit.
  Keyword mode runs through the retrieval engine's keyword index instead of
  the DB regex scan. Modes unavailable for the scope are refused with a
  reason. Rerank, MMR and de-duplication are kept; already_seen markers,
  retrieval_statistics and the zero-result "CRITICAL" block are gone.
- read_document replaces list_knowledge_chunks, get_document_info and
  wiki_read_source_doc: id accepts a dN or cN handle, always returns the
  document header, pages by exact offset (fixing the old floor-to-page
  bug), finds passages with query (literal by default, regex opt-in) and
  reads neighbours around a chunk with context.
- list_documents pages through one knowledge base, honouring @file/@tag
  scope.
- wiki_search takes a single query plus regex, knowledge_base_ids, limit;
  literal queries are escaped so the model never reasons about JSON
  escaping. Legacy queries / knowledge_base_id are still accepted.
- query_knowledge_graph is registered only when a graph-enabled KB is in
  scope and its description/tips were trimmed.

Compatibility
- Retired names in stored allowlists, presets and API calls are mapped to
  their successors by NormalizeAllowedTools at registration time; no data
  migration. Stored histories with old names still decode, render and
  redact. Calls to retired names return a replacement hint.
- modelcontext gains an "id" key space that decodes against both the chunk
  and document handle tables (decode-only), plus rendering for the
  document header, chunk roles, in-document matches and next_offset.

Prompts and surfaces
- The RAG, wiki researcher and hybrid templates now name the tools and the
  search -> read -> cite order; tool descriptions are short and contain no
  workflow instructions.
- Engine display names, history redaction, grounding prompt, IM rendering,
  the built-in MCP server (search_knowledge gains mode/limit, grep_chunks
  becomes keyword search, read_document gains query, wiki_search gains
  regex), frontend editor/renderers/i18n, presets, website docs and the
  changelog are updated accordingly.

Tests cover name mapping, mode validation and refusal, output shape,
read_document paging/context/query/scope, list_documents, wiki_search
escaping and legacy arguments, modelcontext decoding and rendering, and
registration-time aliasing and graph gating.

* fix(agent): address review findings on read_document, list_documents and model rendering

- read_document: fetch the second page whenever the first page did not
  reach the end of the document, so an unaligned window near the end no
  longer drops the trailing chunks (also fixes context windows around a
  chunk near the end); a query passed together with a cN handle now
  searches the owning document instead of being ignored; query mode stops
  collecting once the output budget is nearly spent and reports truncated;
  the document row is authorized in place instead of being fetched twice;
  the context read takes the total from the window fetch instead of a
  separate count query.
- list_documents: resolve the page's document scope in one batched tag
  lookup instead of one call per row.
- modelcontext: render read_document output once and read next_offset
  through the existing intValue helper.
- search_knowledge: point title/file-name lookups at list_documents.
- Tests for the boundary window, chunk context near the end, cN + query,
  and budget-bound query results.

* fix(agent): close compatibility gaps in the consolidated retrieval tools

- Wiki-only scopes: read_document and list_documents are registered
  whenever a wiki KB is in scope, since every KB stores chunks. Their
  capability requirement includes wiki but is marked auxiliary, so they do
  not widen a RAG agent's derived "all knowledge bases" filter to wiki-only
  bases (Go and frontend derivations both honour it).
- search_knowledge resolves the retrieval mode per knowledge base instead
  of refusing the call: FAQ and vector-only bases answer keyword requests
  semantically, keyword-only bases answer semantic requests by keyword.
  Results carry requested_mode and mode_fallbacks, the empty-result text
  names the fallback, and the call is refused only when no base in scope
  has a chunk index.
- The model rendering uses the mode the search actually ran with (it was
  always labelled semantic) and emits <mode_fallback> per degraded base.
- list_documents applies the @file/@tag scope before paging: tags are
  pushed into the database filter, pinned documents are loaded by ID, and
  total/next_page count only readable documents.
- read_document resolves chunk context by chunk_index through a new
  ChunkRepository.ListChunkNeighbors, so parent, summary and image chunks
  sharing the index sequence no longer shift the neighbourhood; offset is
  documented as a reading-order position, not a chunk index.
- wiki_search (agent and MCP) keeps its regular-expression default and
  only matches literally when the text is not a valid expression;
  regex=false forces a literal match and regex=true rejects invalid input.
- MCP grep_chunks keeps grep semantics: literal terms from the pattern
  fetch candidates from the keyword index (semantic for bases without
  one), and every returned chunk is verified against the pattern.

* docs(changelog): align the consolidation entry with regex wiki_search and grep_chunks semantics

* docs(mcp): note that grep_chunks recall is bounded by index candidates
2026-09-18 14:12:22 +08:00
lyingbug 6db8fdd601
feat(artifacts): artifacts library page backed by a message_artifacts table (#3384)
* feat(artifacts): add an artifacts library with its own message_artifacts table

Skill-generated files were only reachable from inside the conversation that
produced them. This adds a sidebar entry and a page that lists them across
every conversation the user can see.

Storage: artifacts move out of the messages.artifacts JSONB column into a new
message_artifacts table (PostgreSQL 000103, SQLite 000023), backfilled on
upgrade. The table is now the only source of truth; the old column is kept and
the down migration writes the table back into it. The message repository
loads artifacts for every message it returns and writes them on create,
update (when non-nil) and fork, so callers still use Message.Artifacts.
mod_time is stored as RFC 3339 text because the collector matches files on
nanosecond mtimes, which PostgreSQL timestamps would truncate.

API: GET /api/v1/artifacts lists the latest version of each file (grouped by
session + source path, with version_count), scoped like the session list,
with keyword / file type filters and paging. Downloads keep using the
per-session endpoint.

Frontend: "产物/Artifacts" sidebar entry (hidden without sandbox support), a
library page with type tabs, search, date groups, infinite loading, preview
drawer, download and jump-to-conversation; strings in all five locales. The
sidebar's top-menu paths are now one shared list.

* fix(artifacts): keep the restore hash guard and count versions by URL

RecordRestoredArtifactMtime again only stamps rows whose content hash matches
the restored content (and ignores empty hashes), and never rewrites the hash,
matching MessageArtifacts.WithRestoredMtime. Without the guard a restore of
v1's content also moved v2's mtime and relabelled v2 with v1's hash.

The library's version_count now counts distinct URLs per (session, source
path). A later answer that references an earlier file stores another row with
the same URL, which COUNT(*) reported as an extra version.

* fix(artifacts): scope the library to web chats and clear the legacy column

The library used the session list's default scope, which counts sessions
without an owner as legacy tenant-level rows. IM sessions are created without
an owner, so every member saw the file names and titles of every IM chat
(downloads then 404 for non-admins). The library now applies the same "web"
bucket predicate as the home sidebar, extracted from QueryPaged so the two
cannot drift: no IM mapping (including cleared ones), no embed marker, no
API-key owner.

Migrations 000103 / SQLite 000023 now clear messages.artifacts after the
backfill. Message loads still SELECT *, so the stale copy was read on every
history load. Only rows that carried artifacts are rewritten; the column stays
for instances on the old binary during a rolling upgrade, and the down
migration still rebuilds it from the table.

* fix(migrations): keep the 000103 backfill alive on malformed artifact JSON

A single file_size that is not an integer ("12.5", "") or a created_at that
does not parse ("garbage", month 13) raised a cast error and failed the whole
migration, blocking startup. Casts now go through pg_temp helpers that return
NULL on bad input, falling back to 0 and the message's created_at; valid rows
are unchanged. SQLite casts never raise; its migration test now covers the
same malformed values.

* docs(artifacts): describe the web-only library scope and the cleared legacy column
2026-09-18 12:10:19 +08:00
lyingbug b4aa5bbe8d
refactor(frontend): style consistency pass — shared shells, tokens, unified confirmations (#3376)
* refactor(frontend): batch 1 of style consistency cleanup

- theme.css: alias --td-font-family-mono to --app-font-family-mono so the
  29 monospace call sites follow the user's code-font setting
- replace 115 hardcoded rgba(7,192,95,x) brand tints with
  color-mix(in srgb, var(--td-brand-color) N%, transparent) so they track
  the dark-mode brand color
- strip 358 dead var(--td-*, fallback) fallbacks (tokens are guaranteed by
  theme.css); keep the 3 undefined tokens untouched
- menu.vue: drop 9 unreferenced style blocks; remove TencentSans font file
  and its global import
- AgentStreamDisplay: drop 6 unused keyframes; move the teleported wiki
  drawer styles into components/css/wiki-graph-drawer.less imported by
  both chat and WikiBrowser so styling no longer depends on load order
- creatChat: remove four !important fixed-width media queries; chat root no
  longer forces font-size: 20px
- list pages: create buttons use native theme="primary" (drops the purple
  gradient on AgentList); header-action-btn no longer needs !important
- add styleGuard.test.mjs ratchet test (brand rgba, legacy blue, token
  fallbacks, z-index !important, raster icons)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* refactor(frontend): unify destructive confirmations on useConfirmDelete

- useConfirmDelete now uses the danger dialog theme with a red confirm
  button; it is the single entry point for delete/leave confirmations
- AgentList, KnowledgeBaseList and OrganizationList drop their hand-rolled
  del-*-dialog (span-as-button, circle.png) in favour of useConfirmDelete;
  circle.png asset removed
- FAQ single-entry delete gains a confirmation (it deleted immediately);
  new knowledgeEditor.faq.confirmDelete key in all five locales
- VectorStore/StorageBackend delete dialogs and the generated-question
  popconfirm use the danger theme like the rest of the app
- style guard raster-icon baseline lowered to 10

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* feat(frontend): shared modal shell with Esc, overlay close and unsaved guard

Add composables/useModalShell and wire it into the four full-screen
settings-style modals (Settings, AgentEditorModal,
OrganizationSettingsModal, KnowledgeBaseEditorModal):

- Esc closes the modal everywhere (previously only Settings); it defers
  to any open TDesign dialog/drawer/popup and to the agent editor's own
  placeholder popups
- overlay click closes everywhere (Settings gains it)
- editors snapshot their form after load/save; closing with unsaved
  changes now asks "有未保存的更改 / 放弃更改 / 继续编辑" instead of
  silently discarding
- new common.unsavedChanges.* keys in all five locales

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(frontend): mark instant-effect sections in the knowledge base editor

Share, data source and activity sections apply changes immediately, but
the editor footer still showed Cancel / Save, so users either re-saved
or assumed Cancel would undo. Those sections now show an "applies
immediately" note with a single Close button; other sections keep the
Cancel / Save footer. New knowledgeEditor.footer.instantEffect key in all
five locales.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* refactor(frontend): consistent success wording and confirm labels (zh-CN)

- toasts use the "已X" form everywhere: 25 zh-CN values such as
  保存成功 / 删除成功 / 智能体创建成功 become 已保存 / 已删除 / 已创建智能体;
  common.copySuccess now reads the same as common.copied
- confirm buttons in dialogs and popconfirms use the bare verb
  (删除 / 重置 / 移除 / 应用 ...) instead of 确认X; dialog titles keep 确认删除
- GeneralSettings no longer pops a bare "成功" toast after theme / font /
  font-size changes, which are self-evident and applied instantly

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* refactor(frontend): extract SettingsModalShell for the four settings-style modals

Settings, AgentEditorModal, OrganizationSettingsModal and
KnowledgeBaseEditorModal each carried a copy of the same overlay / panel /
sidebar-nav / footer markup and ~20 CSS blocks, already drifting
(1000/1080/1100px widths, three shadows, different nav paddings).

components/SettingsModalShell.vue now owns that chrome: one 1080x780
panel, grouped nav with badges, optional loading overlay, footer with a
note slot and an actions slot. Consumers keep only their content and
wire `@close` to their useModalShell.requestClose. Settings keeps its
sub-menu nav through the `nav` slot; OrganizationSettingsModal keeps its
image icon through the `nav-icon` slot.

Net: -1025 lines across the four modals.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* refactor(frontend): shared resource-card mixins and EmptyState for list pages

KnowledgeBaseList, AgentList and OrganizationList each re-declared the
same 136px card (border, radius, shadow, hover, header/title/description/
bottom, more-button reveal, feature badges) with small drifts, plus a
copy of the empty-state block using the upload illustration for every
kind of emptiness.

- components/css/resource-card.less: .resource-card(),
  .resource-card-grid() and .resource-feature-badge() mixins; the pages
  keep only their own variants (type gradients, favourite star,
  decoration). More-buttons stay visible on touch devices.
- components/EmptyState.vue: icon / title / description / actions; the
  11 empty states now use a matching TDesign icon instead of upload.svg
- badge accent colours move from hard-coded old-blue / material orange /
  pink / slate rgba to color-mix over theme tokens (new
  --app-accent-purple in theme.css); style guard legacy-blue baseline
  drops from 40 to 18

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* refactor(frontend): shared settings-section mixins for header, row, info, control

25 settings/system/integration pages each re-declared .section-header,
.setting-row, .setting-info and .setting-control with five different
header margins (18-32px), three description sizes and assorted paddings.
components/css/settings-section.less now provides
.settings-section-header() / .setting-row() / .setting-info() /
.setting-control() / .setting-save-state(); pages keep only their
deliberate deviations (e.g. Ollama's column control, TenantInfo's fixed
label column). PlatformAPIKeys' style block switches to less so it can
use the mixins. Net -570 lines.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* refactor(frontend): provider-card mixins, dark-safe vendor badges, one spin keyframe

- components/css/provider-card.less: .provider-card() /
  -interactive() / -add() / -badge() / -badge-color() / -body() /
  -header() / -title() / -subtitle() / -more() shared by the model,
  vector store, web search, storage, parser and sandbox settings cards;
  MCP and skill cards reuse the 26px badge variant
- vendor badge colours are now `.provider-card-badge-color(#hex)`: the
  foreground is mixed 75/25 with the text colour so it stays readable in
  dark mode, the background is the same colour at 12% alpha
- 18 copies of a rotate-360 keyframe (steer-spin, chat-header-spin,
  sandbox-terminal-spin, ...) collapse into a global `wk-spin` in
  theme.css; 23 files updated, one source test adjusted

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* refactor(frontend): use TDesign password toggle for API keys; align chat toolbar buttons

- ModelEditorDialog: the API key field is a plain t-input type="password"
  and relies on TDesign's built-in show/hide eye instead of a hand-rolled
  suffix toggle, matching every other secret field in the app
- chat answer toolbar buttons are 28px with 6px radius, the same size as
  the user-message actions and the input control bar

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* refactor(frontend): app design tokens, tokenized literals, global TDesign overrides

theme.css gains an app-level token set derived from the de-facto scale
already used in the codebase, so values do not change:
  --app-radius-{xs,sm,md,lg,xl,pill} (4/6/8/10/12/999px)
  --app-text-{2xs..4xl}              (10..24px)
  --app-space-{1..10}                (4px grid)
  --app-motion-{instant,fast,base,slow} (120/150/200/300ms)
  --z-{sticky,dropdown,modal,drawer,popover,toast}

A codemod mapped 675 border-radius, 1904 font-size and 551 transition
duration literals in 191 files onto those tokens (value-preserving; five
source-text tests now accept either form).

assets/theme/tdesign-overrides.less holds global-intent TDesign
overrides; its `.wk-popover` skin replaces six per-file copies of the
blurred popover panel (TenantMembers x2, UserProfile,
OrganizationSettingsModal, systemAdminDialog.less,
share-to-space-panel.overlay.less) without !important.

styleGuard ratchets now also cover radius / font-size / motion literals,
`transition: all`, total `!important` and z-index !important.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(frontend): keep symmetric side insets for the chat column on narrow viewports

.chat had padding 0 0 20px 20px so the scrollbar could sit on the content
edge, but that also left the message list and input box flush against the
right edge whenever the viewport was narrower than 960px + sidebar. The
inset now lives on .msg_list and .input-container (--chat-content-inset,
20px each side, max-width 960px + insets); the scroll container still
spans the full column so the scrollbar stays on the edge. Wide layouts are
unchanged (960px content, centered).

* chore(frontend): strip trailing whitespace flagged by pre-push

* test(frontend): accept tokenized font-size and shell-rendered loading overlay

Two source-text assertions only ran in CI (Node 24 discovers .test.ts,
local Node 20 does not):
- ChatQuestionMinimap: the 13px preview font is now var(--app-text-md)
- modelUsageDetails: the editors' loading overlay is rendered by
  SettingsModalShell via :loading instead of an inline v-if
Both regexes now accept either form.

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-17 23:11:08 +08:00
wizardchen 8b1a64004d feat(mcp): show the endpoint token as the drawer's second step
The "endpoint ready, save the token" dialog stacked the token, the URL and
three client snippets into one tall modal on top of the drawer. The drawer
now has two steps like the embed and IM channel drawers: "Configure" and
"Connect". Creating an endpoint advances to the Connect step in place, where
the one-time token, the endpoint URL and the client snippets (in tabs, one
visible at a time) are read; Finish closes the drawer. Rotating a token and
the card's "Connection info" action open the same step, the latter with the
token placeholder. The separate dialog and the "show client configuration"
button are gone.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-17 22:51:25 +08:00
lyingbug 76a19f14c4
feat(mcp): add built-in MCP server with per-workspace endpoints (#3371)
* feat(mcp): add built-in MCP server with per-workspace endpoints

WeKnora previously exposed itself to MCP clients only through the Python
package under mcp-server/, which binds one process to one API key and
therefore to one workspace, and mirrors the REST API tool-for-tool.

This adds a native MCP server surface to the Go backend:

- New mcp_endpoints table (PostgreSQL 000100, SQLite 000020). A workspace
  can publish any number of endpoints, each with its own bearer token
  (SHA-256 stored, rotatable, shown once), knowledge-base allowlist, tool
  allowlist, default agent and per-minute rate limit.
- Management API under /api/v1/mcp-endpoints (Viewer reads, Admin writes,
  API keys need manage_channels) plus a tool catalog endpoint.
- internal/mcpserver hosts one mcp-go Streamable HTTP server in stateless
  mode at /mcp/:endpoint_id. tools/list is filtered per endpoint and
  tools/call re-checks the allowlist, applies rate limiting and touches
  last_used_at. MCPEndpointAuth resolves the token and injects the
  workspace, an mcp_endpoint principal and an API-key style scope derived
  from the endpoint, so existing knowledge-base and capability checks
  apply unchanged.
- Redesigned tool set (12 tools in four groups): retrieval and reading
  reuse the agent's native tools; ask runs the default or a named agent
  synchronously and returns a cited answer with a session_id for
  follow-ups; wiki tools cover search, read and index; write tools are
  off by default. Knowledge bases accept ids or names.
- Frontend: new "MCP Server" integrations tab (tab id mcpserver, to
  avoid clashing with the existing MCP-client settings section) with
  endpoint cards, a create/edit drawer, a one-time token dialog and
  ready-to-paste snippets for Cursor/VS Code/Claude Desktop, Claude Code
  and mcp-remote. Locales updated in all five languages.
- Deployment capability integrations.mcpserver wired on both sides.
- Docs: website-docs MCP page now leads with the built-in server; the
  Python mcp-server README carries a deprecation notice.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(mcp): wire the MCP server into DI/router and tighten authorization

The previous commit lost eight staged files to the repo pre-commit hook,
which resolves ROOT to the main checkout and re-adds the main-checkout
copies of tracked files into the worktree index. This commit restores them
(container providers, RouterParams and route registration, context key,
principal, clone table entry, deployment capability key, SQLite parity
test) and addresses the review findings:

- Knowledge-base scope is authorized, not trusted: endpoint allowlists and
  every tool call resolve each knowledge base through access.ResolveKB for
  the calling principal (ownership or organization share). Foreign IDs are
  rejected on create/update and dropped at call time.
- Write tools mint explicit editor grants via access.KBAccess.WithGrant
  before calling the knowledge service, so add/update/delete go through the
  same RequireKBWrite path as the REST API. add_document also checks the
  grant itself.
- ask no longer accepts agent_id. It runs only the endpoint's configured
  agent; tenant-owned agents and user-facing builtins qualify, internal
  builtins (wiki fixer, skill installer) are refused both on save and at
  call time. Web search is forced off for MCP calls.
- Tool annotations match behaviour: ask is not read-only, add_document is
  a mutation.
- CORS allows MCP-Protocol-Version / Mcp-Session-Id / Last-Event-ID and
  exposes Mcp-Session-Id for browser-based MCP clients.
- Rate limiter runs its local cleanup goroutine; SQLite migration gains the
  deleted_at index for parity with PostgreSQL; non-ASCII endpoint names get
  unique mcpServers keys derived from the endpoint id.
- Swagger annotations on the management handler.
- Tests: KB isolation (service and server), write grants, endpoint-agent
  restriction, tool annotations, and a router test that mounts the public
  /mcp/:endpoint_id surface and checks the deployment capability.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* chore(mcp): renumber migrations after rebase onto main

main took 000100 / 000020 for chunks_index_diet, so the mcp_endpoints
migrations move to 000101 (PostgreSQL) and 000021 (SQLite); the SQLite
parity test and docs follow.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(mcp): run document tools under the knowledge base owner tenant

Shared knowledge bases resolved through access.ResolveKB were only half
usable: documents of an organization-shared knowledge base are stored under
the owner tenant, so the document-level tools that queried by the calling
tenant found nothing, and add_document would have created rows under the
caller's tenant inside someone else's knowledge base.

- knowledgeInScope loads documents tenant-agnostically and then requires
  the document to belong to an allowed knowledge base and to that base's
  tenant.
- scopedKBContext replaces grantContext: it resolves the grant, switches
  the execution tenant to the knowledge base owner (KBAccess.Context) and
  swaps TenantInfo to the owner so storage/model settings resolve there.
  list_documents, read_document and every write tool run under it.
- Locale text and docs no longer claim clients can pass agent_id.
- Go SDK gains MCP endpoint methods (client/mcp_endpoint.go) with docs, and
  the Swagger artifacts are regenerated.
- Tests: shared knowledge base read/write under the owner tenant, spoofed
  document tenant rejected, viewer share cannot write.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* chore(mcp): renumber migrations after rebase onto main

main now carries 000101 / 000021 (knowledge_profiles), so the
mcp_endpoints migrations move to 000102 (PostgreSQL) and 000022 (SQLite);
the SQLite parity test expects version 22 and the docs follow.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(mcp): guard last_used touch without a repository and wrap SDK line

The transport tests build the server without a repository; the background
last_used_at write then dereferenced a nil interface and, on the slower CI
runner, took the test binary down. touchLastUsed now returns early when no
repository is wired, and the tests inject a recording repository and assert
the touch instead. Also wraps a 123-column SDK signature for the client
module's lll check.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-17 22:40:05 +08:00
lyingbug 5574ebc011
feat(knowledge): derive knowledge base descriptions from document profiles (#3370)
* feat(knowledge): derive knowledge base descriptions from document profiles

Knowledge bases only had a hand-written description, which most users
leave empty, so agents bound to several knowledge bases had nothing to
route on and searched all of them. This adds a generated description
that is derived from per-document data instead of maintained by a model.

Document profile: the summary call now returns JSON with a 2-3 sentence
summary plus a gist, 3-5 topic keywords, a document type and one
typical question (knowledges.profile). Input is capped at 8k chars and
output at 1024 tokens; plain-text replies from custom templates still
work and simply carry no profile. The summary chunk embeds the gist and
short summary.

Knowledge base aggregate: a database-only fold over those rows (counts
per file type, tag, normalized topic and doc type; stratified samples of
titles and questions; a hash of the inputs). Deleting, moving or
re-parsing a document changes nothing but the rows, so the next rebuild
is exact without any model judgement.

Description text: one small model call over the aggregate yields a
gist, merged topics and typical questions (knowledge_bases.
generated_profile). The call is skipped when the aggregate hash is
unchanged; failures keep the previous text and record the error; an
empty knowledge base clears it. The manual description is never
touched, and the agent runtime context renders both so the model can
pass knowledge_base_ids instead of fanning out.

Refreshes are requested from summary task exit, post-process completion,
deletion, cross-KB moves and enabling the option, debounced per
knowledge base in 30 s windows via kb:profile on the summary queue.
POST /knowledge-bases/:id/profile/generate regenerates synchronously.
profile_config (enabled, model_id, custom_instructions) opts a document
knowledge base in; the settings dialog shows the generated card with
regenerate and adopt-as-description actions in five locales. Search
results now log hits per chunk type so the value of indexing summary
chunks can be measured.

Migrations 000101 (PostgreSQL) and 000021 (SQLite) add the columns; the
SQLite schema test expects the new version and columns.

* fix(knowledge): keep generated descriptions out of duplicates and refresh clones

DuplicateKnowledgeBase copies the source row through JSON, which carried
generated_profile onto a knowledge base that has no documents yet, so
an empty duplicate advertised the source's topics. The duplicate now
starts without a generated description and keeps profile_config so it
derives its own once documents arrive.

CopyKnowledgeBase builds the target field by field and skipped
profile_config, and the clone task never asked for a description after
copying the documents, so a clone stayed undescribed until its next
upload. The target now carries a copy of profile_config and both clone
paths request a refresh on completion.

* fix(knowledge): refresh the loaded clone target and carry document profiles

ProcessKBClone requested the description refresh with the reservation
stub it builds before CopyKnowledgeBase runs. For the main create path
that stub has neither a type nor profile_config, so the refresh helper
rejected it and nothing was enqueued. The refresh now uses the loaded
target returned by CopyKnowledgeBase.

cloneKnowledge copied the summary text but not the structured profile,
so even a scheduled refresh would have aggregated titles without topics
until every clone was re-summarized. Cloned documents now carry an
independent copy of the profile.
2026-09-17 22:21:55 +08:00
wizardchen 105c177b80 feat(knowledge): make document summary generation optional 2026-09-17 19:39:52 +08:00
wizardchen 559ad532ae refactor(frontend): consolidate knowledge tag filters and remove stale styles 2026-09-17 16:46:27 +08:00
wizardchen d645334d08 refactor(frontend): share citation popover lifecycle 2026-09-17 15:28:31 +08:00
wizardchen 8fbee673e6 fix(browser): soften handoff UI and prevent preview overlay flicker 2026-09-17 14:51:20 +08:00
wizardchen b3d3851ca1 fix(chat): refine fork feedback and user message actions 2026-09-17 14:50:45 +08:00
nullptr-error 42e6163981
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries

为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。

* feat(sandbox): add git, fork snapshots, and bootstrap hook

沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。

* feat(session): checkpoint workspace at the end of each turn

每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。

* feat(session): fork conversations and reap orphan snapshots

支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。

* feat(chat): add session fork entry, prefill, and badges

在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。

* style: add missing newline so session_fork_delete_test.go is gofmt-clean

* fix(session): prune later git history when rolling a fork workspace back

reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。

* style(session): clear golangci-lint findings on the session-fork diff

Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.

* fix(chat): show the fork button on hover without shifting the thread

Overlay the action so revealing it no longer expands the user bubble and janks the messages below.

* fix(chat): drop the fork landing banners

Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.

* fix(agent): dedupe artifacts by content hash, not size

Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.

* feat(session): allow forking from an assistant answer

User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.

* fix(session): resolve parent attachments from a forked chat

Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.

* fix(agent): rewrite sandbox refs after a content-hash skip

Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.

* fix(session): drop a dead fork snapshot and retry checkpoint rewrite

Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.

* fix(session): load forked parent attachments into the prompt

ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.

* fix(chat): keep the user-message fork button visible

The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.

---------

Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 14:20:18 +08:00
serply e80f5dfbc7 feat(web-search): add Serply provider
Serply returns Google results through a keyed JSON API, which fills the
gap between Google Custom Search (needs an engine ID and a restricted
scope) and the scrapers. The adapter follows brave.go: hardcoded
endpoint, redirects refused so the key never leaves the official host,
4MB response cap, and per-call country and freshness filters. country
maps to Google's gl parameter and pd/pw/pm/py map to tbs qdr:d/w/m/y.
Serply has no date-range filter, so that form returns an error instead
of being silently dropped. num is clamped to 10 because the API serves
one results page per call.

Wiring matches the Bocha provider: type constant and metadata, registry
factory, service validation, frontend union, swagger enum entries (edited
by hand; a full swag regen drags in unrelated drift), and the web search
docs table.
2026-09-17 12:25:09 +08:00
wizardchen 84c9871d16 fix(browser): align BrowserSkill 0.3.0 and repair task lifecycle 2026-09-17 11:54:12 +08:00
wizardchen f2606629b3 refactor(frontend): share skill install progress subscriptions 2026-09-16 23:12:14 +08:00
wizardchen 5bcc43d728 refactor(frontend): share skill installer model configuration 2026-09-16 20:58:03 +08:00
wizardchen bfa7f0ed69 refactor(frontend): remove unused components and share tag selection logic 2026-09-16 20:49:16 +08:00
lyingbug d7ccd5ba51
fix: align client sessions and integration request handling (#3305)
* fix: align client sessions and integration request handling

* fix: preserve trusted Doris redirects and prepare browser tests

* fix: align proxy address checks and integration test coverage
2026-09-16 16:20:57 +08:00
ttommybot a7d3545297
feat(knowledge): add batch file downloads (#3300)
* feat(knowledge): add batch file downloads

* fix(knowledge): harden batch file downloads

Skip entries without original files, keep folder paths in the ZIP, map
client cancel to 400, and cap concurrent archives so a full-select
download is usable without 500s or disk pile-up.

* fix(knowledge): format batch-download tests for pre-push lint

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-16 15:40:10 +08:00
jacentsao 01f0700b35
feat(datasource): add Confluence sync (#3287)
* feat(datasource): add Confluence sync

* fix(confluence): resume full sync and list Server pages without CQL

CQL search silently truncates large spaces and can delete pages that
dropped out of the index. Full-sync checkpoints now keep a deletion
baseline so Asynq retries continue instead of restarting.

* fix(confluence): satisfy package lint for pre-push against main

* fix(confluence): parse Server page lists and keep version expand

The default Server/DC edition unmarshaled /content/page as a nested
envelope, so sync imported zero pages. Pagination next links also drop
expand=version,space, which made later pages versionless and hid edits.

* fix(confluence): classify errors and fail closed on empty listings

Raw Confluence error bodies were copied into sync-log UI, and pagination
next links could leave the configured context path via `..`. Empty
listings against a non-empty baseline now abort instead of deleting.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-16 14:38:16 +08:00