feat(settings): bind internal/external knowledge bases from the UI

Routing targets move from env-only to a UI-managed binding (migration
000034 routing_kb_bindings, single active row):
- GET/PUT /api/v1/routing-bindings + /options: env defaults act as the
  bootstrap fallback; a UI binding wins and takes effect immediately
  (per-request resolution, no restart), and clearing falls back to env
- PUT validates against the connected WeKnora instance (real knowledge
  base list via the scoped API key) and rejects same-KB bindings;
  saves require the admin role
- route/catalog capabilities now resolve through the binding so both
  annotation paths share one source of truth
- system settings > 服务配置 gains a 知识库绑定 panel: dropdown picker
  (or raw ID when WeKnora is unreachable) showing bound name, origin
  (UI vs env default) and last author
- contract tests: OpenAPI, handler matrix (fallback, validation,
  same-KB rejection, capability resolution), frontend fetch/save layer
This commit is contained in:
姚章浩
2026-09-14 14:45:35 +08:00
parent 4c86c5e659
commit 021e91eae4
17 changed files with 676 additions and 13 deletions
@@ -0,0 +1 @@
DROP TABLE IF EXISTS routing_kb_bindings;
@@ -0,0 +1,14 @@
-- Policy-driven ingestion, step 3: routable knowledge-base bindings move from
-- environment-only configuration into the UI. A single row stores which
-- WeKnora knowledge base receives 对内 and which receives 对外 annotations.
-- The env-supplied defaults stay as a bootstrap fallback only.
CREATE TABLE routing_kb_bindings (
id TEXT PRIMARY KEY DEFAULT 'active' CHECK (id = 'active'),
internal_kb_id VARCHAR(64) NOT NULL DEFAULT '',
external_kb_id VARCHAR(64) NOT NULL DEFAULT '',
updated_by VARCHAR(64) NOT NULL DEFAULT '',
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
INSERT INTO routing_kb_bindings(id,internal_kb_id,external_kb_id,updated_by)
VALUES('active','','','system:migration');