面向 PAT 用户的 Knowledge API 接口。鉴权方式为 Authorization: Bearer <pat_token>,基础路径为 /personal/v1/knowledge/。
| 方法 | 路径 | 说明 |
|---|---|---|
| POST | /personal/v1/knowledge/list | 获取知识列表 |
| GET | /personal/v1/knowledge/{id} | 获取知识详情 |
| POST | /personal/v1/knowledge/create | 创建知识 |
| POST | /personal/v1/knowledge/update | 更新知识 |
| POST | /personal/v1/knowledge/upsert | 保存知识(创建或更新) |
{
"code": 200,
"message": "common.success",
"data": { ... }
}
| 字段 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码,200 表示成功 |
| message | string | 国际化消息 key |
| data | object/null | 响应数据 |
列表接口 data 结构(PaginationData):
| 字段 | 类型 | 说明 |
|---|---|---|
| page | object/null | 分页信息,不传分页参数时为 null |
| page.total | int | 总记录数 |
| page.page_num | int | 当前页码(从 1 开始) |
| page.page_size | int | 每页记录数 |
| items | array | 知识列表 KnowledgeResponse[] |
| 字段 | 类型 | 说明 |
|---|---|---|
| id | int | 系统自增主键 |
| name | string | 知识名称 |
| type | string | 知识类型:default(简单知识)/ document(文档知识) |
| trigger | string | 触发条件类型(见下方枚举) |
| trigger_config | object | 触发条件配置(根据 trigger 不同而不同) |
| description | string/null | 知识描述 |
| data | object | 知识内容数据(根据 type 不同而不同) |
| labels | object/null | 标签键值对,例如 {"env": "prod"} |
| metadata | object/null | 元数据信息 |
| application_id | string/null | 从 trigger_config.application_id 派生的兼容字段 |
| application_name | string/null | 应用触发配置对应的显示名称 |
| workspace_id | string/null | 工作空间 ID |
| is_public | bool | 是否公共知识 |
| is_readonly | bool | 是否只读 |
| is_applied | bool | 当前 workspace 是否已订阅 |
| source | string | 知识来源,默认 "custom" |
| forked_from | int/null | Fork 来源知识 ID,NULL 表示原创 |
| created_at | int | 创建时间戳(毫秒) |
| updated_at | int | 更新时间戳(毫秒) |
| 值 | 说明 | trigger_config 要求 |
|---|---|---|
smart | 智能触发 | 不应含 application_id 之外的配置参数 |
always | 始终触发 | 不应含 application_id 之外的配置参数 |
application | 应用触发 | 必须提供 application_id |
service | 服务触发 | 必须提供 service_id |
infrastructure | 基础设施触发 | 必须提供 infrastructure_id |
connector | 连接器触发 | 必须提供 connector_id |
bridge_node | 桥接节点触发 | 必须提供 bridge_node_client_id |
proxy | 代理节点触发 | 必须提供 proxy_id |
alert | 告警触发 | 必须提供非空 match_patterns 数组 |
| 值 | 说明 | data 要求 |
|---|---|---|
default | 简单知识 | 必须提供 content 字段 |
document | 文档知识 | 必须提供 document_content 或 document_id 字段 |
| 值 | 说明 |
|---|---|
eq | 精确匹配 |
includeAny | 包含任一(OR) |
excludeAny | 排除任一 |
like | 模糊匹配 |
POST /personal/v1/knowledge/list
Authorization: Bearer <pat_token>
Content-Type: application/json
请求体:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| filters | object | 否 | 过滤条件 |
| filters.name | FilterValue | 否 | 按知识名称过滤 |
| filters.type | FilterValue | 否 | 按知识类型过滤 |
| filters.trigger | FilterValue | 否 | 按触发条件过滤 |
| filters.labels | LabelFilter | 否 | 按标签过滤 |
| filters.application_id | FilterValue | 否 | 按 application_id 过滤 |
| filters.service_id | FilterValue | 否 | 按 service_id 过滤 |
| filters.infrastructure_id | FilterValue | 否 | 按 infrastructure_id 过滤 |
| filters.connector_id | FilterValue | 否 | 按 connector_id 过滤 |
| filters.bridge_node_client_id | FilterValue | 否 | 按 bridge_node_client_id 过滤 |
| filters.proxy_id | FilterValue | 否 | 按 proxy_id 过滤 |
| filters.workspace_id | FilterValue | 否 | 按 workspace_id 过滤 |
| filters.is_public | FilterValue | 否 | 是否公共知识 |
| filters.is_readonly | FilterValue | 否 | 是否只读 |
| filters.source | FilterValue | 否 | 按知识来源过滤 |
| sort | object | 否 | 排序配置 |
| sort.order_by | string | 是 | 排序字段 |
| sort.order | string | 是 | 排序方向:desc, asc |
| page | object | 否 | 分页配置 |
| page.page_no | int | 否 | 页码,从 1 开始,默认 1 |
| page.page_size | int | 否 | 每页记录数,1~200,默认 20 |
| include_public | bool | 否 | 是否包含公共知识,默认 false |
| context_visible_only | bool | 否 | 是否仅使用 Context 可见集合,默认 true |
FilterValue 结构:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| operator | string | 是 | 过滤操作符:eq, includeAny, excludeAny, like |
| values | array | 否 | 用于数组操作的值列表 |
| value | string | 否 | 用于单值操作的值 |
LabelFilter 结构:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| operator | string | 是 | 过滤操作符 |
| values | array | 是 | 标签过滤项列表 |
| values.key | string | 是 | 标签 key |
| values.value | string/null | 否 | 标签 value,为空表示只匹配 key |
curl 示例:
# 查询列表(不带过滤)
curl -s -X POST 'http://localhost:8000/personal/v1/knowledge/list' \
-H 'Authorization: Bearer <pat_token>' \
-H 'Content-Type: application/json' \
-d '{
"page": {
"page_no": 1,
"page_size": 20
},
"sort": {
"order_by": "created_at",
"order": "desc"
}
}' | jq .
# 按名称模糊查询
curl -s -X POST 'http://localhost:8000/personal/v1/knowledge/list' \
-H 'Authorization: Bearer <pat_token>' \
-H 'Content-Type: application/json' \
-d '{
"filters": {
"name": {
"operator": "like",
"value": "告警"
}
},
"page": {
"page_no": 1,
"page_size": 20
}
}' | jq .
# 按 trigger 类型过滤
curl -s -X POST 'http://localhost:8000/personal/v1/knowledge/list' \
-H 'Authorization: Bearer <pat_token>' \
-H 'Content-Type: application/json' \
-d '{
"filters": {
"trigger": {
"operator": "eq",
"value": "alert"
}
},
"page": {
"page_no": 1,
"page_size": 50
}
}' | jq .
GET /personal/v1/knowledge/{id}
Authorization: Bearer <pat_token>
路径参数:
| 参数 | 类型 | 说明 |
|---|---|---|
| id | int | 知识系统主键 ID |
curl 示例:
curl -s 'http://localhost:8000/personal/v1/knowledge/1' \
-H 'Authorization: Bearer <pat_token>' | jq .
响应示例:
{
"code": 200,
"message": "common.success",
"data": {
"id": 1,
"name": "MySQL 连接数告警处理",
"type": "default",
"trigger": "alert",
"trigger_config": {
"match_patterns": ["MySQL 连接数"]
},
"description": "MySQL 连接数超限后的标准处理流程",
"data": {
"content": "1. 登录 MySQL 执行 SHOW PROCESSLIST\n2. 确认长事务或慢查询\n3. kill 阻塞会话"
},
"labels": {"env": "prod"},
"application_id": null,
"application_name": null,
"workspace_id": "wks-xxx",
"is_public": false,
"is_readonly": false,
"is_applied": false,
"source": "custom",
"forked_from": null,
"created_at": 1717000000000,
"updated_at": 1717000000000
}
}
POST /personal/v1/knowledge/create
Authorization: Bearer <pat_token>
Content-Type: application/json
请求体:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | 知识名称,最长 255 字符,不能为空或纯空白 |
| type | string | 是 | 知识类型:default 或 document |
| trigger | string | 是 | 触发条件类型 |
| trigger_config | object | 是 | 触发配置,需与 trigger 类型匹配 |
| description | string/null | 否 | 知识描述 |
| data | object | 是 | 知识内容数据 |
| labels | object/null | 否 | 标签键值对,key 不能为空 |
| metadata | object/null | 否 | 元数据信息 |
curl 示例:
# 创建简单知识(default 类型 + alert 触发)
curl -s -X POST 'http://localhost:8000/personal/v1/knowledge/create' \
-H 'Authorization: Bearer <pat_token>' \
-H 'Content-Type: application/json' \
-d '{
"name": "MySQL 连接数告警处理",
"type": "default",
"trigger": "alert",
"trigger_config": {
"match_patterns": ["MySQL 连接数"]
},
"description": "MySQL 连接数超限后的标准处理流程",
"data": {
"content": "1. 登录 MySQL 执行 SHOW PROCESSLIST\n2. 确认长事务或慢查询\n3. kill 阻塞会话"
},
"labels": {
"env": "prod",
"team": "dba"
}
}' | jq .
# 创建应用触发知识
curl -s -X POST 'http://localhost:8000/personal/v1/knowledge/create' \
-H 'Authorization: Bearer <pat_token>' \
-H 'Content-Type: application/json' \
-d '{
"name": "订单服务重启流程",
"type": "document",
"trigger": "application",
"trigger_config": {
"application_id": "app-order-service"
},
"data": {
"document_content": "# 订单服务重启\n\n1. 确认无正在处理的订单\n2. 执行 graceful shutdown\n3. 等待健康检查通过"
}
}' | jq .
POST /personal/v1/knowledge/update
Authorization: Bearer <pat_token>
Content-Type: application/json
所有非 id 的字段均为可选。更新 data 时必须同时提供 type;更新 trigger_config 时必须同时提供 trigger。
请求体:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | int | 是 | 知识系统主键 ID |
| name | string/null | 否 | 知识名称 |
| type | string/null | 否 | 知识类型 |
| trigger | string/null | 否 | 触发条件类型 |
| trigger_config | object/null | 否 | 触发配置(提供时必须同时提供 trigger) |
| description | string/null | 否 | 知识描述 |
| data | object/null | 否 | 知识内容数据(提供时必须同时提供 type) |
| labels | object/null | 否 | 标签键值对 |
| metadata | object/null | 否 | 元数据信息 |
curl 示例:
# 更新知识名称和内容
curl -s -X POST 'http://localhost:8000/personal/v1/knowledge/update' \
-H 'Authorization: Bearer <pat_token>' \
-H 'Content-Type: application/json' \
-d '{
"id": 1,
"name": "MySQL 连接数告警处理 v2",
"type": "default",
"data": {
"content": "更新后的处理流程..."
}
}' | jq .
POST /personal/v1/knowledge/upsert
Authorization: Bearer <pat_token>
Content-Type: application/json
以 name + trigger + trigger_config 作为唯一标识进行 upsert。存在则更新,不存在则创建。
请求体:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | 知识名称 |
| trigger | string | 是 | 触发条件类型 |
| trigger_config | object | 是 | 触发配置 |
| type | string/null | 否 | 知识类型 |
| description | string/null | 否 | 知识描述 |
| data | object/null | 否 | 知识内容数据 |
| labels | object/null | 否 | 标签键值对 |
| metadata | object/null | 否 | 元数据信息 |
curl 示例:
curl -s -X POST 'http://localhost:8000/personal/v1/knowledge/upsert' \
-H 'Authorization: Bearer <pat_token>' \
-H 'Content-Type: application/json' \
-d '{
"name": "MySQL 连接数告警处理",
"type": "default",
"trigger": "alert",
"trigger_config": {
"match_patterns": ["MySQL 连接数"]
},
"data": {
"content": "最新的处理流程..."
},
"labels": {
"env": "staging"
}
}' | jq .