Files
runny 9058149576
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
refactor: 项目更名 WeKnora → Academy
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名)
- 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块)
- docreader proto 描述符采用等长替换,保持序列化字节布局有效
- Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像
- 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
2026-11-13 20:52:51 +08:00

76 lines
2.9 KiB
Go

package handler
import (
"encoding/json"
"io"
"net/http"
apperrors "academy/internal/errors"
"academy/internal/types"
"academy/internal/types/interfaces"
"github.com/gin-gonic/gin"
)
// GraphSearchHandler exposes a read-only JSON view of one authorized KB graph.
type GraphSearchHandler struct {
kbHandler *KnowledgeBaseHandler
service interfaces.GraphSearchService
}
// NewGraphSearchHandler reuses the standard KB access resolver.
func NewGraphSearchHandler(kbHandler *KnowledgeBaseHandler, service interfaces.GraphSearchService) *GraphSearchHandler {
return &GraphSearchHandler{kbHandler: kbHandler, service: service}
}
// Search godoc
// @Summary 查询知识图谱
// @Description 对单个授权知识库按实体名进行区分大小写的子串查询,返回实体、定向关系及仍然有效的来源分块。不调用模型,不影响默认检索。0 表示使用默认上限。
// @Tags 知识库
// @Accept json
// @Produce json
// @Param id path string true "知识库ID"
// @Param agent_id query string false "共享智能体 ID"
// @Param agent_source_tenant_id query integer false "共享智能体来源空间"
// @Param request body types.GraphSearchRequest true "查询及结果上限"
// @Success 200 {object} handler.DataResponse{data=types.GraphSearchResult}
// @Failure 400 {object} apperrors.AppError "参数错误"
// @Failure 401 {object} apperrors.AppError "未登录"
// @Failure 403 {object} apperrors.AppError "无权访问知识库"
// @Failure 404 {object} apperrors.AppError "知识库不存在"
// @Failure 409 {object} apperrors.AppError "知识图谱未启用"
// @Failure 500 {object} apperrors.AppError "来源校验失败"
// @Failure 503 {object} apperrors.AppError "图谱服务不可用"
// @Security Bearer
// @Security ApiKeyAuth
// @Router /knowledge-bases/{id}/graph-search [post]
func (h *GraphSearchHandler) Search(c *gin.Context) {
kb, _, _, _, err := h.kbHandler.validateAndGetKnowledgeBase(c)
if err != nil {
_ = c.Error(err)
return
}
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 8<<10)
decoder := json.NewDecoder(c.Request.Body)
decoder.DisallowUnknownFields()
var req types.GraphSearchRequest
if err := decoder.Decode(&req); err != nil {
_ = c.Error(apperrors.NewBadRequestError("Invalid graph query request"))
return
}
// Reject trailing JSON rather than silently executing only the first query.
if err := decoder.Decode(new(any)); err != io.EOF {
_ = c.Error(apperrors.NewBadRequestError("Expected one graph query object"))
return
}
if err := req.Normalize(); err != nil {
_ = c.Error(apperrors.NewBadRequestError(err.Error()))
return
}
result, err := h.service.Search(c.Request.Context(), kb, req)
if err != nil {
_ = c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": result})
}