refactor: restructure channel gateway and chat module architecture

- Refactor channel adapters (feishu, telegram, local) with enhanced descriptor and config
- Restructure channel manager, service, types, and outbound messaging
- Simplify chat module by removing normalize.go and chat.go, consolidating into resolver and types
- Update router channel handlers and tests
- Sync swagger documentation
This commit is contained in:
BBQ
2026-02-06 20:22:37 +08:00
parent c3cfdc4096
commit a246b79a4f
42 changed files with 1683 additions and 1745 deletions
+173 -65
View File
@@ -241,6 +241,41 @@ const docTemplate = `{
}
},
"/bots/{bot_id}/container": {
"get": {
"tags": [
"containerd"
],
"summary": "Get container info for bot",
"parameters": [
{
"type": "string",
"description": "Bot ID",
"name": "bot_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handlers.GetContainerResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
},
"post": {
"tags": [
"containerd"
@@ -284,14 +319,12 @@ const docTemplate = `{
}
}
}
}
},
"/bots/{bot_id}/container/list": {
"get": {
},
"delete": {
"tags": [
"containerd"
],
"summary": "List containers for bot",
"summary": "Delete MCP container for bot",
"parameters": [
{
"type": "string",
@@ -302,10 +335,13 @@ const docTemplate = `{
}
],
"responses": {
"200": {
"description": "OK",
"204": {
"description": "No Content"
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ListContainersResponse"
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
@@ -351,7 +387,7 @@ const docTemplate = `{
"tags": [
"containerd"
],
"summary": "Create container snapshot",
"summary": "Create container snapshot for bot",
"parameters": [
{
"type": "string",
@@ -376,16 +412,28 @@ const docTemplate = `{
"schema": {
"$ref": "#/definitions/handlers.CreateSnapshotResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/bots/{bot_id}/container/{id}": {
"delete": {
"/bots/{bot_id}/container/start": {
"post": {
"tags": [
"containerd"
],
"summary": "Delete MCP container",
"summary": "Start container task for bot",
"parameters": [
{
"type": "string",
@@ -393,23 +441,50 @@ const docTemplate = `{
"name": "bot_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/bots/{bot_id}/container/stop": {
"post": {
"tags": [
"containerd"
],
"summary": "Stop container task for bot",
"parameters": [
{
"type": "string",
"description": "Container ID",
"name": "id",
"description": "Bot ID",
"name": "bot_id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
},
"400": {
"description": "Bad Request",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
"type": "object"
}
},
"404": {
@@ -4494,7 +4569,7 @@ const docTemplate = `{
"messages": {
"type": "array",
"items": {
"$ref": "#/definitions/chat.GatewayMessage"
"$ref": "#/definitions/chat.ModelMessage"
}
},
"model": {
@@ -4520,7 +4595,7 @@ const docTemplate = `{
"messages": {
"type": "array",
"items": {
"$ref": "#/definitions/chat.GatewayMessage"
"$ref": "#/definitions/chat.ModelMessage"
}
},
"model": {
@@ -4537,9 +4612,56 @@ const docTemplate = `{
}
}
},
"chat.GatewayMessage": {
"chat.ModelMessage": {
"type": "object",
"additionalProperties": {}
"properties": {
"content": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
},
"role": {
"type": "string"
},
"tool_call_id": {
"type": "string"
},
"tool_calls": {
"type": "array",
"items": {
"$ref": "#/definitions/chat.ToolCall"
}
}
}
},
"chat.ToolCall": {
"type": "object",
"properties": {
"function": {
"$ref": "#/definitions/chat.ToolCallFunction"
},
"id": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"chat.ToolCallFunction": {
"type": "object",
"properties": {
"arguments": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"handlers.ChannelMeta": {
"type": "object",
@@ -4567,41 +4689,9 @@ const docTemplate = `{
}
}
},
"handlers.ContainerInfo": {
"type": "object",
"properties": {
"created_at": {
"type": "string"
},
"id": {
"type": "string"
},
"image": {
"type": "string"
},
"labels": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"snapshot_key": {
"type": "string"
},
"snapshotter": {
"type": "string"
},
"updated_at": {
"type": "string"
}
}
},
"handlers.CreateContainerRequest": {
"type": "object",
"properties": {
"container_id": {
"type": "string"
},
"image": {
"type": "string"
},
@@ -4630,9 +4720,6 @@ const docTemplate = `{
"handlers.CreateSnapshotRequest": {
"type": "object",
"properties": {
"container_id": {
"type": "string"
},
"snapshot_name": {
"type": "string"
}
@@ -4748,14 +4835,35 @@ const docTemplate = `{
}
}
},
"handlers.ListContainersResponse": {
"handlers.GetContainerResponse": {
"type": "object",
"properties": {
"containers": {
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ContainerInfo"
}
"container_id": {
"type": "string"
},
"container_path": {
"type": "string"
},
"created_at": {
"type": "string"
},
"host_path": {
"type": "string"
},
"image": {
"type": "string"
},
"namespace": {
"type": "string"
},
"status": {
"type": "string"
},
"task_running": {
"type": "boolean"
},
"updated_at": {
"type": "string"
}
}
},
+173 -65
View File
@@ -232,6 +232,41 @@
}
},
"/bots/{bot_id}/container": {
"get": {
"tags": [
"containerd"
],
"summary": "Get container info for bot",
"parameters": [
{
"type": "string",
"description": "Bot ID",
"name": "bot_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handlers.GetContainerResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
},
"post": {
"tags": [
"containerd"
@@ -275,14 +310,12 @@
}
}
}
}
},
"/bots/{bot_id}/container/list": {
"get": {
},
"delete": {
"tags": [
"containerd"
],
"summary": "List containers for bot",
"summary": "Delete MCP container for bot",
"parameters": [
{
"type": "string",
@@ -293,10 +326,13 @@
}
],
"responses": {
"200": {
"description": "OK",
"204": {
"description": "No Content"
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ListContainersResponse"
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
@@ -342,7 +378,7 @@
"tags": [
"containerd"
],
"summary": "Create container snapshot",
"summary": "Create container snapshot for bot",
"parameters": [
{
"type": "string",
@@ -367,16 +403,28 @@
"schema": {
"$ref": "#/definitions/handlers.CreateSnapshotResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/bots/{bot_id}/container/{id}": {
"delete": {
"/bots/{bot_id}/container/start": {
"post": {
"tags": [
"containerd"
],
"summary": "Delete MCP container",
"summary": "Start container task for bot",
"parameters": [
{
"type": "string",
@@ -384,23 +432,50 @@
"name": "bot_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/bots/{bot_id}/container/stop": {
"post": {
"tags": [
"containerd"
],
"summary": "Stop container task for bot",
"parameters": [
{
"type": "string",
"description": "Container ID",
"name": "id",
"description": "Bot ID",
"name": "bot_id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
},
"400": {
"description": "Bad Request",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
"type": "object"
}
},
"404": {
@@ -4485,7 +4560,7 @@
"messages": {
"type": "array",
"items": {
"$ref": "#/definitions/chat.GatewayMessage"
"$ref": "#/definitions/chat.ModelMessage"
}
},
"model": {
@@ -4511,7 +4586,7 @@
"messages": {
"type": "array",
"items": {
"$ref": "#/definitions/chat.GatewayMessage"
"$ref": "#/definitions/chat.ModelMessage"
}
},
"model": {
@@ -4528,9 +4603,56 @@
}
}
},
"chat.GatewayMessage": {
"chat.ModelMessage": {
"type": "object",
"additionalProperties": {}
"properties": {
"content": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
},
"role": {
"type": "string"
},
"tool_call_id": {
"type": "string"
},
"tool_calls": {
"type": "array",
"items": {
"$ref": "#/definitions/chat.ToolCall"
}
}
}
},
"chat.ToolCall": {
"type": "object",
"properties": {
"function": {
"$ref": "#/definitions/chat.ToolCallFunction"
},
"id": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"chat.ToolCallFunction": {
"type": "object",
"properties": {
"arguments": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"handlers.ChannelMeta": {
"type": "object",
@@ -4558,41 +4680,9 @@
}
}
},
"handlers.ContainerInfo": {
"type": "object",
"properties": {
"created_at": {
"type": "string"
},
"id": {
"type": "string"
},
"image": {
"type": "string"
},
"labels": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"snapshot_key": {
"type": "string"
},
"snapshotter": {
"type": "string"
},
"updated_at": {
"type": "string"
}
}
},
"handlers.CreateContainerRequest": {
"type": "object",
"properties": {
"container_id": {
"type": "string"
},
"image": {
"type": "string"
},
@@ -4621,9 +4711,6 @@
"handlers.CreateSnapshotRequest": {
"type": "object",
"properties": {
"container_id": {
"type": "string"
},
"snapshot_name": {
"type": "string"
}
@@ -4739,14 +4826,35 @@
}
}
},
"handlers.ListContainersResponse": {
"handlers.GetContainerResponse": {
"type": "object",
"properties": {
"containers": {
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ContainerInfo"
}
"container_id": {
"type": "string"
},
"container_path": {
"type": "string"
},
"created_at": {
"type": "string"
},
"host_path": {
"type": "string"
},
"image": {
"type": "string"
},
"namespace": {
"type": "string"
},
"status": {
"type": "string"
},
"task_running": {
"type": "boolean"
},
"updated_at": {
"type": "string"
}
}
},
+154 -84
View File
@@ -428,7 +428,7 @@ definitions:
type: integer
messages:
items:
$ref: '#/definitions/chat.GatewayMessage'
$ref: '#/definitions/chat.ModelMessage'
type: array
model:
type: string
@@ -445,7 +445,7 @@ definitions:
properties:
messages:
items:
$ref: '#/definitions/chat.GatewayMessage'
$ref: '#/definitions/chat.ModelMessage'
type: array
model:
type: string
@@ -456,8 +456,38 @@ definitions:
type: string
type: array
type: object
chat.GatewayMessage:
additionalProperties: {}
chat.ModelMessage:
properties:
content:
items:
type: integer
type: array
name:
type: string
role:
type: string
tool_call_id:
type: string
tool_calls:
items:
$ref: '#/definitions/chat.ToolCall'
type: array
type: object
chat.ToolCall:
properties:
function:
$ref: '#/definitions/chat.ToolCallFunction'
id:
type: string
type:
type: string
type: object
chat.ToolCallFunction:
properties:
arguments:
type: string
name:
type: string
type: object
handlers.ChannelMeta:
properties:
@@ -476,29 +506,8 @@ definitions:
user_config_schema:
$ref: '#/definitions/channel.ConfigSchema'
type: object
handlers.ContainerInfo:
properties:
created_at:
type: string
id:
type: string
image:
type: string
labels:
additionalProperties:
type: string
type: object
snapshot_key:
type: string
snapshotter:
type: string
updated_at:
type: string
type: object
handlers.CreateContainerRequest:
properties:
container_id:
type: string
image:
type: string
snapshotter:
@@ -517,8 +526,6 @@ definitions:
type: object
handlers.CreateSnapshotRequest:
properties:
container_id:
type: string
snapshot_name:
type: string
type: object
@@ -593,12 +600,26 @@ definitions:
message:
type: string
type: object
handlers.ListContainersResponse:
handlers.GetContainerResponse:
properties:
containers:
items:
$ref: '#/definitions/handlers.ContainerInfo'
type: array
container_id:
type: string
container_path:
type: string
created_at:
type: string
host_path:
type: string
image:
type: string
namespace:
type: string
status:
type: string
task_running:
type: boolean
updated_at:
type: string
type: object
handlers.ListSnapshotsResponse:
properties:
@@ -1458,6 +1479,50 @@ paths:
tags:
- chat
/bots/{bot_id}/container:
delete:
parameters:
- description: Bot ID
in: path
name: bot_id
required: true
type: string
responses:
"204":
description: No Content
"404":
description: Not Found
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ErrorResponse'
summary: Delete MCP container for bot
tags:
- containerd
get:
parameters:
- description: Bot ID
in: path
name: bot_id
required: true
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handlers.GetContainerResponse'
"404":
description: Not Found
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ErrorResponse'
summary: Get container info for bot
tags:
- containerd
post:
parameters:
- description: Bot ID
@@ -1487,57 +1552,6 @@ paths:
summary: Create and start MCP container for bot
tags:
- containerd
/bots/{bot_id}/container/{id}:
delete:
parameters:
- description: Bot ID
in: path
name: bot_id
required: true
type: string
- description: Container ID
in: path
name: id
required: true
type: string
responses:
"204":
description: No Content
"400":
description: Bad Request
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"404":
description: Not Found
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ErrorResponse'
summary: Delete MCP container
tags:
- containerd
/bots/{bot_id}/container/list:
get:
parameters:
- description: Bot ID
in: path
name: bot_id
required: true
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handlers.ListContainersResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ErrorResponse'
summary: List containers for bot
tags:
- containerd
/bots/{bot_id}/container/snapshots:
get:
parameters:
@@ -1576,7 +1590,63 @@ paths:
description: OK
schema:
$ref: '#/definitions/handlers.CreateSnapshotResponse'
summary: Create container snapshot
"404":
description: Not Found
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ErrorResponse'
summary: Create container snapshot for bot
tags:
- containerd
/bots/{bot_id}/container/start:
post:
parameters:
- description: Bot ID
in: path
name: bot_id
required: true
type: string
responses:
"200":
description: OK
schema:
type: object
"404":
description: Not Found
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ErrorResponse'
summary: Start container task for bot
tags:
- containerd
/bots/{bot_id}/container/stop:
post:
parameters:
- description: Bot ID
in: path
name: bot_id
required: true
type: string
responses:
"200":
description: OK
schema:
type: object
"404":
description: Not Found
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ErrorResponse'
summary: Stop container task for bot
tags:
- containerd
/bots/{bot_id}/history: