feat: expose KB ↔ vector store binding in list, editor, and detail UI

Backend
-------
ListKnowledgeBases now enriches each row with the resolved vector_store
metadata (name / source / engine_type / status) via a new
buildKBListResponse helper. Store views are batch-resolved once per
request through BatchResolveStoreView so an N-KB list costs one
vector-store service call rather than N — closing the N+1 limitation
flagged in #1372's known-limitations section. Cross-tenant shared KBs
continue to render via SharedStoreDisplay so the owning tenant's store
inventory cannot be correlated across rows; the underlying vector_store_id
UUID is stripped from those responses.

Resolver failures degrade gracefully: bound KBs render as unavailable
instead of breaking the list. Test coverage pins the env / bound /
shared distinction, the batch-call-count invariant, and the
graceful-failure path.

Frontend
--------
KB editor modal gains a new "Vector Store" section. Create mode shows a
dropdown that combines the system default (env store) and the tenant's
configured user stores, fetched once at mount via the existing
listVectorStores API. Edit mode shows the bound store read-only via a
new VectorStoreBadge component with an explicit immutability hint —
matching the backend's `<-:create` GORM tag and the service-layer
UpdateKnowledgeBaseRequest DTO that already omit the field.

KB list cards surface a small engine-type badge for own-tenant bound
KBs, and a warning badge when the bound store is unavailable. Env-bound
and shared KBs render no badge (visual noise control). KB detail header
shows the bound store via the same VectorStoreBadge component; shared
KBs fall through to the badge's internal "shared" branch with no name /
engine / id rendered.

The KB editor's create-time error handler translates the typed
ErrVectorStoreBindingInvalid (2200) and ErrVectorStoreUnavailable
(2201) into localized messages and jumps the user back to the
VectorStore section so they can pick a different store or fall back to
the system default.

The KB row type gains five optional fields (vector_store_id / name /
engine_type / source / status). i18n: 18 new keys added to en-US,
ko-KR, zh-CN; ru-RU receives English placeholders pending translation
(consistent with prior PRs in this locale).

Part of #993 (Phase 2: Per-KB VectorStore Binding).
Phase 2 roadmap item: PR 5 (KB binding UI + list-response enrichment).
Depends on #994, #1310, #1372, #1386 (all backend in the Phase 2 series).
This commit is contained in:
ochan.kwon
2026-05-18 23:50:09 +09:00
committed by lyingbug
parent 0f57bf3ff8
commit 8b7d00b260
15 changed files with 1165 additions and 12 deletions
+33 -3
View File
@@ -1304,10 +1304,21 @@ func (h *OrganizationHandler) ListSharedKnowledgeBases(c *gin.Context) {
return
}
// Each row goes through sharedKBRow so the embedded KnowledgeBase
// payload runs SharedStoreDisplay() before serialization. This is
// the cross-tenant strip path: callers never receive the owning
// tenant's vector_store_id, vector_store_name, or
// vector_store_engine_type from the share endpoints. The share
// metadata (share_id, organization_id, etc.) is preserved as-is.
rows := make([]map[string]interface{}, 0, len(sharedKBs))
for _, info := range sharedKBs {
rows = append(rows, sharedKBRow(info, nil))
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"data": sharedKBs,
"total": len(sharedKBs),
"data": rows,
"total": len(rows),
})
}
@@ -1639,7 +1650,26 @@ func (h *OrganizationHandler) ListOrganizationSharedKnowledgeBases(c *gin.Contex
c.Error(apperrors.NewInternalServerError("Failed to list shared knowledge bases"))
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": list, "total": len(list)})
// Project each row through sharedKBRow so cross-tenant strip applies
// uniformly across the space view as well. is_mine and the optional
// source_from_agent payload are passed through as extras so the
// frontend can keep its current rendering branches. Rows where
// is_mine is true are still strip-projected here — callers see the
// rich view of their own bindings on the regular KB list / detail
// endpoints, so dropping the owner-side enrichment from the space
// view trades a small UI nicety for a strictly simpler invariant
// ("share endpoints never leak vector-store metadata").
rows := make([]map[string]interface{}, 0, len(list))
for _, item := range list {
extras := map[string]interface{}{"is_mine": item.IsMine}
if item.SourceFromAgent != nil {
extras["source_from_agent"] = item.SourceFromAgent
}
rows = append(rows, sharedKBRow(&item.SharedKnowledgeBaseInfo, extras))
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": rows, "total": len(rows)})
}
// ListOrganizationSharedAgents lists all agents in the given organization (including those shared by the current tenant), for the list page when a space is selected.