docs(swagger): document the real request and response types (#4304)
* docs(swagger): add shared response envelope types
* docs(swagger): type knowledge base responses
* docs(swagger): add concrete response body types
* docs(swagger): type chunk list responses
* docs(swagger): type knowledge mutation responses
* docs(swagger): type wiki search and autofix responses
* docs(swagger): type FAQ responses
* docs(swagger): type tag responses
* docs(swagger): type message responses and SSE schemas
* docs(swagger): type agent responses
* docs(swagger): type remaining handler responses
* docs(swagger): regenerate OpenAPI spec
* docs(swagger): type knowledge, activity and wiki maintenance endpoints
Covers the endpoints left out of the earlier passes: knowledge base
detail, document list/detail/spans/reparse/cancel/delete, knowledge
base activity and the Wiki stats, issues, lint and rebuild-links
endpoints. The spans handler now writes the documented structs instead
of gin.H, so the schema cannot drift from the body; the JSON is
unchanged. List filters gain their real enums and bounds, including
the finalizing, cancelled and deleting parse states.
* docs(swagger): document JSON-valued fields as JSON, not byte arrays
types.JSON and json.RawMessage are byte slices, so swag rendered every
metadata, details and config field as an array of integers. A swag
overrides file documents them as objects; the four fields that hold
arrays (relation chunk ids, allowed origins, image refs) say so with a
swaggertype tag.
* chore(lint): exempt swag annotation lines from the line-length limit
swag reads each @Param, @Success and @Failure as a single line, so an
enum list or a composed response type cannot be wrapped to fit.
* chore(lint): exempt struct tags carrying swag attributes from the line limit
Struct tags cannot wrap either; a field documented with swaggertype or
extensions keeps its tags on the declaration line.
2026-10-14 17:41:42 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
// Response envelopes for Swagger annotations. Handlers write these shapes
|
|
|
|
|
// with gin.H; the types only exist so the documented body matches. Compose
|
|
|
|
|
// the payload in the annotation, e.g.
|
|
|
|
|
//
|
|
|
|
|
// @Success 200 {object} handler.DataResponse{data=types.Knowledge}
|
|
|
|
|
// @Success 200 {object} handler.PageResponse{data=[]types.Knowledge}
|
|
|
|
|
|
|
|
|
|
// DataResponse is the {"success": true, "data": ...} body.
|
|
|
|
|
type DataResponse struct {
|
|
|
|
|
Success bool `json:"success" example:"true"`
|
|
|
|
|
Data any `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PageResponse is a page of a list with the total match count.
|
|
|
|
|
type PageResponse struct {
|
|
|
|
|
Success bool `json:"success" example:"true"`
|
|
|
|
|
Data any `json:"data"`
|
feat(agent): add the built-in WeKnora assistant with an operation catalog (#4302)
* feat(agent): add the built-in WeKnora assistant with an operation catalog
Adds builtin-weknora-assistant, which inspects and manages WeKnora with the
signed-in user's permissions:
- find_operations / run_operation over an allow-listed API operation catalog,
dispatched in-process through the real router as the user
- builtin approval for write/destructive operations, refused when
non-interactive
- agent attribution in knowledge base activity, including async tasks
- page_context request field, narrowed to the turn's search targets and
rendered into runtime_context with model handles
* refactor(agent): compile the operation catalog from x-agent Swagger annotations
The catalog was a hand-written copy of what the swag annotations already
describe: routes, parameters, enums and response shapes. It now compiles
from the Swagger document embedded in the binary. Handlers opt in with
// @x-agent {"id":"knowledge.delete","risk":"destructive",...}
// @x-agent-hint "Cannot be undone."
// @Param id path string true "知识ID" extensions(x-agent=knowledge_id)
and response types mark the fields the model may see with an
extensions:"x-agent" struct tag. Exposure stays opt-in at every level:
unmarked operations, parameters and fields are not reachable, so a new
field on Knowledge or a new query parameter never reaches the model by
accident. NewCatalog still enforces the safety rules (forbidden areas,
risk versus method, approval targets), and a test fails when the
annotations and docs/swagger.json disagree.
The twelve operations compile to the same routes, parameters and
results as before; document results now share one field set, and the
parse_status filter accepts deleting, which the API supports.
* fix(agent): enforce resume and wiki context scopes
2026-10-15 04:18:30 +00:00
|
|
|
Total int64 `json:"total" extensions:"x-agent"`
|
|
|
|
|
Page int `json:"page" extensions:"x-agent"`
|
|
|
|
|
PageSize int `json:"page_size" extensions:"x-agent"`
|
docs(swagger): document the real request and response types (#4304)
* docs(swagger): add shared response envelope types
* docs(swagger): type knowledge base responses
* docs(swagger): add concrete response body types
* docs(swagger): type chunk list responses
* docs(swagger): type knowledge mutation responses
* docs(swagger): type wiki search and autofix responses
* docs(swagger): type FAQ responses
* docs(swagger): type tag responses
* docs(swagger): type message responses and SSE schemas
* docs(swagger): type agent responses
* docs(swagger): type remaining handler responses
* docs(swagger): regenerate OpenAPI spec
* docs(swagger): type knowledge, activity and wiki maintenance endpoints
Covers the endpoints left out of the earlier passes: knowledge base
detail, document list/detail/spans/reparse/cancel/delete, knowledge
base activity and the Wiki stats, issues, lint and rebuild-links
endpoints. The spans handler now writes the documented structs instead
of gin.H, so the schema cannot drift from the body; the JSON is
unchanged. List filters gain their real enums and bounds, including
the finalizing, cancelled and deleting parse states.
* docs(swagger): document JSON-valued fields as JSON, not byte arrays
types.JSON and json.RawMessage are byte slices, so swag rendered every
metadata, details and config field as an array of integers. A swag
overrides file documents them as objects; the four fields that hold
arrays (relation chunk ids, allowed origins, image refs) say so with a
swaggertype tag.
* chore(lint): exempt swag annotation lines from the line-length limit
swag reads each @Param, @Success and @Failure as a single line, so an
enum list or a composed response type cannot be wrapped to fit.
* chore(lint): exempt struct tags carrying swag attributes from the line limit
Struct tags cannot wrap either; a field documented with swaggertype or
extensions keeps its tags on the declaration line.
2026-10-14 17:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DataMessageResponse is DataResponse with a human-readable message.
|
|
|
|
|
type DataMessageResponse struct {
|
|
|
|
|
Success bool `json:"success" example:"true"`
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
Data any `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MessageResponse is the {"success": true, "message": ...} body.
|
|
|
|
|
type MessageResponse struct {
|
|
|
|
|
Success bool `json:"success" example:"true"`
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
}
|