feat(api): serve endpoints under /api/v2, retain /api/v1 as alias

Every business endpoint (memory/*, ome/*, knowledge/*) is now served
under /api/v2, aligning the open-source API with the EverOS Cloud
contract. /api/v1 is retained as a permanent, backward-compatible alias:
the same router objects are mounted under both prefixes, so both resolve
to identical handlers and request/response contracts. Existing /api/v1
integrations keep working unchanged. Infra endpoints (/health, /metrics)
stay unversioned.

Fix the Prometheus request-metric label to build the path from the full
request URL (with path params folded) rather than the route's
router-relative path, so the version prefix is preserved and v1/v2
traffic stays distinguishable.

Docs (docs/api.md, docs/openapi.json), CHANGELOG, and route docstrings
updated to lead with /api/v2. Add test_api_versioning as the parity
guard: every v2 route has an identical v1 twin and vice versa.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
zhanghui
2026-07-24 13:44:58 +08:00
co-authored by Claude Opus 4.8
parent c4c2977898
commit 21b845bf88
21 changed files with 1092 additions and 76 deletions
+870 -4
View File
@@ -811,6 +811,766 @@
}
}
}
},
"/api/v2/memory/add": {
"post": {
"tags": [
"memory"
],
"summary": "Add Memory",
"description": "Add messages into the user-memory + agent-memory pipelines.",
"operationId": "add_memory_api_v2_memory_add_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MemorizeAddRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_AddResponseData_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/memory/flush": {
"post": {
"tags": [
"memory"
],
"summary": "Flush Memory",
"description": "Force boundary detection over the current ``session_id`` buffer.\n\n[OSS-only] — cloud edition decides boundary timing server-side and\ndoes not expose this endpoint.",
"operationId": "flush_memory_api_v2_memory_flush_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MemorizeFlushRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_FlushResponseData_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/memory/search": {
"post": {
"tags": [
"memory"
],
"summary": "Post Search",
"description": "Hybrid retrieval across the configured memory backends.",
"operationId": "post_search_api_v2_memory_search_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SearchRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SearchResponse"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/memory/get": {
"post": {
"tags": [
"memory"
],
"summary": "Post Get",
"description": "Paginated listing over the requested ``memory_type``.",
"operationId": "post_get_api_v2_memory_get_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetResponse"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/ome/trigger": {
"post": {
"tags": [
"ome"
],
"summary": "Trigger",
"description": "Manually trigger a registered OME strategy and wait for completion.",
"operationId": "trigger_api_v2_ome_trigger_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TriggerRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TriggerResponse"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/knowledge/documents": {
"post": {
"tags": [
"knowledge"
],
"summary": "Create Document Route",
"description": "Upload a new knowledge document.",
"operationId": "create_document_route_api_v2_knowledge_documents_post",
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/Body_create_document_route_api_v2_knowledge_documents_post"
}
}
}
},
"responses": {
"201": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_DocumentCreateResponse_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
},
"get": {
"tags": [
"knowledge"
],
"summary": "List Documents Route",
"description": "Paginated document listing.",
"operationId": "list_documents_route_api_v2_knowledge_documents_get",
"parameters": [
{
"name": "app_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "App Id"
}
},
{
"name": "project_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "Project Id"
}
},
{
"name": "category_id",
"in": "query",
"required": false,
"schema": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Category Id"
}
},
{
"name": "page",
"in": "query",
"required": false,
"schema": {
"type": "integer",
"minimum": 1,
"default": 1,
"title": "Page"
}
},
{
"name": "page_size",
"in": "query",
"required": false,
"schema": {
"type": "integer",
"maximum": 100,
"minimum": 1,
"default": 20,
"title": "Page Size"
}
},
{
"name": "sort_by",
"in": "query",
"required": false,
"schema": {
"enum": [
"created_at",
"updated_at",
"title"
],
"type": "string",
"default": "created_at",
"title": "Sort By"
}
},
{
"name": "sort_order",
"in": "query",
"required": false,
"schema": {
"enum": [
"asc",
"desc"
],
"type": "string",
"default": "desc",
"title": "Sort Order"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_DocumentListResponse_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/knowledge/documents/{doc_id}": {
"put": {
"tags": [
"knowledge"
],
"summary": "Replace Document Route",
"description": "Replace an existing knowledge document (atomic backup/restore on failure).",
"operationId": "replace_document_route_api_v2_knowledge_documents__doc_id__put",
"parameters": [
{
"name": "doc_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^d_[a-f0-9]{12,32}$",
"title": "Doc Id"
}
}
],
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/Body_replace_document_route_api_v2_knowledge_documents__doc_id__put"
}
}
}
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_DocumentCreateResponse_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
},
"delete": {
"tags": [
"knowledge"
],
"summary": "Delete Document Route",
"description": "Remove a knowledge document.",
"operationId": "delete_document_route_api_v2_knowledge_documents__doc_id__delete",
"parameters": [
{
"name": "doc_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^d_[a-f0-9]{12,32}$",
"title": "Doc Id"
}
},
{
"name": "app_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "App Id"
}
},
{
"name": "project_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "Project Id"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
},
"get": {
"tags": [
"knowledge"
],
"summary": "Get Document Route",
"description": "Fetch a single document with its topic list.",
"operationId": "get_document_route_api_v2_knowledge_documents__doc_id__get",
"parameters": [
{
"name": "doc_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^d_[a-f0-9]{12,32}$",
"title": "Doc Id"
}
},
{
"name": "app_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "App Id"
}
},
{
"name": "project_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "Project Id"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_DocumentDetailResponse_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
},
"patch": {
"tags": [
"knowledge"
],
"summary": "Patch Document Route",
"description": "Update mutable document metadata fields.",
"operationId": "patch_document_route_api_v2_knowledge_documents__doc_id__patch",
"parameters": [
{
"name": "doc_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^d_[a-f0-9]{12,32}$",
"title": "Doc Id"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DocumentPatchRequest"
}
}
}
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_DocumentPatchResponse_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/knowledge/topics/{topic_id}": {
"get": {
"tags": [
"knowledge"
],
"summary": "Get Topic Route",
"description": "Fetch a single topic with full content.",
"operationId": "get_topic_route_api_v2_knowledge_topics__topic_id__get",
"parameters": [
{
"name": "topic_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^d_[a-f0-9]{12,32}_\\d+$",
"title": "Topic Id"
}
},
{
"name": "app_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "App Id"
}
},
{
"name": "project_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "Project Id"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_TopicDetailResponse_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/knowledge/search": {
"post": {
"tags": [
"knowledge"
],
"summary": "Search Knowledge Route",
"description": "Knowledge retrieval (keyword / vector / hybrid).",
"operationId": "search_knowledge_route_api_v2_knowledge_search_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KnowledgeSearchRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_KnowledgeSearchResponse_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v2/knowledge/categories": {
"get": {
"tags": [
"knowledge"
],
"summary": "List Categories Route",
"description": "List taxonomy categories from ``.taxonomy.md``.",
"operationId": "list_categories_route_api_v2_knowledge_categories_get",
"parameters": [
{
"name": "app_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "App Id"
}
},
{
"name": "project_id",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "default",
"title": "Project Id"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessEnvelope_CategoryListResponse_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
@@ -890,6 +1650,59 @@
],
"title": "Body_create_document_route_api_v1_knowledge_documents_post"
},
"Body_create_document_route_api_v2_knowledge_documents_post": {
"properties": {
"file": {
"type": "string",
"contentMediaType": "application/octet-stream",
"title": "File"
},
"title": {
"type": "string",
"minLength": 1,
"pattern": "\\w",
"title": "Title"
},
"source_type": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Source Type"
},
"category_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Category Id"
},
"app_id": {
"type": "string",
"title": "App Id",
"default": "default"
},
"project_id": {
"type": "string",
"title": "Project Id",
"default": "default"
}
},
"type": "object",
"required": [
"file",
"title"
],
"title": "Body_create_document_route_api_v2_knowledge_documents_post"
},
"Body_replace_document_route_api_v1_knowledge_documents__doc_id__put": {
"properties": {
"file": {
@@ -943,6 +1756,59 @@
],
"title": "Body_replace_document_route_api_v1_knowledge_documents__doc_id__put"
},
"Body_replace_document_route_api_v2_knowledge_documents__doc_id__put": {
"properties": {
"file": {
"type": "string",
"contentMediaType": "application/octet-stream",
"title": "File"
},
"title": {
"type": "string",
"minLength": 1,
"pattern": "\\w",
"title": "Title"
},
"source_type": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Source Type"
},
"category_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Category Id"
},
"app_id": {
"type": "string",
"title": "App Id",
"default": "default"
},
"project_id": {
"type": "string",
"title": "Project Id",
"default": "default"
}
},
"type": "object",
"required": [
"file",
"title"
],
"title": "Body_replace_document_route_api_v2_knowledge_documents__doc_id__put"
},
"CategoryDTO": {
"properties": {
"category_id": {
@@ -1819,7 +2685,7 @@
"memory_type"
],
"title": "GetRequest",
"description": "Request body for ``POST /api/v1/memory/get``.\n\nCallers identify the memory owner via ``user_id`` XOR ``agent_id`` —\nexactly one must be set. Internally the manager keeps using\n``owner_id`` / ``owner_type`` (the storage tables' columns); those\nare exposed as derived properties so the rename only affects the\nwire contract."
"description": "Request body for ``POST /api/v2/memory/get``.\n\nCallers identify the memory owner via ``user_id`` XOR ``agent_id`` —\nexactly one must be set. Internally the manager keeps using\n``owner_id`` / ``owner_type`` (the storage tables' columns); those\nare exposed as derived properties so the rename only affects the\nwire contract."
},
"GetResponse": {
"properties": {
@@ -2642,7 +3508,7 @@
"query"
],
"title": "SearchRequest",
"description": "Request body for ``POST /api/v1/memory/search``.\n\nCallers identify the memory owner via ``user_id`` XOR ``agent_id`` —\nexactly one must be set. Internally the manager + compile_filters keep\nusing ``owner_id`` / ``owner_type`` (the storage tables' columns);\nthose are exposed as derived properties so the rename only affects\nthe wire contract, not the internal recall plumbing."
"description": "Request body for ``POST /api/v2/memory/search``.\n\nCallers identify the memory owner via ``user_id`` XOR ``agent_id`` —\nexactly one must be set. Internally the manager + compile_filters keep\nusing ``owner_id`` / ``owner_type`` (the storage tables' columns);\nthose are exposed as derived properties so the rename only affects\nthe wire contract, not the internal recall plumbing."
},
"SearchResponse": {
"properties": {
@@ -3001,7 +3867,7 @@
"name"
],
"title": "TriggerRequest",
"description": "Request body for ``POST /api/v1/ome/trigger``."
"description": "Request body for ``POST /api/v2/ome/trigger``."
},
"TriggerResponse": {
"properties": {
@@ -3020,7 +3886,7 @@
"name"
],
"title": "TriggerResponse",
"description": "Response body for ``POST /api/v1/ome/trigger``."
"description": "Response body for ``POST /api/v2/ome/trigger``."
},
"UnprocessedMessageDTO": {
"properties": {