Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
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
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (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 & 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
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (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
Helm / chart (push) Canceled after 0s
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名) - 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块) - docreader proto 描述符采用等长替换,保持序列化字节布局有效 - Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像 - 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
101 lines
3.3 KiB
Go
101 lines
3.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"academy/internal/errors"
|
|
"academy/internal/logger"
|
|
"academy/internal/types"
|
|
"academy/internal/types/interfaces"
|
|
)
|
|
|
|
// WithGrants lets the handler list and revoke the caller's agent grants.
|
|
func (h *MCPServiceHandler) WithGrants(grants interfaces.AgentGrantRepository) *MCPServiceHandler {
|
|
h.grants = grants
|
|
return h
|
|
}
|
|
|
|
// grantOwner is the caller as grants record it.
|
|
func grantOwner(c *gin.Context) (uint64, string, bool) {
|
|
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
|
principal, _ := types.PrincipalFromContext(c.Request.Context())
|
|
userID := principal.StorageID()
|
|
return tenantID, userID, tenantID != 0 && strings.TrimSpace(userID) != ""
|
|
}
|
|
|
|
// ListAgentGrants godoc
|
|
// @Summary 列出会话内的 Agent 授权
|
|
// @Description 列出当前用户在某个会话(根会话)中通过“本会话允许”记住的授权,包括其委派子任务上批准的授权。
|
|
// @Tags Agent
|
|
// @Produce json
|
|
// @Param session_id query string true "根会话 ID"
|
|
// @Success 200 {object} map[string]interface{} "授权列表"
|
|
// @Failure 400 {object} errors.AppError "请求参数错误"
|
|
// @Security Bearer
|
|
// @Router /agent/grants [get]
|
|
func (h *MCPServiceHandler) ListAgentGrants(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
if h.grants == nil {
|
|
_ = c.Error(errors.NewInternalServerError("agent grants are not configured"))
|
|
return
|
|
}
|
|
tenantID, userID, ok := grantOwner(c)
|
|
if !ok {
|
|
_ = c.Error(errors.NewUnauthorizedError("a signed-in user is required"))
|
|
return
|
|
}
|
|
sessionID := strings.TrimSpace(c.Query("session_id"))
|
|
if sessionID == "" {
|
|
_ = c.Error(errors.NewBadRequestError("session_id is required"))
|
|
return
|
|
}
|
|
grants, err := h.grants.ListGrants(ctx, tenantID, userID, types.AgentGrantScopeSession, sessionID)
|
|
if err != nil {
|
|
logger.ErrorWithFields(ctx, err, map[string]interface{}{"session_id": sessionID})
|
|
_ = c.Error(errors.NewInternalServerError(err.Error()))
|
|
return
|
|
}
|
|
if grants == nil {
|
|
grants = []*types.AgentGrant{}
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": grants})
|
|
}
|
|
|
|
// RevokeAgentGrant godoc
|
|
// @Summary 撤销 Agent 授权
|
|
// @Description 撤销当前用户的一条授权;之后同类调用会重新询问。
|
|
// @Tags Agent
|
|
// @Produce json
|
|
// @Param id path string true "授权 ID"
|
|
// @Success 200 {object} map[string]interface{} "撤销结果"
|
|
// @Failure 404 {object} errors.AppError "授权不存在"
|
|
// @Security Bearer
|
|
// @Router /agent/grants/{id} [delete]
|
|
func (h *MCPServiceHandler) RevokeAgentGrant(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
if h.grants == nil {
|
|
_ = c.Error(errors.NewInternalServerError("agent grants are not configured"))
|
|
return
|
|
}
|
|
tenantID, userID, ok := grantOwner(c)
|
|
if !ok {
|
|
_ = c.Error(errors.NewUnauthorizedError("a signed-in user is required"))
|
|
return
|
|
}
|
|
revoked, err := h.grants.RevokeGrant(ctx, tenantID, userID, c.Param("id"), time.Now())
|
|
if err != nil {
|
|
logger.ErrorWithFields(ctx, err, nil)
|
|
_ = c.Error(errors.NewInternalServerError(err.Error()))
|
|
return
|
|
}
|
|
if !revoked {
|
|
_ = c.Error(errors.NewNotFoundError("grant not found"))
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true})
|
|
}
|