feat: harden support, localize knowledge and add operator availability [skip ci]

Source-only publication of reviewed commit 64e96a7f423673dc29ad56485be9fc79bce8af1c.

Passed in isolation: focused frontend/backend tests, race checks, TypeScript typecheck, lint, Go compilation, Flowgram build, and deterministic SDK build/tests.

Not accepted as a production release: Next.js export/native assembly remains blocked by environment memory limits; browser interaction and MySQL staging acceptance remain unverified. No production server, database/schema, runtime configuration, deployment, release tag, or workflow execution was performed.

Expected source tree: 0a4a7528e9.
This commit is contained in:
2026-10-16 15:21:42 +00:00
parent 299ea50fb5
commit 2f7a491666
176 changed files with 11869 additions and 2716 deletions

View File

@@ -1,15 +1,18 @@
// Modified in the independent AgentDesk fork: localized knowledge workflows and safe display errors.
package dashboard
import (
"agent-desk/internal/pkg/httpx"
"context"
"errors"
"agent-desk/internal/ai/rag"
"agent-desk/internal/pkg/constants"
"agent-desk/internal/pkg/dto/request"
"agent-desk/internal/services"
"agent-desk/internal/pkg/errorsx"
"agent-desk/internal/pkg/httpx"
"agent-desk/internal/pkg/httpx/params"
"agent-desk/internal/pkg/i18nx"
"agent-desk/internal/services"
"github.com/gin-gonic/gin"
)
@@ -26,9 +29,9 @@ func KnowledgeRetrievePostDebugSearch(ctx *gin.Context) {
return
}
resp, err := rag.Answer.DebugSearch(context.Background(), req)
resp, err := rag.Answer.DebugSearch(knowledgeRequestContext(ctx), req)
if err != nil {
httpx.WriteJSON(ctx, err)
httpx.WriteJSON(ctx, safeKnowledgeOperationError(err, "error.knowledge.retrieveFailed"))
return
}
httpx.WriteJSON(ctx, resp)
@@ -47,9 +50,9 @@ func KnowledgeRetrievePostDebugAnswer(ctx *gin.Context) {
return
}
resp, err := rag.Answer.DebugAnswer(context.Background(), req, operator)
resp, err := rag.Answer.DebugAnswer(knowledgeRequestContext(ctx), req, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
httpx.WriteJSON(ctx, safeKnowledgeOperationError(err, "error.knowledge.retrieveFailed"))
return
}
httpx.WriteJSON(ctx, resp)
@@ -70,8 +73,8 @@ func KnowledgeRetrievePostBuild(ctx *gin.Context) {
httpx.WriteJSON(ctx, err)
return
}
if err := rag.Answer.BuildDocumentIndex(context.Background(), req.DocumentID); err != nil {
httpx.WriteJSON(ctx, err)
if err := rag.Answer.BuildDocumentIndex(knowledgeRequestContext(ctx), req.DocumentID); err != nil {
httpx.WriteJSON(ctx, safeKnowledgeOperationError(err, "error.knowledge.indexFailed"))
return
}
httpx.WriteJSON(ctx, nil)
@@ -83,8 +86,8 @@ func KnowledgeRetrievePostBuild(ctx *gin.Context) {
httpx.WriteJSON(ctx, err)
return
}
if err := rag.Index.IndexFAQByID(context.Background(), req.FAQID); err != nil {
httpx.WriteJSON(ctx, err)
if err := rag.Index.IndexFAQByID(knowledgeRequestContext(ctx), req.FAQID); err != nil {
httpx.WriteJSON(ctx, safeKnowledgeOperationError(err, "error.knowledge.indexFailed"))
return
}
httpx.WriteJSON(ctx, nil)
@@ -93,3 +96,29 @@ func KnowledgeRetrievePostBuild(ctx *gin.Context) {
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0066"))
}
func knowledgeRequestContext(ctx *gin.Context) context.Context {
parent := context.Background()
if ctx != nil && ctx.Request != nil {
parent = ctx.Request.Context()
}
return i18nx.WithLocale(parent, i18nx.Locale(ctx))
}
// Only catalog-owned errors without arbitrary diagnostic arguments are safe to
// return from index/embedding/vector providers. Unwrap the application error so
// a surrounding SQL/provider message never reaches the response.
func safeKnowledgeOperationError(err error, fallbackKey string) error {
if err == nil {
return nil
}
var appErr *errorsx.I18nError
if errors.As(err, &appErr) && appErr != nil && len(appErr.Args) == 0 && i18nx.Get(appErr.Key) != appErr.Key {
return appErr
}
var localizedErr *i18nx.Error
if errors.As(err, &localizedErr) && localizedErr != nil && len(localizedErr.Args) == 0 && i18nx.Get(localizedErr.Key) != localizedErr.Key {
return i18nx.Errorf(localizedErr.Key)
}
return errorsx.BusinessErrorI18n(0, fallbackKey)
}