WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/accesspolicy"
|
||||
apperrors "github.com/Tencent/WeKnora/internal/errors"
|
||||
"github.com/Tencent/WeKnora/internal/im"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
func (s *sessionService) prepareQAAgentExecution(ctx context.Context, req *types.QARequest) (context.Context, error) {
|
||||
if req.CustomAgent == nil || s.customAgentService == nil {
|
||||
return ctx, nil
|
||||
}
|
||||
provider, ok := s.customAgentService.(interface {
|
||||
PrepareAgentExecutionContext(context.Context, string) (context.Context, error)
|
||||
})
|
||||
if !ok {
|
||||
return ctx, apperrors.NewForbiddenError("Agent 执行授权校验不可用,请稍后重试")
|
||||
}
|
||||
agent := req.CustomAgent
|
||||
executionCtx := ctx
|
||||
if req.SharedAgentReadOnly {
|
||||
if req.Session == nil || req.Session.TenantID == 0 || s.agentShareService == nil {
|
||||
return ctx, apperrors.NewForbiddenError("共享 Agent 已失效或无权使用")
|
||||
}
|
||||
// The request handler already selected the source workspace. Recheck
|
||||
// its organization share before granting that exact Agent execution.
|
||||
shared, err := s.agentShareService.GetSharedAgentForTenant(ctx, req.Session.TenantID, types.TenantRoleFromContext(ctx), agent.ID, agent.TenantID)
|
||||
if err != nil || shared == nil || shared.ID != agent.ID || shared.TenantID != agent.TenantID {
|
||||
return ctx, apperrors.NewForbiddenError("共享 Agent 已失效或无权使用")
|
||||
}
|
||||
executionCtx = accesspolicy.WithExecutionDependency(ctx, shared.TenantID, "agents", shared.ID, shared.CreatedBy)
|
||||
} else if im.IsVerifiedAgentExecution(ctx, agent) {
|
||||
executionCtx = accesspolicy.WithExecutionDependency(ctx, agent.TenantID, "agents", agent.ID, agent.CreatedBy)
|
||||
}
|
||||
prepared, err := provider.PrepareAgentExecutionContext(executionCtx, agent.ID)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
current, err := s.customAgentService.GetAgentByID(prepared, agent.ID)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
if current == nil || current.TenantID != agent.TenantID {
|
||||
return ctx, apperrors.NewForbiddenError("Agent 已删除或无权使用")
|
||||
}
|
||||
req.CustomAgent = current
|
||||
return prepared, nil
|
||||
}
|
||||
Reference in New Issue
Block a user