Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(openapi): generate openapi.yml from routes via hono-openapi (#17944)

Rdmclin23ea7afd5d8a0
diff --git a/.prettierignore b/.prettierignore
index e96269b4bc6..c4479083687 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -18,6 +18,9 @@ LICENSE
# dependencies
node_modules
+
+# generated files (regenerate with `bun generate:openapi` in packages/openapi)
+packages/openapi/openapi.yml
*.log
*.lock
package-lock.json
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 120c10b70e5..ec4534b0fbf 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -97,6 +97,8 @@ export default eslint(
'.i18nrc.js',
// vendored code (copied from @microsoft/fetch-event-source)
'packages/utils/src/client/fetchEventSource/parse.ts',
+ // generated files (regenerate with `bun generate:openapi` in packages/openapi)
+ 'packages/openapi/openapi.yml',
],
next: true,
react: 'next',
diff --git a/packages/openapi/openapi.yml b/packages/openapi/openapi.yml
new file mode 100644
index 00000000000..a9bc451d4d2
--- /dev/null
+++ b/packages/openapi/openapi.yml
@@ -0,0 +1,3148 @@
+openapi: 3.1.0
+components:
+ securitySchemes:
+ bearerAuth:
+ bearerFormat: API Key (sk-lh-...) or OIDC JWT
+ scheme: bearer
+ type: http
+info:
+ title: LobeHub API
+ description: LobeHub platform REST API. Generated from `packages/openapi` routes
+ β€” do not edit openapi.yml by hand; run `bun generate:openapi` instead.
+ version: 1.0.0
+security:
+ - bearerAuth: []
+servers:
+ - description: LobeHub Cloud
+ url: https://app.lobehub.com
+paths:
+ /api/v1/health:
+ get:
+ operationId: getApiV1Health
+ summary: Health check
+ tags:
+ - health
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ /api/v1/agent-groups:
+ get:
+ operationId: getApiV1AgentGroups
+ summary: Get agent group list
+ tags:
+ - agent-groups
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ post:
+ operationId: postApiV1AgentGroups
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ name:
+ type: string
+ minLength: 1
+ sort:
+ anyOf:
+ - type: number
+ - type: "null"
+ required:
+ - name
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agent-groups
+ /api/v1/agent-groups/{id}:
+ get:
+ operationId: getApiV1AgentGroupsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agent-groups
+ patch:
+ operationId: patchApiV1AgentGroupsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ name:
+ anyOf:
+ - type: string
+ minLength: 1
+ - type: "null"
+ sort:
+ anyOf:
+ - type: number
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agent-groups
+ delete:
+ operationId: deleteApiV1AgentGroupsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agent-groups
+ /api/v1/agents:
+ get:
+ operationId: getApiV1Agents
+ parameters:
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agents
+ post:
+ operationId: postApiV1Agents
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ avatar:
+ anyOf:
+ - type: string
+ - type: "null"
+ chatConfig:
+ anyOf:
+ - type: object
+ properties:
+ disableContextCaching:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ displayMode:
+ anyOf:
+ - type: string
+ enum:
+ - chat
+ - docs
+ - type: "null"
+ enableCompressHistory:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableGraphMode:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableHistoryCount:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableMaxTokens:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableReasoning:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableReasoningEffort:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ graph:
+ anyOf:
+ - type: object
+ properties:
+ description:
+ type: string
+ fields:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties:
+ type: object
+ properties:
+ desc:
+ type: string
+ minLength: 1
+ schema:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ required:
+ - desc
+ - schema
+ maxInstructionCount:
+ type: integer
+ exclusiveMinimum: 0
+ maximum: 9007199254740991
+ name:
+ type: string
+ minLength: 1
+ nodes:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties:
+ oneOf:
+ - type: object
+ properties:
+ allowedToolApiNames:
+ type: array
+ items:
+ type: string
+ minLength: 1
+ maxAgentSteps:
+ type: integer
+ exclusiveMinimum: 0
+ maximum: 9007199254740991
+ type:
+ type: string
+ const: agent
+ required:
+ - type
+ - type: object
+ properties:
+ type:
+ type: string
+ const: llm
+ required:
+ - type
+ terminal:
+ type: string
+ minLength: 1
+ edges:
+ type: array
+ items:
+ type: object
+ properties:
+ condition:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ from:
+ type: string
+ input:
+ type: object
+ properties:
+ fields:
+ type: array
+ items:
+ type: object
+ properties:
+ desc:
+ type: string
+ minLength: 1
+ field:
+ type: string
+ minLength: 1
+ required:
+ type: boolean
+ from:
+ type: string
+ minLength: 1
+ required:
+ - field
+ - from
+ output:
+ type: object
+ properties:
+ fields:
+ type: array
+ items:
+ type: object
+ properties:
+ desc:
+ type: string
+ minLength: 1
+ field:
+ type: string
+ minLength: 1
+ required:
+ type: boolean
+ required:
+ - field
+ instruction:
+ type: string
+ minLength: 1
+ instruction:
+ type: string
+ minLength: 1
+ maxTraversals:
+ type: integer
+ minimum: 0
+ maximum: 9007199254740991
+ to:
+ type: string
+ required:
+ - from
+ - instruction
+ - to
+ required:
+ - fields
+ - name
+ - nodes
+ - terminal
+ - edges
+ - type: "null"
+ historyCount:
+ anyOf:
+ - type: number
+ - type: "null"
+ reasoningBudgetToken:
+ anyOf:
+ - type: number
+ - type: "null"
+ reasoningEffort:
+ anyOf:
+ - type: string
+ enum:
+ - low
+ - medium
+ - high
+ - type: "null"
+ searchFCModel:
+ anyOf:
+ - type: string
+ - type: "null"
+ searchMode:
+ anyOf:
+ - type: string
+ enum:
+ - disabled
+ - enabled
+ - type: "null"
+ useModelBuiltinSearch:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ - type: "null"
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ model:
+ anyOf:
+ - type: string
+ - type: "null"
+ params:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ provider:
+ anyOf:
+ - type: string
+ - type: "null"
+ systemRole:
+ anyOf:
+ - type: string
+ - type: "null"
+ title:
+ type: string
+ minLength: 1
+ required:
+ - title
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agents
+ /api/v1/agents/{id}:
+ get:
+ operationId: getApiV1AgentsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agents
+ patch:
+ operationId: patchApiV1AgentsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ avatar:
+ anyOf:
+ - type: string
+ - type: "null"
+ chatConfig:
+ anyOf:
+ - type: object
+ properties:
+ disableContextCaching:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ displayMode:
+ anyOf:
+ - type: string
+ enum:
+ - chat
+ - docs
+ - type: "null"
+ enableCompressHistory:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableGraphMode:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableHistoryCount:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableMaxTokens:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableReasoning:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ enableReasoningEffort:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ graph:
+ anyOf:
+ - type: object
+ properties:
+ description:
+ type: string
+ fields:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties:
+ type: object
+ properties:
+ desc:
+ type: string
+ minLength: 1
+ schema:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ required:
+ - desc
+ - schema
+ maxInstructionCount:
+ type: integer
+ exclusiveMinimum: 0
+ maximum: 9007199254740991
+ name:
+ type: string
+ minLength: 1
+ nodes:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties:
+ oneOf:
+ - type: object
+ properties:
+ allowedToolApiNames:
+ type: array
+ items:
+ type: string
+ minLength: 1
+ maxAgentSteps:
+ type: integer
+ exclusiveMinimum: 0
+ maximum: 9007199254740991
+ type:
+ type: string
+ const: agent
+ required:
+ - type
+ - type: object
+ properties:
+ type:
+ type: string
+ const: llm
+ required:
+ - type
+ terminal:
+ type: string
+ minLength: 1
+ edges:
+ type: array
+ items:
+ type: object
+ properties:
+ condition:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ from:
+ type: string
+ input:
+ type: object
+ properties:
+ fields:
+ type: array
+ items:
+ type: object
+ properties:
+ desc:
+ type: string
+ minLength: 1
+ field:
+ type: string
+ minLength: 1
+ required:
+ type: boolean
+ from:
+ type: string
+ minLength: 1
+ required:
+ - field
+ - from
+ output:
+ type: object
+ properties:
+ fields:
+ type: array
+ items:
+ type: object
+ properties:
+ desc:
+ type: string
+ minLength: 1
+ field:
+ type: string
+ minLength: 1
+ required:
+ type: boolean
+ required:
+ - field
+ instruction:
+ type: string
+ minLength: 1
+ instruction:
+ type: string
+ minLength: 1
+ maxTraversals:
+ type: integer
+ minimum: 0
+ maximum: 9007199254740991
+ to:
+ type: string
+ required:
+ - from
+ - instruction
+ - to
+ required:
+ - fields
+ - name
+ - nodes
+ - terminal
+ - edges
+ - type: "null"
+ historyCount:
+ anyOf:
+ - type: number
+ - type: "null"
+ reasoningBudgetToken:
+ anyOf:
+ - type: number
+ - type: "null"
+ reasoningEffort:
+ anyOf:
+ - type: string
+ enum:
+ - low
+ - medium
+ - high
+ - type: "null"
+ searchFCModel:
+ anyOf:
+ - type: string
+ - type: "null"
+ searchMode:
+ anyOf:
+ - type: string
+ enum:
+ - disabled
+ - enabled
+ - type: "null"
+ useModelBuiltinSearch:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ - type: "null"
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ model:
+ anyOf:
+ - type: string
+ - type: "null"
+ params:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ provider:
+ anyOf:
+ - type: string
+ - type: "null"
+ systemRole:
+ anyOf:
+ - type: string
+ - type: "null"
+ title:
+ type: string
+ minLength: 1
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agents
+ delete:
+ operationId: deleteApiV1AgentsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - agents
+ /api/v1/files:
+ get:
+ operationId: getApiV1Files
+ parameters:
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ - in: query
+ name: fileType
+ schema:
+ type: string
+ - in: query
+ name: knowledgeBaseId
+ schema:
+ type: string
+ - in: query
+ name: queryAll
+ schema:
+ type: string
+ - in: query
+ name: updatedAtEnd
+ schema:
+ type: string
+ format: date-time
+ pattern: ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
+ - in: query
+ name: updatedAtStart
+ schema:
+ type: string
+ format: date-time
+ pattern: ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
+ - in: query
+ name: userId
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ post:
+ operationId: postApiV1Files
+ requestBody:
+ content:
+ multipart/form-data:
+ schema:
+ properties:
+ agentId:
+ type: string
+ directory:
+ type: string
+ file:
+ format: binary
+ type: string
+ knowledgeBaseId:
+ type: string
+ sessionId:
+ type: string
+ skipCheckFileType:
+ type: boolean
+ skipExist:
+ type: boolean
+ required:
+ - file
+ type: object
+ required: true
+ summary: Upload a file and return the corresponding file record
+ tags:
+ - files
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ /api/v1/files/{id}:
+ get:
+ operationId: getApiV1FilesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ patch:
+ operationId: patchApiV1FilesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ knowledgeBaseId:
+ anyOf:
+ - type: string
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ delete:
+ operationId: deleteApiV1FilesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ /api/v1/files/{id}/url:
+ get:
+ operationId: getApiV1FilesByIdUrl
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ - in: query
+ name: expiresIn
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ /api/v1/files/{id}/parses:
+ post:
+ operationId: postApiV1FilesByIdParses
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ - in: query
+ name: skipExist
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ /api/v1/files/{id}/chunks:
+ post:
+ operationId: postApiV1FilesByIdChunks
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ autoEmbedding:
+ type: boolean
+ skipExist:
+ type: boolean
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ get:
+ operationId: getApiV1FilesByIdChunks
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ /api/v1/files/batches:
+ post:
+ operationId: postApiV1FilesBatches
+ requestBody:
+ content:
+ multipart/form-data:
+ schema:
+ properties:
+ agentId:
+ type: string
+ directory:
+ type: string
+ files:
+ items:
+ format: binary
+ type: string
+ type: array
+ knowledgeBaseId:
+ type: string
+ sessionId:
+ type: string
+ skipCheckFileType:
+ type: boolean
+ skipExist:
+ type: boolean
+ required:
+ - files
+ type: object
+ required: true
+ summary: Batch file upload
+ tags:
+ - files
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ /api/v1/files/queries:
+ post:
+ operationId: postApiV1FilesQueries
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ fileIds:
+ minItems: 1
+ type: array
+ items:
+ type: string
+ minLength: 1
+ required:
+ - fileIds
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - files
+ /api/v1/knowledge-bases:
+ get:
+ operationId: getApiV1KnowledgeBases
+ parameters:
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ post:
+ operationId: postApiV1KnowledgeBases
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ avatar:
+ type: string
+ format: uri
+ description:
+ type: string
+ maxLength: 1000
+ name:
+ type: string
+ minLength: 1
+ maxLength: 255
+ required:
+ - name
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ /api/v1/knowledge-bases/{id}:
+ get:
+ operationId: getApiV1KnowledgeBasesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ patch:
+ operationId: patchApiV1KnowledgeBasesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ avatar:
+ type: string
+ format: uri
+ description:
+ type: string
+ maxLength: 1000
+ name:
+ type: string
+ minLength: 1
+ maxLength: 255
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ delete:
+ operationId: deleteApiV1KnowledgeBasesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ /api/v1/knowledge-bases/{id}/files:
+ get:
+ operationId: getApiV1KnowledgeBasesByIdFiles
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ - in: query
+ name: fileType
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ /api/v1/knowledge-bases/{id}/files/batch:
+ post:
+ operationId: postApiV1KnowledgeBasesByIdFilesBatch
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ fileIds:
+ minItems: 1
+ type: array
+ items:
+ type: string
+ minLength: 1
+ required:
+ - fileIds
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ delete:
+ operationId: deleteApiV1KnowledgeBasesByIdFilesBatch
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ fileIds:
+ minItems: 1
+ type: array
+ items:
+ type: string
+ minLength: 1
+ required:
+ - fileIds
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ /api/v1/knowledge-bases/{id}/files/move:
+ post:
+ operationId: postApiV1KnowledgeBasesByIdFilesMove
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ fileIds:
+ minItems: 1
+ type: array
+ items:
+ type: string
+ minLength: 1
+ targetKnowledgeBaseId:
+ type: string
+ minLength: 1
+ required:
+ - fileIds
+ - targetKnowledgeBaseId
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - knowledge-bases
+ /api/v1/message-translations/{messageId}:
+ post:
+ operationId: postApiV1MessageTranslationsByMessageId
+ parameters:
+ - in: path
+ name: messageId
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ from:
+ type: string
+ model:
+ anyOf:
+ - type: string
+ - type: "null"
+ provider:
+ anyOf:
+ - type: string
+ - type: "null"
+ to:
+ type: string
+ minLength: 1
+ required:
+ - to
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - message-translations
+ get:
+ operationId: getApiV1MessageTranslationsByMessageId
+ parameters:
+ - in: path
+ name: messageId
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - message-translations
+ patch:
+ operationId: patchApiV1MessageTranslationsByMessageId
+ parameters:
+ - in: path
+ name: messageId
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ from:
+ type: string
+ model:
+ anyOf:
+ - type: string
+ - type: "null"
+ provider:
+ anyOf:
+ - type: string
+ - type: "null"
+ to:
+ type: string
+ minLength: 1
+ content:
+ type: string
+ required:
+ - to
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - message-translations
+ delete:
+ operationId: deleteApiV1MessageTranslationsByMessageId
+ parameters:
+ - in: path
+ name: messageId
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - message-translations
+ /api/v1/messages/count:
+ get:
+ operationId: getApiV1MessagesCount
+ parameters:
+ - in: query
+ name: topicIds
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: userId
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - messages
+ /api/v1/messages:
+ get:
+ operationId: getApiV1Messages
+ parameters:
+ - in: query
+ name: topicId
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: userId
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: role
+ schema:
+ anyOf:
+ - type: string
+ enum:
+ - user
+ - system
+ - assistant
+ - tool
+ - type: "null"
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - messages
+ post:
+ operationId: postApiV1Messages
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ content:
+ type: string
+ minLength: 1
+ role:
+ type: string
+ enum:
+ - user
+ - system
+ - assistant
+ - tool
+ model:
+ anyOf:
+ - type: string
+ - type: "null"
+ provider:
+ anyOf:
+ - type: string
+ - type: "null"
+ topicId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ threadId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ parentId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ quotaId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ agentId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ clientId:
+ anyOf:
+ - type: string
+ - type: "null"
+ metadata:
+ anyOf:
+ - {}
+ - type: "null"
+ reasoning:
+ anyOf:
+ - {}
+ - type: "null"
+ search:
+ anyOf:
+ - {}
+ - type: "null"
+ tools:
+ anyOf:
+ - {}
+ - type: "null"
+ traceId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ observationId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ files:
+ anyOf:
+ - type: array
+ items:
+ type: string
+ - type: "null"
+ favorite:
+ default: false
+ anyOf:
+ - type: boolean
+ - type: "null"
+ required:
+ - content
+ - role
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - messages
+ delete:
+ operationId: deleteApiV1Messages
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ messageIds:
+ minItems: 1
+ type: array
+ items:
+ type: string
+ minLength: 1
+ required:
+ - messageIds
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - messages
+ /api/v1/messages/{id}:
+ get:
+ operationId: getApiV1MessagesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - messages
+ delete:
+ operationId: deleteApiV1MessagesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - messages
+ /api/v1/messages/replies:
+ post:
+ operationId: postApiV1MessagesReplies
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ content:
+ type: string
+ minLength: 1
+ role:
+ type: string
+ const: user
+ model:
+ anyOf:
+ - type: string
+ - type: "null"
+ provider:
+ anyOf:
+ - type: string
+ - type: "null"
+ topicId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ threadId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ parentId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ quotaId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ agentId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ clientId:
+ anyOf:
+ - type: string
+ - type: "null"
+ metadata:
+ anyOf:
+ - {}
+ - type: "null"
+ reasoning:
+ anyOf:
+ - {}
+ - type: "null"
+ search:
+ anyOf:
+ - {}
+ - type: "null"
+ tools:
+ anyOf:
+ - {}
+ - type: "null"
+ traceId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ observationId:
+ anyOf:
+ - anyOf:
+ - type: string
+ - type: "null"
+ - type: "null"
+ files:
+ anyOf:
+ - type: array
+ items:
+ type: string
+ - type: "null"
+ favorite:
+ default: false
+ anyOf:
+ - type: boolean
+ - type: "null"
+ required:
+ - content
+ - role
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - messages
+ /api/v1/models:
+ get:
+ operationId: getApiV1Models
+ parameters:
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ - in: query
+ name: enabled
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: provider
+ schema:
+ anyOf:
+ - type: string
+ minLength: 1
+ maxLength: 64
+ - type: "null"
+ - in: query
+ name: type
+ schema:
+ anyOf:
+ - type: string
+ enum:
+ - chat
+ - embedding
+ - tts
+ - asr
+ - image
+ - text2video
+ - text2music
+ - realtime
+ - stt
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - models
+ post:
+ operationId: postApiV1Models
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ abilities:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ config:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ contextWindowTokens:
+ anyOf:
+ - type: integer
+ minimum: -9007199254740991
+ maximum: 9007199254740991
+ - type: "null"
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ displayName:
+ type: string
+ minLength: 1
+ enabled:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ organization:
+ anyOf:
+ - type: string
+ - type: "null"
+ parameters:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ pricing:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ releasedAt:
+ anyOf:
+ - type: string
+ - type: "null"
+ sort:
+ anyOf:
+ - type: integer
+ minimum: -9007199254740991
+ maximum: 9007199254740991
+ - type: "null"
+ source:
+ anyOf:
+ - type: string
+ enum:
+ - remote
+ - custom
+ - builtin
+ - type: "null"
+ type:
+ anyOf:
+ - type: string
+ enum:
+ - chat
+ - embedding
+ - tts
+ - asr
+ - image
+ - text2video
+ - text2music
+ - realtime
+ - stt
+ - type: "null"
+ id:
+ type: string
+ minLength: 1
+ maxLength: 150
+ providerId:
+ type: string
+ minLength: 1
+ maxLength: 64
+ required:
+ - displayName
+ - id
+ - providerId
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - models
+ /api/v1/models/{providerId}/{modelId}:
+ get:
+ operationId: getApiV1ModelsByProviderIdByModelId
+ parameters:
+ - in: path
+ name: modelId
+ schema:
+ type: string
+ minLength: 1
+ maxLength: 150
+ required: true
+ - in: path
+ name: providerId
+ schema:
+ type: string
+ minLength: 1
+ maxLength: 64
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - models
+ patch:
+ operationId: patchApiV1ModelsByProviderIdByModelId
+ parameters:
+ - in: path
+ name: modelId
+ schema:
+ type: string
+ minLength: 1
+ maxLength: 150
+ required: true
+ - in: path
+ name: providerId
+ schema:
+ type: string
+ minLength: 1
+ maxLength: 64
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ abilities:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ config:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ contextWindowTokens:
+ anyOf:
+ - type: integer
+ minimum: -9007199254740991
+ maximum: 9007199254740991
+ - type: "null"
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ displayName:
+ type: string
+ minLength: 1
+ enabled:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ organization:
+ anyOf:
+ - type: string
+ - type: "null"
+ parameters:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ pricing:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ - type: "null"
+ releasedAt:
+ anyOf:
+ - type: string
+ - type: "null"
+ sort:
+ anyOf:
+ - type: integer
+ minimum: -9007199254740991
+ maximum: 9007199254740991
+ - type: "null"
+ source:
+ anyOf:
+ - type: string
+ enum:
+ - remote
+ - custom
+ - builtin
+ - type: "null"
+ type:
+ anyOf:
+ - type: string
+ enum:
+ - chat
+ - embedding
+ - tts
+ - asr
+ - image
+ - text2video
+ - text2music
+ - realtime
+ - stt
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - models
+ /api/v1/permissions:
+ get:
+ operationId: getApiV1Permissions
+ parameters:
+ - in: query
+ name: active
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: category
+ schema:
+ anyOf:
+ - type: string
+ minLength: 1
+ - type: "null"
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - permissions
+ post:
+ operationId: postApiV1Permissions
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ category:
+ type: string
+ minLength: 1
+ code:
+ type: string
+ minLength: 1
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ isActive:
+ default: true
+ anyOf:
+ - type: boolean
+ - type: "null"
+ name:
+ type: string
+ minLength: 1
+ required:
+ - category
+ - code
+ - name
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - permissions
+ /api/v1/permissions/{id}:
+ get:
+ operationId: getApiV1PermissionsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 16
+ maxLength: 16
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - permissions
+ patch:
+ operationId: patchApiV1PermissionsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 16
+ maxLength: 16
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ category:
+ type: string
+ minLength: 1
+ code:
+ type: string
+ minLength: 1
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ isActive:
+ default: true
+ anyOf:
+ - type: boolean
+ - type: "null"
+ name:
+ type: string
+ minLength: 1
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - permissions
+ delete:
+ operationId: deleteApiV1PermissionsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 16
+ maxLength: 16
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - permissions
+ /api/v1/providers:
+ get:
+ operationId: getApiV1Providers
+ parameters:
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ - in: query
+ name: enabled
+ schema:
+ type: boolean
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - providers
+ post:
+ operationId: postApiV1Providers
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ checkModel:
+ anyOf:
+ - type: string
+ - type: "null"
+ config:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ enabled:
+ type: boolean
+ fetchOnClient:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ keyVaults:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties:
+ type: string
+ logo:
+ anyOf:
+ - type: string
+ - type: "null"
+ name:
+ anyOf:
+ - type: string
+ minLength: 1
+ - type: "null"
+ settings:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ sort:
+ anyOf:
+ - type: integer
+ minimum: -9007199254740991
+ maximum: 9007199254740991
+ - type: "null"
+ source:
+ type: string
+ enum:
+ - builtin
+ - custom
+ id:
+ type: string
+ minLength: 1
+ required:
+ - id
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - providers
+ /api/v1/providers/{id}:
+ get:
+ operationId: getApiV1ProvidersById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ maxLength: 64
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - providers
+ patch:
+ operationId: patchApiV1ProvidersById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ maxLength: 64
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ checkModel:
+ anyOf:
+ - type: string
+ - type: "null"
+ config:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ enabled:
+ type: boolean
+ fetchOnClient:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ keyVaults:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties:
+ type: string
+ - type: "null"
+ logo:
+ anyOf:
+ - type: string
+ - type: "null"
+ name:
+ anyOf:
+ - type: string
+ minLength: 1
+ - type: "null"
+ settings:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ sort:
+ anyOf:
+ - type: integer
+ minimum: -9007199254740991
+ maximum: 9007199254740991
+ - type: "null"
+ source:
+ type: string
+ enum:
+ - builtin
+ - custom
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - providers
+ delete:
+ operationId: deleteApiV1ProvidersById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ maxLength: 64
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - providers
+ /api/v1/responses:
+ post:
+ operationId: postApiV1Responses
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ input:
+ anyOf:
+ - type: string
+ - type: array
+ items:
+ oneOf:
+ - type: object
+ properties:
+ content:
+ anyOf:
+ - type: string
+ - type: array
+ items:
+ oneOf:
+ - type: object
+ properties:
+ text:
+ type: string
+ type:
+ type: string
+ const: input_text
+ required:
+ - text
+ - type
+ - type: object
+ properties:
+ annotations:
+ type: array
+ items: {}
+ logprobs:
+ type: array
+ items: {}
+ text:
+ type: string
+ type:
+ type: string
+ const: output_text
+ required:
+ - text
+ - type
+ - type: object
+ properties:
+ detail:
+ type: string
+ enum:
+ - auto
+ - low
+ - high
+ image_url:
+ type: string
+ type:
+ type: string
+ const: input_image
+ required:
+ - type
+ - type: object
+ properties:
+ file_data:
+ type: string
+ file_id:
+ type: string
+ filename:
+ type: string
+ type:
+ type: string
+ const: input_file
+ required:
+ - type
+ id:
+ type: string
+ role:
+ type: string
+ enum:
+ - user
+ - assistant
+ - system
+ - developer
+ status:
+ type: string
+ enum:
+ - completed
+ - in_progress
+ type:
+ type: string
+ const: message
+ required:
+ - content
+ - role
+ - type
+ additionalProperties: {}
+ - type: object
+ properties:
+ arguments:
+ type: string
+ call_id:
+ type: string
+ id:
+ type: string
+ name:
+ type: string
+ status:
+ type: string
+ enum:
+ - completed
+ - in_progress
+ type:
+ type: string
+ const: function_call
+ required:
+ - arguments
+ - name
+ - type
+ - type: object
+ properties:
+ call_id:
+ type: string
+ id:
+ type: string
+ output:
+ type: string
+ status:
+ type: string
+ enum:
+ - completed
+ - in_progress
+ - incomplete
+ type:
+ type: string
+ const: function_call_output
+ required:
+ - call_id
+ - output
+ - type
+ instructions:
+ anyOf:
+ - type: string
+ - type: "null"
+ max_output_tokens:
+ anyOf:
+ - type: integer
+ exclusiveMinimum: 0
+ maximum: 9007199254740991
+ - type: "null"
+ metadata:
+ anyOf:
+ - type: object
+ propertyNames:
+ type: string
+ additionalProperties:
+ type: string
+ - type: "null"
+ model:
+ type: string
+ parallel_tool_calls:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ previous_response_id:
+ anyOf:
+ - type: string
+ - type: "null"
+ reasoning:
+ anyOf:
+ - type: object
+ properties:
+ effort:
+ type: string
+ enum:
+ - low
+ - medium
+ - high
+ - type: "null"
+ stream:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ temperature:
+ anyOf:
+ - type: number
+ minimum: 0
+ maximum: 2
+ - type: "null"
+ tool_choice:
+ anyOf:
+ - anyOf:
+ - type: string
+ enum:
+ - auto
+ - required
+ - none
+ - type: object
+ properties:
+ name:
+ type: string
+ type:
+ type: string
+ const: function
+ required:
+ - name
+ - type
+ - type: "null"
+ tools:
+ anyOf:
+ - type: array
+ items:
+ anyOf:
+ - type: object
+ properties:
+ description:
+ type: string
+ name:
+ type: string
+ parameters:
+ type: object
+ propertyNames:
+ type: string
+ additionalProperties: {}
+ strict:
+ type: boolean
+ type:
+ type: string
+ const: function
+ required:
+ - name
+ - type
+ - type: object
+ properties:
+ type:
+ type: string
+ pattern: ^lobe-.*
+ required:
+ - type
+ - type: "null"
+ top_p:
+ anyOf:
+ - type: number
+ minimum: 0
+ maximum: 1
+ - type: "null"
+ truncation:
+ anyOf:
+ - type: object
+ properties:
+ type:
+ default: disabled
+ type: string
+ enum:
+ - auto
+ - disabled
+ - type: "null"
+ user:
+ anyOf:
+ - type: string
+ - type: "null"
+ required:
+ - input
+ - model
+ additionalProperties: {}
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - responses
+ /api/v1/roles:
+ get:
+ operationId: getApiV1Roles
+ parameters:
+ - in: query
+ name: active
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: system
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - roles
+ post:
+ operationId: postApiV1Roles
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ displayName:
+ type: string
+ minLength: 1
+ isActive:
+ default: true
+ anyOf:
+ - type: boolean
+ - type: "null"
+ isSystem:
+ default: false
+ anyOf:
+ - type: boolean
+ - type: "null"
+ name:
+ type: string
+ minLength: 1
+ required:
+ - displayName
+ - name
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - roles
+ /api/v1/roles/{id}:
+ get:
+ operationId: getApiV1RolesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - roles
+ patch:
+ operationId: patchApiV1RolesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ description:
+ anyOf:
+ - type: string
+ - type: "null"
+ displayName:
+ type: string
+ minLength: 1
+ isActive:
+ default: true
+ anyOf:
+ - type: boolean
+ - type: "null"
+ isSystem:
+ default: false
+ anyOf:
+ - type: boolean
+ - type: "null"
+ name:
+ type: string
+ minLength: 1
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - roles
+ delete:
+ operationId: deleteApiV1RolesById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - roles
+ /api/v1/roles/{id}/permissions:
+ get:
+ operationId: getApiV1RolesByIdPermissions
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - roles
+ patch:
+ operationId: patchApiV1RolesByIdPermissions
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ grant:
+ anyOf:
+ - type: array
+ items:
+ type: string
+ minLength: 1
+ - type: "null"
+ revoke:
+ anyOf:
+ - type: array
+ items:
+ type: string
+ minLength: 1
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - roles
+ delete:
+ operationId: deleteApiV1RolesByIdPermissions
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - roles
+ /api/v1/topics:
+ get:
+ operationId: getApiV1Topics
+ parameters:
+ - in: query
+ name: agentId
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: excludeTriggers
+ schema:
+ type: array
+ items:
+ type: string
+ - in: query
+ name: groupId
+ schema:
+ anyOf:
+ - type: string
+ - type: "null"
+ - in: query
+ name: includeTriggers
+ schema:
+ type: array
+ items:
+ type: string
+ - in: query
+ name: isInbox
+ schema:
+ type: string
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - topics
+ post:
+ operationId: postApiV1Topics
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ agentId:
+ anyOf:
+ - type: string
+ - type: "null"
+ clientId:
+ type: string
+ favorite:
+ type: boolean
+ groupId:
+ anyOf:
+ - type: string
+ - type: "null"
+ title:
+ type: string
+ minLength: 1
+ required:
+ - title
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - topics
+ /api/v1/topics/{id}:
+ get:
+ operationId: getApiV1TopicsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - topics
+ patch:
+ operationId: patchApiV1TopicsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ favorite:
+ type: boolean
+ historySummary:
+ type: string
+ metadata:
+ type: object
+ properties:
+ model:
+ type: string
+ provider:
+ type: string
+ boundDeviceId:
+ type: string
+ workingDirectory:
+ type: string
+ title:
+ type: string
+ minLength: 1
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - topics
+ delete:
+ operationId: deleteApiV1TopicsById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - topics
+ /api/v1/users/me:
+ get:
+ operationId: getApiV1UsersMe
+ summary: Get current authenticated user
+ tags:
+ - users
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ /api/v1/users:
+ get:
+ operationId: getApiV1Users
+ parameters:
+ - in: query
+ name: keyword
+ schema:
+ type: string
+ - in: query
+ name: page
+ schema:
+ type: string
+ - in: query
+ name: pageSize
+ schema:
+ type: string
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - users
+ post:
+ operationId: postApiV1Users
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ avatar:
+ anyOf:
+ - type: string
+ - type: "null"
+ email:
+ anyOf:
+ - type: string
+ format: email
+ pattern: ^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$
+ - type: "null"
+ firstName:
+ anyOf:
+ - type: string
+ - type: "null"
+ fullName:
+ anyOf:
+ - type: string
+ - type: "null"
+ id:
+ anyOf:
+ - type: string
+ - type: "null"
+ lastName:
+ anyOf:
+ - type: string
+ - type: "null"
+ phone:
+ anyOf:
+ - type: string
+ - type: "null"
+ roleIds:
+ anyOf:
+ - type: array
+ items:
+ type: string
+ minLength: 1
+ - type: "null"
+ username:
+ anyOf:
+ - type: string
+ minLength: 1
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - users
+ /api/v1/users/{id}:
+ get:
+ operationId: getApiV1UsersById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - users
+ patch:
+ operationId: patchApiV1UsersById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ avatar:
+ anyOf:
+ - type: string
+ - type: "null"
+ email:
+ anyOf:
+ - type: string
+ format: email
+ pattern: ^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$
+ - type: "null"
+ firstName:
+ anyOf:
+ - type: string
+ - type: "null"
+ fullName:
+ anyOf:
+ - type: string
+ - type: "null"
+ isOnboarded:
+ anyOf:
+ - type: boolean
+ - type: "null"
+ lastName:
+ anyOf:
+ - type: string
+ - type: "null"
+ phone:
+ anyOf:
+ - type: string
+ - type: "null"
+ preference:
+ anyOf:
+ - {}
+ - type: "null"
+ roleIds:
+ anyOf:
+ - type: array
+ items:
+ type: string
+ minLength: 1
+ - type: "null"
+ username:
+ anyOf:
+ - type: string
+ minLength: 1
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - users
+ delete:
+ operationId: deleteApiV1UsersById
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - users
+ /api/v1/users/{id}/roles:
+ get:
+ operationId: getApiV1UsersByIdRoles
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - users
+ patch:
+ operationId: patchApiV1UsersByIdRoles
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ addRoles:
+ anyOf:
+ - type: array
+ items:
+ type: object
+ properties:
+ expiresAt:
+ anyOf:
+ - type: string
+ format: date-time
+ pattern: ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
+ - type: "null"
+ roleId:
+ type: string
+ minLength: 1
+ required:
+ - roleId
+ - type: "null"
+ removeRoles:
+ anyOf:
+ - type: array
+ items:
+ type: string
+ minLength: 1
+ - type: "null"
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - users
+ delete:
+ operationId: deleteApiV1UsersByIdRoles
+ parameters:
+ - in: path
+ name: id
+ schema:
+ type: string
+ minLength: 1
+ required: true
+ responses:
+ "200":
+ description: Successful response (schema pending)
+ tags:
+ - users
diff --git a/packages/openapi/package.json b/packages/openapi/package.json
index f1cd06c402a..95276480b08 100644
--- a/packages/openapi/package.json
+++ b/packages/openapi/package.json
@@ -4,22 +4,27 @@
"private": true,
"main": "./src/index.ts",
"scripts": {
+ "generate:openapi": "bun scripts/generate-openapi.ts",
"test:response-compliance": "./scripts/compliance-test.sh"
},
"dependencies": {
+ "@hono/standard-validator": "^0.3.0",
"@hono/zod-validator": "^0.7.6",
"@lobechat/model-runtime": "workspace:*",
"@lobechat/types": "workspace:*",
+ "@scalar/hono-api-reference": "^0.11.12",
"debug": "^4.4.3",
"drizzle-orm": "^0.45.2",
"formidable": "^3.5.4",
"hono": "^4.12.27",
+ "hono-openapi": "^1.3.1",
"js-sha256": "^0.11.1",
"lodash": "^4.18.1",
"url-join": "^5.0.0",
"zod": "^4.4.3"
},
"devDependencies": {
- "@types/formidable": "^3.5.1"
+ "@types/formidable": "^3.5.1",
+ "yaml": "^2.9.0"
}
}
diff --git a/packages/openapi/scripts/generate-openapi.test.ts b/packages/openapi/scripts/generate-openapi.test.ts
new file mode 100644
index 00000000000..b554053fd7f
--- /dev/null
+++ b/packages/openapi/scripts/generate-openapi.test.ts
@@ -0,0 +1,57 @@
+import { execSync } from 'node:child_process';
+import { readFileSync } from 'node:fs';
+import path from 'node:path';
+
+import { describe, expect, it } from 'vitest';
+import { parse } from 'yaml';
+
+const PKG_ROOT = path.join(__dirname, '..');
+
+describe('generate-openapi', () => {
+ it('openapi.yml stays in sync with the registered routes', () => {
+ // Runs the generator in --check mode as a subprocess (the same command CI
+ // and developers use), so the committed spec failing to match the routes
+ // fails this test with the generator's own diagnostics.
+ try {
+ execSync('bun scripts/generate-openapi.ts --check', {
+ cwd: PKG_ROOT,
+ encoding: 'utf8',
+ stdio: 'pipe',
+ });
+ } catch (error) {
+ const execError = error as { stderr?: string; stdout?: string };
+ throw new Error(
+ `openapi.yml is out of date. Run \`bun generate:openapi\` in packages/openapi and commit the result.\n${execError.stderr ?? ''}${execError.stdout ?? ''}`,
+ { cause: error },
+ );
+ }
+ }, 120_000);
+
+ it('committed spec is a valid OpenAPI 3.1 document with full route coverage', () => {
+ const spec = parse(readFileSync(path.join(PKG_ROOT, 'openapi.yml'), 'utf8'));
+
+ expect(spec.openapi).toBe('3.1.0');
+ expect(spec.info.title).toBe('LobeHub API');
+ expect(spec.components.securitySchemes.bearerAuth.scheme).toBe('bearer');
+
+ const operations = Object.values(spec.paths as Record<string, object>).flatMap((item) =>
+ Object.keys(item).filter((method) =>
+ ['delete', 'get', 'patch', 'post', 'put'].includes(method),
+ ),
+ );
+ // 78 business endpoints + /health; grows as routes are added.
+ expect(operations.length).toBeGreaterThanOrEqual(79);
+
+ // Every response object must carry a description (required by OpenAPI).
+ for (const item of Object.values(spec.paths as Record<string, Record<string, any>>)) {
+ for (const op of Object.values(item)) {
+ if (!op.responses) continue;
+ for (const response of Object.values(
+ op.responses as Record<string, { description?: string }>,
+ )) {
+ expect(response.description).toBeTruthy();
+ }
+ }
+ }
+ });
+});
diff --git a/packages/openapi/scripts/generate-openapi.ts b/packages/openapi/scripts/generate-openapi.ts
new file mode 100644
index 00000000000..19dec71581a
--- /dev/null
+++ b/packages/openapi/scripts/generate-openapi.ts
@@ -0,0 +1,94 @@
+/**
+ * Generate the OpenAPI 3.1 spec (openapi.yml) from the live Hono app.
+ *
+ * The document itself is assembled by `src/spec.ts` (shared with the runtime
+ * `GET /api/v1/openapi.json` endpoint). This script adds what the emitter
+ * needs on top: safe env bootstrapping, a parity check that fails when a
+ * registered route is missing from the spec (instead of silently vanishing),
+ * and a `--check` mode for CI.
+ *
+ * Usage:
+ * bun scripts/generate-openapi.ts # regenerate openapi.yml
+ * bun scripts/generate-openapi.ts --check # verify openapi.yml is up to date (CI)
+ */
+import { readFileSync, writeFileSync } from 'node:fs';
+import path from 'node:path';
+
+// Safe defaults so importing the app never touches real infrastructure.
+// NODE_ENV=test makes the database adaptor return a mock instance, and the
+// dummy secrets satisfy import-time env validation in downstream packages.
+// (NODE_ENV is typed read-only, hence Object.assign)
+if (!process.env.NODE_ENV) Object.assign(process.env, { NODE_ENV: 'test' });
+process.env.KEY_VAULTS_SECRET ??= 'openapi-spec-generation';
+process.env.CLOUD_DATABASE_URL ??= 'postgresql://mock:mock@localhost:5432/mock';
+process.env.QSTASH_TOKEN ??= 'mock-qstash-token';
+
+const PKG_ROOT = path.join(import.meta.dirname, '..');
+const SPEC_PATH = path.join(PKG_ROOT, 'openapi.yml');
+const HTTP_METHODS = new Set(['DELETE', 'GET', 'PATCH', 'POST', 'PUT']);
+
+// Documentation-serving routes: real endpoints, deliberately not part of the
+// API surface described by the spec.
+const SPEC_EXEMPT = new Set(['GET /api/v1/docs', 'GET /api/v1/openapi.json']);
+
+// Import after the env defaults above are in place.
+const { honoApp } = await import('../src/app');
+const { buildSpecDocument } = await import('../src/spec');
+const YAML = await import('yaml');
+
+const spec = await buildSpecDocument(honoApp);
+const paths = (spec.paths ?? {}) as Record<string, Record<string, unknown>>;
+
+// ---------- Parity check: every registered route must be in the spec ----------
+const normalize = (routePath: string) => routePath.replaceAll(/:([^/]+)/g, '{$1}');
+
+const registered = new Set(
+ honoApp.routes
+ .filter((r) => HTTP_METHODS.has(r.method))
+ .map((r) => `${r.method} ${normalize(r.path)}`)
+ .filter((endpoint) => !SPEC_EXEMPT.has(endpoint)),
+);
+const documented = new Set(
+ Object.entries(paths).flatMap(([specPath, item]) =>
+ Object.keys(item)
+ .filter((method) => HTTP_METHODS.has(method.toUpperCase()))
+ .map((method) => `${method.toUpperCase()} ${specPath}`),
+ ),
+);
+
+const missing = [...registered].filter((endpoint) => !documented.has(endpoint));
+const extra = [...documented].filter((endpoint) => !registered.has(endpoint));
+
+if (missing.length > 0 || extra.length > 0) {
+ if (missing.length > 0) {
+ console.error(
+ `βœ— ${missing.length} route(s) missing from the spec (no hono-openapi validator/describeRoute attached):`,
+ );
+ for (const endpoint of missing) console.error(` - ${endpoint}`);
+ }
+ for (const endpoint of extra) console.error(` ? documented but not registered: ${endpoint}`);
+ process.exit(1);
+}
+
+// ---------- Emit ----------
+const output = YAML.stringify(spec, { aliasDuplicateObjects: false });
+
+if (process.argv.includes('--check')) {
+ const committed = readFileSync(SPEC_PATH, 'utf8');
+ if (committed !== output) {
+ console.error(
+ 'βœ— openapi.yml is out of date with the routes. Run `bun generate:openapi` in packages/openapi and commit the result.',
+ );
+ process.exit(1);
+ }
+ console.log(`βœ“ openapi.yml is up to date (${documented.size} operations)`);
+} else {
+ writeFileSync(SPEC_PATH, output);
+ console.log(
+ `βœ“ openapi.yml written: ${documented.size} operations, ${Object.keys(paths).length} paths`,
+ );
+}
+
+// The auth middleware registers a cache-cleanup interval at import time,
+// which would otherwise keep the process alive.
+process.exit(0);
diff --git a/packages/openapi/src/app.ts b/packages/openapi/src/app.ts
index 23b34a7d026..99bc2321bf0 100644
--- a/packages/openapi/src/app.ts
+++ b/packages/openapi/src/app.ts
@@ -1,14 +1,20 @@
+import { Scalar } from '@scalar/hono-api-reference';
+import type { Context } from 'hono';
import { Hono } from 'hono';
+import { getCookie } from 'hono/cookie';
import { cors } from 'hono/cors';
import { HTTPException } from 'hono/http-exception';
import { logger } from 'hono/logger';
import { prettyJSON } from 'hono/pretty-json';
+import { describeRoute } from 'hono-openapi';
+import { SCALAR_CUSTOM_CSS } from './docs-theme';
// Import user authentication middleware (supports both OIDC and API Key authentication)
import { userAuthMiddleware } from './middleware/auth';
import { workspaceAuthMiddleware } from './middleware/workspace';
// Import routes
import routes from './routes';
+import { buildSpecDocument } from './spec';
// Create Hono app instance
const app = new Hono().basePath('/api/v1');
@@ -34,7 +40,7 @@ app.onError((error: Error, c) => {
});
// Health check endpoint
-app.get('/health', (c) => {
+app.get('/health', describeRoute({ summary: 'Health check', tags: ['health'] }), (c) => {
return c.json({
service: 'lobe-chat-api',
status: 'ok',
@@ -42,6 +48,59 @@ app.get('/health', (c) => {
});
});
+// API documentation (public, like the API spec itself).
+// The spec is rebuilt from the live routes on first request and cached, so it
+// can never lag behind the deployed code; `openapi.yml` at the package root is
+// the versioned artifact of the same document for SDK generation and diffing.
+let specCache: Awaited<ReturnType<typeof buildSpecDocument>> | null = null;
+app.get('/openapi.json', async (c) => {
+ specCache ??= await buildSpecDocument(app);
+ return c.json(specCache);
+});
+// Scalar ships built-in UI translations for these locales.
+const SCALAR_BUILTIN_LOCALES = ['ar', 'de', 'en', 'es', 'fr', 'ru', 'zh-CN'] as const;
+type ScalarLocale = (typeof SCALAR_BUILTIN_LOCALES)[number];
+
+/**
+ * Resolve the docs UI locale with the same priority the main app uses:
+ * `?hl=` query > `LOBE_LOCALE` cookie > `Accept-Language` header.
+ * Returns undefined for English (Scalar's default) or unsupported locales.
+ */
+const resolveDocsLocale = (c: Context): ScalarLocale | undefined => {
+ const sources = [
+ c.req.query('hl'),
+ getCookie(c, 'LOBE_LOCALE'),
+ c.req.header('Accept-Language'),
+ ].filter(Boolean) as string[];
+
+ for (const source of sources) {
+ for (const candidate of source.split(',')) {
+ const tag = candidate.split(';')[0].trim();
+ if (!tag || tag === 'auto') continue;
+ if (tag.toLowerCase().startsWith('zh')) return 'zh-CN';
+ const match = SCALAR_BUILTIN_LOCALES.find(
+ (locale) => locale === tag || locale === tag.split('-')[0].toLowerCase(),
+ );
+ if (match) return match === 'en' ? undefined : match;
+ }
+ }
+ return undefined;
+};
+
+app.get('/docs', (c, next) => {
+ const locale = resolveDocsLocale(c);
+ return Scalar({
+ customCss: SCALAR_CUSTOM_CSS,
+ favicon: '/favicon.ico',
+ ...(locale ? { localization: { locale } } : {}),
+ pageTitle: 'LobeHub API',
+ // 'none' keeps the runtime bundle from injecting its own theme stylesheet
+ // after our customCss, which would override every variable we set.
+ theme: 'none',
+ url: '/api/v1/openapi.json',
+ })(c, next);
+});
+
// Register routes
Object.entries(routes).forEach(([key, value]) => app.route(`/${key}`, value));
diff --git a/packages/openapi/src/common/validator.ts b/packages/openapi/src/common/validator.ts
new file mode 100644
index 00000000000..93b9084a66d
--- /dev/null
+++ b/packages/openapi/src/common/validator.ts
@@ -0,0 +1,26 @@
+import { validator } from 'hono-openapi';
+
+/**
+ * Drop-in replacement for `@hono/zod-validator`'s `zValidator`, built on
+ * `hono-openapi`'s validator so every request schema is registered into the
+ * generated OpenAPI spec (see `scripts/generate-openapi.ts`).
+ *
+ * The failure hook reproduces `@hono/zod-validator`'s default 400 response
+ * shape (`{ success: false, error: { name: 'ZodError', message } }`) so the
+ * swap is invisible to API consumers.
+ */
+export const zValidator = ((target: never, schema: never) =>
+ validator(target, schema, (result, c) => {
+ if (!result.success) {
+ return c.json(
+ {
+ error: {
+ message: JSON.stringify(result.error, null, 2),
+ name: 'ZodError',
+ },
+ success: false,
+ },
+ 400,
+ );
+ }
+ })) as typeof validator;
diff --git a/packages/openapi/src/docs-theme.ts b/packages/openapi/src/docs-theme.ts
new file mode 100644
index 00000000000..e1a5ba79bea
--- /dev/null
+++ b/packages/openapi/src/docs-theme.ts
@@ -0,0 +1,51 @@
+/**
+ * Scalar theme overrides matching the main app's look: LobeHub's neutral
+ * monochrome palette (black accent on light, white accent on true-black dark)
+ * and the antd system font stack. Applied on top of Scalar's default theme
+ * via `customCss` in `app.ts`.
+ */
+export const SCALAR_CUSTOM_CSS = `
+:root {
+ --scalar-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
+ 'Helvetica Neue', Arial, sans-serif;
+ --scalar-font-code: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo,
+ Courier, monospace;
+ --scalar-radius: 6px;
+ --scalar-radius-lg: 8px;
+ --scalar-radius-xl: 10px;
+}
+
+.light-mode {
+ --scalar-background-1: #ffffff;
+ --scalar-background-2: #fafafa;
+ --scalar-background-3: #f5f5f5;
+ --scalar-background-accent: rgba(0, 0, 0, 0.04);
+ --scalar-border-color: rgba(5, 5, 5, 0.08);
+ --scalar-color-1: rgba(0, 0, 0, 0.88);
+ --scalar-color-2: rgba(0, 0, 0, 0.65);
+ --scalar-color-3: rgba(0, 0, 0, 0.45);
+ --scalar-color-accent: #000000;
+ --scalar-sidebar-background-1: #fafafa;
+ --scalar-sidebar-border-color: rgba(5, 5, 5, 0.08);
+ --scalar-sidebar-color-active: rgba(0, 0, 0, 0.88);
+ --scalar-sidebar-item-active-background: rgba(0, 0, 0, 0.06);
+ --scalar-sidebar-item-hover-background: rgba(0, 0, 0, 0.04);
+}
+
+.dark-mode {
+ --scalar-background-1: #000000;
+ --scalar-background-2: #0a0a0a;
+ --scalar-background-3: #141414;
+ --scalar-background-accent: rgba(255, 255, 255, 0.06);
+ --scalar-border-color: rgba(255, 255, 255, 0.1);
+ --scalar-color-1: rgba(255, 255, 255, 0.9);
+ --scalar-color-2: rgba(255, 255, 255, 0.65);
+ --scalar-color-3: rgba(255, 255, 255, 0.45);
+ --scalar-color-accent: #ffffff;
+ --scalar-sidebar-background-1: #0a0a0a;
+ --scalar-sidebar-border-color: rgba(255, 255, 255, 0.1);
+ --scalar-sidebar-color-active: rgba(255, 255, 255, 0.9);
+ --scalar-sidebar-item-active-background: rgba(255, 255, 255, 0.1);
+ --scalar-sidebar-item-hover-background: rgba(255, 255, 255, 0.06);
+}
+`;
diff --git a/packages/openapi/src/routes/agent-groups.route.ts b/packages/openapi/src/routes/agent-groups.route.ts
index a9f6f829bdd..9eb9e33cebe 100644
--- a/packages/openapi/src/routes/agent-groups.route.ts
+++ b/packages/openapi/src/routes/agent-groups.route.ts
@@ -1,8 +1,9 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
+import { describeRoute } from 'hono-openapi';
import { getAllScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { AgentGroupController } from '../controllers/agent-group.controller';
import { requireAuth } from '../middleware/auth';
import { requireAnyPermission } from '../middleware/permission-check';
@@ -22,8 +23,12 @@ const AgentGroupRoutes = new Hono();
*/
AgentGroupRoutes.get(
'/',
+ describeRoute({ summary: 'Get agent group list', tags: ['agent-groups'] }),
requireAuth,
- requireAnyPermission(getAllScopePermissions('AGENT_READ'), 'You do not have permission to view agent group list'),
+ requireAnyPermission(
+ getAllScopePermissions('AGENT_READ'),
+ 'You do not have permission to view agent group list',
+ ),
async (c) => {
const controller = new AgentGroupController();
return await controller.getAgentGroups(c);
@@ -38,7 +43,10 @@ AgentGroupRoutes.get(
AgentGroupRoutes.post(
'/',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AGENT_CREATE'), 'You do not have permission to create an agent group'),
+ requireAnyPermission(
+ getAllScopePermissions('AGENT_CREATE'),
+ 'You do not have permission to create an agent group',
+ ),
zValidator('json', CreateAgentGroupRequestSchema),
async (c) => {
const controller = new AgentGroupController();
@@ -54,7 +62,10 @@ AgentGroupRoutes.post(
AgentGroupRoutes.get(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AGENT_READ'), 'You do not have permission to view agent group details'),
+ requireAnyPermission(
+ getAllScopePermissions('AGENT_READ'),
+ 'You do not have permission to view agent group details',
+ ),
zValidator('param', AgentGroupIdParamSchema),
async (c) => {
const controller = new AgentGroupController();
@@ -70,7 +81,10 @@ AgentGroupRoutes.get(
AgentGroupRoutes.patch(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AGENT_UPDATE'), 'You do not have permission to update an agent group'),
+ requireAnyPermission(
+ getAllScopePermissions('AGENT_UPDATE'),
+ 'You do not have permission to update an agent group',
+ ),
zValidator('param', AgentGroupIdParamSchema),
zValidator('json', UpdateAgentGroupRequestSchema),
async (c) => {
@@ -91,7 +105,10 @@ AgentGroupRoutes.patch(
AgentGroupRoutes.delete(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AGENT_DELETE'), 'You do not have permission to delete an agent group'),
+ requireAnyPermission(
+ getAllScopePermissions('AGENT_DELETE'),
+ 'You do not have permission to delete an agent group',
+ ),
zValidator('param', AgentGroupIdParamSchema),
async (c) => {
const controller = new AgentGroupController();
diff --git a/packages/openapi/src/routes/agents.route.ts b/packages/openapi/src/routes/agents.route.ts
index a27f6758d84..28b42248c33 100644
--- a/packages/openapi/src/routes/agents.route.ts
+++ b/packages/openapi/src/routes/agents.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getAllScopePermissions, getScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { AgentController } from '../controllers/agent.controller';
import { requireAuth } from '../middleware/auth';
import { requireAnyPermission } from '../middleware/permission-check';
diff --git a/packages/openapi/src/routes/files.route.ts b/packages/openapi/src/routes/files.route.ts
index 8c2f82e5e91..296e8df71d2 100644
--- a/packages/openapi/src/routes/files.route.ts
+++ b/packages/openapi/src/routes/files.route.ts
@@ -1,8 +1,9 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
+import { describeRoute } from 'hono-openapi';
import { getAllScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { FileController } from '../controllers/file.controller';
import { requireAnyPermission } from '../middleware';
import { requireAuth } from '../middleware/auth';
@@ -35,7 +36,10 @@ const app = new Hono();
app.get(
'/',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_READ'), 'You do not have permission to view file list'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_READ'),
+ 'You do not have permission to view file list',
+ ),
zValidator('query', FileListQuerySchema),
async (c) => {
const fileController = new FileController();
@@ -60,8 +64,35 @@ app.get(
*/
app.post(
'/',
+ describeRoute({
+ requestBody: {
+ content: {
+ 'multipart/form-data': {
+ schema: {
+ properties: {
+ agentId: { type: 'string' },
+ directory: { type: 'string' },
+ file: { format: 'binary', type: 'string' },
+ knowledgeBaseId: { type: 'string' },
+ sessionId: { type: 'string' },
+ skipCheckFileType: { type: 'boolean' },
+ skipExist: { type: 'boolean' },
+ },
+ required: ['file'],
+ type: 'object',
+ },
+ },
+ },
+ required: true,
+ },
+ summary: 'Upload a file and return the corresponding file record',
+ tags: ['files'],
+ }),
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_UPLOAD'), 'You do not have permission to upload files'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_UPLOAD'),
+ 'You do not have permission to upload files',
+ ),
async (c) => {
const fileController = new FileController();
return await fileController.uploadFile(c);
@@ -78,7 +109,10 @@ app.post(
app.get(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_READ'), 'You do not have permission to get file details'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_READ'),
+ 'You do not have permission to get file details',
+ ),
zValidator('param', FileIdParamSchema),
async (c) => {
const fileController = new FileController();
@@ -99,7 +133,10 @@ app.get(
app.get(
'/:id/url',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_READ'), 'You do not have permission to get file access URL'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_READ'),
+ 'You do not have permission to get file access URL',
+ ),
zValidator('param', FileIdParamSchema),
zValidator('query', FileUrlRequestSchema),
async (c) => {
@@ -123,7 +160,10 @@ app.get(
app.patch(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_UPDATE'), 'You do not have permission to update a file'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_UPDATE'),
+ 'You do not have permission to update a file',
+ ),
zValidator('param', FileIdParamSchema),
zValidator('json', UpdateFileSchema),
async (c) => {
@@ -142,7 +182,10 @@ app.patch(
app.delete(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_DELETE'), 'You do not have permission to delete a file'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_DELETE'),
+ 'You do not have permission to delete a file',
+ ),
zValidator('param', FileIdParamSchema),
async (c) => {
const fileController = new FileController();
@@ -168,7 +211,10 @@ app.delete(
app.post(
'/:id/parses',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_UPDATE'), 'You do not have permission to parse file content'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_UPDATE'),
+ 'You do not have permission to parse file content',
+ ),
zValidator('param', FileIdParamSchema),
zValidator('query', FileParseRequestSchema),
async (c) => {
@@ -191,7 +237,10 @@ app.post(
app.post(
'/:id/chunks',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_UPDATE'), 'You do not have permission to create chunking tasks'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_UPDATE'),
+ 'You do not have permission to create chunking tasks',
+ ),
zValidator('param', FileIdParamSchema),
zValidator('json', FileChunkRequestSchema),
async (c) => {
@@ -215,7 +264,10 @@ app.post(
app.get(
'/:id/chunks',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_READ'), 'You do not have permission to view file chunking status'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_READ'),
+ 'You do not have permission to view file chunking status',
+ ),
zValidator('param', FileIdParamSchema),
async (c) => {
const fileController = new FileController();
@@ -239,8 +291,35 @@ app.get(
*/
app.post(
'/batches',
+ describeRoute({
+ requestBody: {
+ content: {
+ 'multipart/form-data': {
+ schema: {
+ properties: {
+ agentId: { type: 'string' },
+ directory: { type: 'string' },
+ files: { items: { format: 'binary', type: 'string' }, type: 'array' },
+ knowledgeBaseId: { type: 'string' },
+ sessionId: { type: 'string' },
+ skipCheckFileType: { type: 'boolean' },
+ skipExist: { type: 'boolean' },
+ },
+ required: ['files'],
+ type: 'object',
+ },
+ },
+ },
+ required: true,
+ },
+ summary: 'Batch file upload',
+ tags: ['files'],
+ }),
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_UPLOAD'), 'You do not have permission to batch upload files'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_UPLOAD'),
+ 'You do not have permission to batch upload files',
+ ),
async (c) => {
const fileController = new FileController();
return await fileController.batchUploadFiles(c);
@@ -264,7 +343,10 @@ app.post(
app.post(
'/queries',
requireAuth,
- requireAnyPermission(getAllScopePermissions('FILE_READ'), 'You do not have permission to batch get file details'),
+ requireAnyPermission(
+ getAllScopePermissions('FILE_READ'),
+ 'You do not have permission to batch get file details',
+ ),
zValidator('json', BatchGetFilesRequestSchema),
async (c) => {
const fileController = new FileController();
diff --git a/packages/openapi/src/routes/knowledge-bases.route.ts b/packages/openapi/src/routes/knowledge-bases.route.ts
index 62340c117da..2dd02efdf3e 100644
--- a/packages/openapi/src/routes/knowledge-bases.route.ts
+++ b/packages/openapi/src/routes/knowledge-bases.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getAllScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { KnowledgeBaseController } from '../controllers/knowledge-base.controller';
import { requireAnyPermission } from '../middleware';
import { requireAuth } from '../middleware/auth';
@@ -30,7 +30,10 @@ const app = new Hono();
app.get(
'/',
requireAuth,
- requireAnyPermission(getAllScopePermissions('KNOWLEDGE_BASE_READ'), 'You do not have permission to view knowledge base list'),
+ requireAnyPermission(
+ getAllScopePermissions('KNOWLEDGE_BASE_READ'),
+ 'You do not have permission to view knowledge base list',
+ ),
zValidator('query', KnowledgeBaseListQuerySchema),
async (c) => {
const controller = new KnowledgeBaseController();
@@ -53,7 +56,10 @@ app.get(
app.post(
'/',
requireAuth,
- requireAnyPermission(getAllScopePermissions('KNOWLEDGE_BASE_CREATE'), 'You do not have permission to create a knowledge base'),
+ requireAnyPermission(
+ getAllScopePermissions('KNOWLEDGE_BASE_CREATE'),
+ 'You do not have permission to create a knowledge base',
+ ),
zValidator('json', CreateKnowledgeBaseSchema),
async (c) => {
const controller = new KnowledgeBaseController();
@@ -71,7 +77,10 @@ app.post(
app.get(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('KNOWLEDGE_BASE_READ'), 'You do not have permission to view knowledge base details'),
+ requireAnyPermission(
+ getAllScopePermissions('KNOWLEDGE_BASE_READ'),
+ 'You do not have permission to view knowledge base details',
+ ),
zValidator('param', KnowledgeBaseIdParamSchema),
async (c) => {
const controller = new KnowledgeBaseController();
@@ -97,7 +106,10 @@ app.get(
app.patch(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('KNOWLEDGE_BASE_UPDATE'), 'You do not have permission to update a knowledge base'),
+ requireAnyPermission(
+ getAllScopePermissions('KNOWLEDGE_BASE_UPDATE'),
+ 'You do not have permission to update a knowledge base',
+ ),
zValidator('param', KnowledgeBaseIdParamSchema),
zValidator('json', UpdateKnowledgeBaseSchema),
async (c) => {
@@ -116,7 +128,10 @@ app.patch(
app.delete(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('KNOWLEDGE_BASE_DELETE'), 'You do not have permission to delete a knowledge base'),
+ requireAnyPermission(
+ getAllScopePermissions('KNOWLEDGE_BASE_DELETE'),
+ 'You do not have permission to delete a knowledge base',
+ ),
zValidator('param', KnowledgeBaseIdParamSchema),
async (c) => {
const controller = new KnowledgeBaseController();
@@ -162,7 +177,10 @@ app.get(
app.post(
'/:id/files/batch',
requireAuth,
- requireAnyPermission(getAllScopePermissions('KNOWLEDGE_BASE_UPDATE'), 'You do not have permission to update knowledge base files'),
+ requireAnyPermission(
+ getAllScopePermissions('KNOWLEDGE_BASE_UPDATE'),
+ 'You do not have permission to update knowledge base files',
+ ),
zValidator('param', KnowledgeBaseIdParamSchema),
zValidator('json', KnowledgeBaseFileBatchSchema),
async (c) => {
@@ -178,7 +196,10 @@ app.post(
app.delete(
'/:id/files/batch',
requireAuth,
- requireAnyPermission(getAllScopePermissions('KNOWLEDGE_BASE_UPDATE'), 'You do not have permission to update knowledge base files'),
+ requireAnyPermission(
+ getAllScopePermissions('KNOWLEDGE_BASE_UPDATE'),
+ 'You do not have permission to update knowledge base files',
+ ),
zValidator('param', KnowledgeBaseIdParamSchema),
zValidator('json', KnowledgeBaseFileBatchSchema),
async (c) => {
@@ -194,7 +215,10 @@ app.delete(
app.post(
'/:id/files/move',
requireAuth,
- requireAnyPermission(getAllScopePermissions('KNOWLEDGE_BASE_UPDATE'), 'You do not have permission to update knowledge base files'),
+ requireAnyPermission(
+ getAllScopePermissions('KNOWLEDGE_BASE_UPDATE'),
+ 'You do not have permission to update knowledge base files',
+ ),
zValidator('param', KnowledgeBaseIdParamSchema),
zValidator('json', MoveKnowledgeBaseFilesSchema),
async (c) => {
diff --git a/packages/openapi/src/routes/message-translations.route.ts b/packages/openapi/src/routes/message-translations.route.ts
index 9fef6a100c7..9b0803c36b2 100644
--- a/packages/openapi/src/routes/message-translations.route.ts
+++ b/packages/openapi/src/routes/message-translations.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getAllScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { MessageTranslationController } from '../controllers';
import { requireAuth } from '../middleware';
import { requireAnyPermission } from '../middleware/permission-check';
diff --git a/packages/openapi/src/routes/messages.route.ts b/packages/openapi/src/routes/messages.route.ts
index 3838224632b..0aa31652554 100644
--- a/packages/openapi/src/routes/messages.route.ts
+++ b/packages/openapi/src/routes/messages.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getAllScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { MessageController } from '../controllers';
import { requireAuth } from '../middleware';
import { requireAnyPermission } from '../middleware/permission-check';
diff --git a/packages/openapi/src/routes/models.route.ts b/packages/openapi/src/routes/models.route.ts
index 3fd73c2978a..c2d35060c45 100644
--- a/packages/openapi/src/routes/models.route.ts
+++ b/packages/openapi/src/routes/models.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getAllScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { ModelController } from '../controllers';
import { requireAuth } from '../middleware';
import { requireAnyPermission } from '../middleware/permission-check';
@@ -20,7 +20,10 @@ const ModelRoutes = new Hono();
ModelRoutes.get(
'/',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_MODEL_READ'), 'You do not have permission to view model list'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_MODEL_READ'),
+ 'You do not have permission to view model list',
+ ),
zValidator('query', ModelsListQuerySchema),
(c) => {
const controller = new ModelController();
@@ -32,7 +35,10 @@ ModelRoutes.get(
ModelRoutes.post(
'/',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_MODEL_CREATE'), 'You do not have permission to create a model'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_MODEL_CREATE'),
+ 'You do not have permission to create a model',
+ ),
zValidator('json', CreateModelRequestSchema),
(c) => {
const controller = new ModelController();
@@ -44,7 +50,10 @@ ModelRoutes.post(
ModelRoutes.get(
'/:providerId/:modelId',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_MODEL_READ'), 'You do not have permission to view model details'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_MODEL_READ'),
+ 'You do not have permission to view model details',
+ ),
zValidator('param', ModelIdParamSchema),
(c) => {
const controller = new ModelController();
@@ -56,7 +65,10 @@ ModelRoutes.get(
ModelRoutes.patch(
'/:providerId/:modelId',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_MODEL_UPDATE'), 'You do not have permission to update a model'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_MODEL_UPDATE'),
+ 'You do not have permission to update a model',
+ ),
zValidator('param', ModelIdParamSchema),
zValidator('json', UpdateModelRequestSchema),
(c) => {
diff --git a/packages/openapi/src/routes/permissions.route.ts b/packages/openapi/src/routes/permissions.route.ts
index aaebacb757d..d997e9dbeec 100644
--- a/packages/openapi/src/routes/permissions.route.ts
+++ b/packages/openapi/src/routes/permissions.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { PermissionController } from '../controllers/permission.controller';
import { requireAuth } from '../middleware/auth';
import { requireAnyPermission } from '../middleware/permission-check';
diff --git a/packages/openapi/src/routes/providers.route.ts b/packages/openapi/src/routes/providers.route.ts
index ff103c2aa0b..fbf8ca8ec8c 100644
--- a/packages/openapi/src/routes/providers.route.ts
+++ b/packages/openapi/src/routes/providers.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getAllScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { ProviderController } from '../controllers/provider.controller';
import { requireAuth } from '../middleware/auth';
import { requireAnyPermission } from '../middleware/permission-check';
@@ -18,7 +18,10 @@ const ProviderRoutes = new Hono();
ProviderRoutes.get(
'/',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_PROVIDER_READ'), 'You do not have permission to view provider list'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_PROVIDER_READ'),
+ 'You do not have permission to view provider list',
+ ),
zValidator('query', ProviderListQuerySchema),
(c) => {
const controller = new ProviderController();
@@ -29,7 +32,10 @@ ProviderRoutes.get(
ProviderRoutes.get(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_PROVIDER_READ'), 'You do not have permission to view provider details'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_PROVIDER_READ'),
+ 'You do not have permission to view provider details',
+ ),
zValidator('param', ProviderIdParamSchema),
(c) => {
const controller = new ProviderController();
@@ -40,7 +46,10 @@ ProviderRoutes.get(
ProviderRoutes.post(
'/',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_PROVIDER_CREATE'), 'You do not have permission to create a provider'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_PROVIDER_CREATE'),
+ 'You do not have permission to create a provider',
+ ),
zValidator('json', CreateProviderRequestSchema),
(c) => {
const controller = new ProviderController();
@@ -51,7 +60,10 @@ ProviderRoutes.post(
ProviderRoutes.patch(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_PROVIDER_UPDATE'), 'You do not have permission to update a provider'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_PROVIDER_UPDATE'),
+ 'You do not have permission to update a provider',
+ ),
zValidator('param', ProviderIdParamSchema),
zValidator('json', UpdateProviderRequestSchema),
(c) => {
@@ -63,7 +75,10 @@ ProviderRoutes.patch(
ProviderRoutes.delete(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('AI_PROVIDER_DELETE'), 'You do not have permission to delete a provider'),
+ requireAnyPermission(
+ getAllScopePermissions('AI_PROVIDER_DELETE'),
+ 'You do not have permission to delete a provider',
+ ),
zValidator('param', ProviderIdParamSchema),
(c) => {
const controller = new ProviderController();
diff --git a/packages/openapi/src/routes/responses.route.ts b/packages/openapi/src/routes/responses.route.ts
index 69c33330e86..59736c5bf7d 100644
--- a/packages/openapi/src/routes/responses.route.ts
+++ b/packages/openapi/src/routes/responses.route.ts
@@ -1,6 +1,6 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
+import { zValidator } from '../common/validator';
import { ResponsesController } from '../controllers/responses.controller';
import { requireAuth } from '../middleware/auth';
import { CreateResponseRequestSchema } from '../types/responses.type';
diff --git a/packages/openapi/src/routes/roles.route.ts b/packages/openapi/src/routes/roles.route.ts
index d1096b8376e..17e6190559e 100644
--- a/packages/openapi/src/routes/roles.route.ts
+++ b/packages/openapi/src/routes/roles.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { RoleController } from '../controllers/role.controller';
import { requireAuth } from '../middleware/auth';
import { requireAnyPermission } from '../middleware/permission-check';
@@ -44,7 +44,10 @@ RolesRoutes.get(
RolesRoutes.post(
'/',
requireAuth,
- requireAnyPermission(getScopePermissions('RBAC_ROLE_CREATE', ['ALL']), 'You do not have permission to create a role'),
+ requireAnyPermission(
+ getScopePermissions('RBAC_ROLE_CREATE', ['ALL']),
+ 'You do not have permission to create a role',
+ ),
zValidator('json', CreateRoleRequestSchema),
async (c) => {
const roleController = new RoleController();
@@ -100,7 +103,10 @@ RolesRoutes.get(
RolesRoutes.patch(
'/:id/permissions',
requireAuth,
- requireAnyPermission(getScopePermissions('RBAC_ROLE_UPDATE', ['ALL']), 'You do not have permission to update role permissions'),
+ requireAnyPermission(
+ getScopePermissions('RBAC_ROLE_UPDATE', ['ALL']),
+ 'You do not have permission to update role permissions',
+ ),
zValidator('param', RoleIdParamSchema),
zValidator('json', UpdateRolePermissionsRequestSchema),
async (c) => {
@@ -137,7 +143,10 @@ RolesRoutes.delete(
RolesRoutes.patch(
'/:id',
requireAuth,
- requireAnyPermission(getScopePermissions('RBAC_ROLE_UPDATE', ['ALL']), 'You do not have permission to update role information'),
+ requireAnyPermission(
+ getScopePermissions('RBAC_ROLE_UPDATE', ['ALL']),
+ 'You do not have permission to update role information',
+ ),
zValidator('param', RoleIdParamSchema),
zValidator('json', UpdateRoleRequestSchema),
async (c) => {
@@ -154,7 +163,10 @@ RolesRoutes.patch(
RolesRoutes.delete(
'/:id',
requireAuth,
- requireAnyPermission(getScopePermissions('RBAC_ROLE_DELETE', ['ALL']), 'You do not have permission to delete a role'),
+ requireAnyPermission(
+ getScopePermissions('RBAC_ROLE_DELETE', ['ALL']),
+ 'You do not have permission to delete a role',
+ ),
zValidator('param', RoleIdParamSchema),
async (c) => {
const roleController = new RoleController();
diff --git a/packages/openapi/src/routes/topics.route.ts b/packages/openapi/src/routes/topics.route.ts
index 93241cee6ec..2bebc9ea947 100644
--- a/packages/openapi/src/routes/topics.route.ts
+++ b/packages/openapi/src/routes/topics.route.ts
@@ -1,8 +1,8 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { getAllScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { TopicController } from '../controllers';
import { requireAuth } from '../middleware';
import { requireAnyPermission } from '../middleware/permission-check';
diff --git a/packages/openapi/src/routes/users.route.ts b/packages/openapi/src/routes/users.route.ts
index 6cccd252465..fb79961c82e 100644
--- a/packages/openapi/src/routes/users.route.ts
+++ b/packages/openapi/src/routes/users.route.ts
@@ -1,8 +1,9 @@
-import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
+import { describeRoute } from 'hono-openapi';
import { getAllScopePermissions, getScopePermissions } from '@/utils/rbac';
+import { zValidator } from '../common/validator';
import { UserController } from '../controllers';
import { requireAuth } from '../middleware/auth';
import { requireAnyPermission } from '../middleware/permission-check';
@@ -21,10 +22,15 @@ const UserRoutes = new Hono();
* GET /api/v1/users/me
* Requires authentication but no special permission
*/
-UserRoutes.get('/me', requireAuth, async (c) => {
- const userController = new UserController();
- return await userController.getCurrentUser(c);
-});
+UserRoutes.get(
+ '/me',
+ describeRoute({ summary: 'Get current authenticated user', tags: ['users'] }),
+ requireAuth,
+ async (c) => {
+ const userController = new UserController();
+ return await userController.getCurrentUser(c);
+ },
+);
/**
* Get the list of users in the system (supports search)
@@ -34,7 +40,10 @@ UserRoutes.get('/me', requireAuth, async (c) => {
UserRoutes.get(
'/',
requireAuth,
- requireAnyPermission(getScopePermissions('USER_READ', ['ALL']), 'You do not have permission to view user list'),
+ requireAnyPermission(
+ getScopePermissions('USER_READ', ['ALL']),
+ 'You do not have permission to view user list',
+ ),
zValidator('query', UserSearchRequestSchema),
async (c) => {
const userController = new UserController();
@@ -50,7 +59,10 @@ UserRoutes.get(
UserRoutes.post(
'/',
requireAuth,
- requireAnyPermission(getScopePermissions('USER_CREATE', ['ALL']), 'You do not have permission to create a user'),
+ requireAnyPermission(
+ getScopePermissions('USER_CREATE', ['ALL']),
+ 'You do not have permission to create a user',
+ ),
zValidator('json', CreateUserRequestSchema),
async (c) => {
const userController = new UserController();
@@ -66,7 +78,10 @@ UserRoutes.post(
UserRoutes.get(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('USER_READ'), 'You do not have permission to view user details'),
+ requireAnyPermission(
+ getAllScopePermissions('USER_READ'),
+ 'You do not have permission to view user details',
+ ),
zValidator('param', UserIdParamSchema),
async (c) => {
const userController = new UserController();
@@ -82,7 +97,10 @@ UserRoutes.get(
UserRoutes.patch(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('USER_UPDATE'), 'You do not have permission to update user information'),
+ requireAnyPermission(
+ getAllScopePermissions('USER_UPDATE'),
+ 'You do not have permission to update user information',
+ ),
zValidator('param', UserIdParamSchema),
zValidator('json', UpdateUserRequestSchema),
async (c) => {
@@ -99,7 +117,10 @@ UserRoutes.patch(
UserRoutes.delete(
'/:id',
requireAuth,
- requireAnyPermission(getAllScopePermissions('USER_DELETE'), 'You do not have permission to delete a user'),
+ requireAnyPermission(
+ getAllScopePermissions('USER_DELETE'),
+ 'You do not have permission to delete a user',
+ ),
zValidator('param', UserIdParamSchema),
async (c) => {
const userController = new UserController();
@@ -115,7 +136,10 @@ UserRoutes.delete(
UserRoutes.get(
'/:id/roles',
requireAuth,
- requireAnyPermission(getAllScopePermissions('RBAC_USER_ROLE_READ'), 'You do not have permission to view user roles'),
+ requireAnyPermission(
+ getAllScopePermissions('RBAC_USER_ROLE_READ'),
+ 'You do not have permission to view user roles',
+ ),
zValidator('param', UserIdParamSchema),
async (c) => {
const userController = new UserController();
@@ -131,7 +155,10 @@ UserRoutes.get(
UserRoutes.patch(
'/:id/roles',
requireAuth,
- requireAnyPermission(getAllScopePermissions('RBAC_USER_ROLE_UPDATE'), 'You do not have permission to assign user roles'),
+ requireAnyPermission(
+ getAllScopePermissions('RBAC_USER_ROLE_UPDATE'),
+ 'You do not have permission to assign user roles',
+ ),
zValidator('param', UserIdParamSchema),
zValidator('json', UpdateUserRolesRequestSchema),
async (c) => {
diff --git a/packages/openapi/src/spec.ts b/packages/openapi/src/spec.ts
new file mode 100644
index 00000000000..7b1679fd7de
--- /dev/null
+++ b/packages/openapi/src/spec.ts
@@ -0,0 +1,70 @@
+import { generateSpecs } from 'hono-openapi';
+
+const HTTP_METHODS = new Set(['DELETE', 'GET', 'PATCH', 'POST', 'PUT']);
+
+type GenerateSpecsApp = Parameters<typeof generateSpecs>[0];
+
+interface OperationObject {
+ operationId?: string;
+ responses?: Record<string, unknown>;
+ tags?: string[];
+}
+
+/**
+ * Build the OpenAPI 3.1 document from the live Hono app.
+ *
+ * Shared by the runtime `GET /api/v1/openapi.json` endpoint (see `app.ts`)
+ * and the `scripts/generate-openapi.ts` emitter, so the served spec and the
+ * committed `openapi.yml` always come from the same logic.
+ */
+export const buildSpecDocument = async (app: GenerateSpecsApp) => {
+ const spec = await generateSpecs(app, {
+ documentation: {
+ components: {
+ securitySchemes: {
+ bearerAuth: {
+ bearerFormat: 'API Key (sk-lh-...) or OIDC JWT',
+ scheme: 'bearer',
+ type: 'http',
+ },
+ },
+ },
+ info: {
+ description:
+ 'LobeHub platform REST API. Generated from `packages/openapi` routes β€” do not edit openapi.yml by hand; run `bun generate:openapi` instead.',
+ title: 'LobeHub API',
+ version: '1.0.0',
+ },
+ security: [{ bearerAuth: [] }],
+ servers: [{ description: 'LobeHub Cloud', url: 'https://app.lobehub.com' }],
+ },
+ });
+
+ const paths = (spec.paths ?? {}) as Record<string, Record<string, OperationObject>>;
+
+ for (const [path, item] of Object.entries(paths)) {
+ // '/api/v1/agent-groups/{id}' -> group 'agent-groups', rest '{id}'
+ const segments = path.replace(/^\/api\/v1\/?/, '').split('/');
+ const group = segments[0] || 'root';
+ const rest = segments.slice(1).join('/');
+
+ for (const [method, op] of Object.entries(item)) {
+ if (!HTTP_METHODS.has(method.toUpperCase())) continue;
+
+ op.tags ??= [group];
+ op.operationId ??= `${group}.${method}${rest ? `_${rest.replaceAll(/[{}]/g, '').replaceAll('/', '_')}` : ''}`;
+ // OpenAPI requires a responses object and a description on every response.
+ // Response schemas are still pending (tracked in the spec rollout plan),
+ // so fill placeholders where the routes have not declared them yet.
+ if (!op.responses || Object.keys(op.responses).length === 0) {
+ op.responses = { 200: { description: 'Successful response (schema pending)' } };
+ }
+ for (const response of Object.values(op.responses)) {
+ const responseObject = response as { description?: string };
+ responseObject.description ??= 'Successful response (schema pending)';
+ }
+ }
+ }
+
+ return spec;
+};