[Bug]: [UX/Docs] v0.3.16 手动资源添加 API 错误提示不友好,常见字段名导致 INVALID_ARGUMENT
Bug Description
环境信息
- OpenViking 版本: v0.3.16 (Docker
ghcr.io/volcengine/openviking:latest) - 部署方式: Docker 容器,Ubuntu 24.04 宿主机
- 认证方式: User Key
- Embedding 配置: OpenAI 兼容中转站,模型
google-gemini-embedding-001,维度 3072
问题描述
在尝试通过 REST API 手动添加资源时,多个直觉上合理的字段名全部触发 INVALID_ARGUMENT / "Extra inputs are not permitted"。经过调研发现是字段命名与文档示例不一致导致的。
Steps to Reproduce
尝试1:传入 content 创建文本资源
curl -X POST http://localhost:1933/api/v1/resources \
-H "Authorization: Bearer <user_key>" \
-H "Content-Type: application/json" \
-d '{"content": "文本内容", "source": "manual", "metadata": {}}'
→ 错误:INVALID_ARGUMENT — body.content: Extra inputs are not permitted
尝试2:传入 url 和 target
curl -X POST http://localhost:1933/api/v1/resources \
-d '{"url": "https://example.com", "target": "viking://resources/test/"}'
→ 错误:INVALID_ARGUMENT — body.url: Extra inputs are not permitted
尝试3:WebDAV PUT
curl -X PUT http://localhost:1933/webdav/resources/test.md
→ 错误:404 NOT_FOUND
尝试4:直接调 /api/v1/embeddings
curl -X POST http://localhost:1933/api/v1/embeddings
→ 错误:404 Not Found
Verified Workarounds
经查阅官方文档并验证,以下方式可正常工作:
方式A:add_resource 添加 URL 资源 ✅
curl -X POST http://localhost:1933/api/v1/resources \
-H "Authorization: Bearer <user_key>" \
-H "Content-Type: application/json" \
-d '{"path": "https://docs.newapi.pro/en", "to": "viking://resources/test/newapi-docs.md", "reason": "测试", "wait": true}'
→ 返回:"ok"
方式B:content/write 创建纯文本文件 ✅
curl -X POST http://localhost:1933/api/v1/content/write \
-H "Authorization: Bearer <user_key>" \
-H "Content-Type: application/json" \
-d '{"uri": "viking://resources/test/manual-memory.md", "content": "# 测试\n\n内容", "mode": "create", "wait": true}'
→ 返回:"ok"
Expected Behavior
- 当传入
content/url/target等常见错误字段时,返回更友好的提示,例如:"字段
content不被支持。如需创建文本文件,请使用POST /api/v1/content/write;如需添加 URL 资源,请使用path字段。" - 文档中增加"常见错误"章节,明确列出非法字段名。
Actual Behavior
Pydantic 直接返回 extra_forbidden,用户需要大量试错才能找到正确的 path/to/temp_file_id 等字段。
Minimal Reproducible Example
curl -X POST http://localhost:1933/api/v1/resources \
-H "Content-Type: application/json" \
-d '{"content": "test"}'
Error Logs
Pydantic 验证错误(add_resource 传入非法字段时):
{
"code": "INVALID_ARGUMENT",
"message": "Invalid request parameters: body.content: Extra inputs are not permitted",
"details": {
"validation_errors": [
{"loc": ["body", "content"], "message": "Extra inputs are not permitted", "type": "extra_forbidden"},
{"loc": ["body", "source"], "message": "Extra inputs are not permitted", "type": "extra_forbidden"},
{"loc": ["body", "metadata"], "message": "Extra inputs are not permitted", "type": "extra_forbidden"}
]
}
}
WebDAV 404 错误:
{"status":"error","error":{"code":"NOT_FOUND","message":"Resource not found: not found: /main/resources/test-webdav.md"}}
Embedding 队列状态(验证通过):
| Embedding | 0 | 0 | 9 | 0 | 0 | 9 |
| Semantic | 0 | 0 | 2 | 0 | 0 | 2 |
OpenViking Version
0.3.16
Python Version
3.13.0
Operating System
Linux
Model Backend
None
Additional Context
- #1960 — OpenClaw 插件兼容性问题(已解决,感谢官方!)
感谢 OpenViking 团队的工作!autoCapture 集成非常稳定,我们只是希望在手动 API 调用的文档和错误提示上能更友好一些。
我想尝试处理这个 issue。计划先补充文档中的常见错误字段说明, 明确 content/url/target 等字段应分别改用 /api/v1/content/write 或 path/to。 如果维护者更希望直接改后端校验错误提示,我也可以按建议调整。
感谢反馈,这个问题我们确认过了:
POST /api/v1/resources当前的正式字段是path/temp_file_id/to/parent/create_parent等;content应该走POST /api/v1/content/write,target不是当前 SDK/HTTP API 的兼容字段。- 文档里确实还有一些旧示例残留了
target=,资源 API 里也有parent_auto_create和 HTTP 字段混淆的问题,容易误导用户。 - 我已经在 #2107 里统一修正了这些文档和示例:把
target=改为to=,把资源 API 文档对齐到create_parent,并补充了add_resource与content/write的边界说明,以及 WebDAVPUT需要先创建父目录的说明。
这次先按文档一致性问题处理并关闭。后续如果还希望进一步增强后端校验错误提示,可以单独开一个 UX issue 跟进。