feat(web): use generate sdk

This commit is contained in:
Acbox
2026-02-11 15:23:47 +08:00
parent ca86a8d1c3
commit 1f30e666e0
48 changed files with 1670 additions and 722 deletions
+8 -8
View File
@@ -6,15 +6,15 @@ import (
)
type Bot struct {
ID string `json:"id"`
OwnerUserID string `json:"owner_user_id"`
Type string `json:"type"`
DisplayName string `json:"display_name"`
ID string `json:"id" validate:"required"`
OwnerUserID string `json:"owner_user_id" validate:"required"`
Type string `json:"type" validate:"required"`
DisplayName string `json:"display_name" validate:"required"`
AvatarURL string `json:"avatar_url,omitempty"`
IsActive bool `json:"is_active"`
IsActive bool `json:"is_active" validate:"required"`
Metadata map[string]any `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at" validate:"required"`
UpdatedAt time.Time `json:"updated_at" validate:"required"`
}
type BotMember struct {
@@ -49,7 +49,7 @@ type UpsertMemberRequest struct {
}
type ListBotsResponse struct {
Items []Bot `json:"items"`
Items []Bot `json:"items" validate:"required"`
}
type ListMembersResponse struct {
+9 -9
View File
@@ -21,18 +21,18 @@ type AuthHandler struct {
}
type LoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username" validate:"required"`
Password string `json:"password" validate:"required"`
}
type LoginResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresAt string `json:"expires_at"`
UserID string `json:"user_id"`
Role string `json:"role"`
DisplayName string `json:"display_name"`
Username string `json:"username"`
AccessToken string `json:"access_token" validate:"required"`
TokenType string `json:"token_type" validate:"required"`
ExpiresAt string `json:"expires_at" validate:"required"`
UserID string `json:"user_id" validate:"required"`
Role string `json:"role" validate:"required"`
DisplayName string `json:"display_name" validate:"required"`
Username string `json:"username" validate:"required"`
}
func NewAuthHandler(log *slog.Logger, userService *users.Service, jwtSecret string, expiresIn time.Duration) *AuthHandler {
+4 -4
View File
@@ -94,11 +94,11 @@ func (h *ChannelHandler) UpsertUserConfig(c echo.Context) error {
}
type ChannelMeta struct {
Type string `json:"type"`
DisplayName string `json:"display_name"`
Type string `json:"type" validate:"required"`
DisplayName string `json:"display_name" validate:"required"`
Configless bool `json:"configless"`
Capabilities channel.ChannelCapabilities `json:"capabilities"`
ConfigSchema channel.ConfigSchema `json:"config_schema"`
Capabilities channel.ChannelCapabilities `json:"capabilities" validate:"required"`
ConfigSchema channel.ConfigSchema `json:"config_schema" validate:"required"`
UserConfigSchema channel.ConfigSchema `json:"user_config_schema"`
TargetSpec channel.TargetSpec `json:"target_spec"`
}
+2
View File
@@ -47,6 +47,7 @@ func (h *ChatHandler) Register(e *echo.Echo) {
// @Tags chat
// @Accept json
// @Produce json
// @Param bot_id path string true "Bot ID"
// @Param request body chat.ChatRequest true "Chat request"
// @Success 200 {object} chat.ChatResponse
// @Failure 400 {object} ErrorResponse
@@ -102,6 +103,7 @@ func (h *ChatHandler) Chat(c echo.Context) error {
// @Tags chat
// @Accept json
// @Produce text/event-stream
// @Param bot_id path string true "Bot ID"
// @Param request body chat.ChatRequest true "Chat request"
// @Success 200 {string} string
// @Failure 400 {object} ErrorResponse
+5
View File
@@ -46,6 +46,7 @@ func (h *HistoryHandler) Register(e *echo.Echo) {
// @Summary Create history record
// @Description Create a history record for current user
// @Tags history
// @Param bot_id path string true "Bot ID"
// @Param payload body history.CreateRequest true "History payload"
// @Success 201 {object} history.Record
// @Failure 400 {object} ErrorResponse
@@ -82,6 +83,7 @@ func (h *HistoryHandler) Create(c echo.Context) error {
// @Summary Get history record
// @Description Get a history record by ID (must belong to current user)
// @Tags history
// @Param bot_id path string true "Bot ID"
// @Param id path string true "History ID"
// @Success 200 {object} history.Record
// @Failure 400 {object} ErrorResponse
@@ -118,6 +120,7 @@ func (h *HistoryHandler) Get(c echo.Context) error {
// @Summary List history records
// @Description List history records for current user
// @Tags history
// @Param bot_id path string true "Bot ID"
// @Param limit query int false "Limit"
// @Success 200 {object} history.ListResponse
// @Failure 400 {object} ErrorResponse
@@ -156,6 +159,7 @@ func (h *HistoryHandler) List(c echo.Context) error {
// @Summary Delete history record
// @Description Delete a history record by ID (must belong to current user)
// @Tags history
// @Param bot_id path string true "Bot ID"
// @Param id path string true "History ID"
// @Success 204 "No Content"
// @Failure 400 {object} ErrorResponse
@@ -195,6 +199,7 @@ func (h *HistoryHandler) Delete(c echo.Context) error {
// @Summary Delete all history records
// @Description Delete all history records for current user
// @Tags history
// @Param bot_id path string true "Bot ID"
// @Success 204 "No Content"
// @Failure 400 {object} ErrorResponse
// @Failure 500 {object} ErrorResponse
+5
View File
@@ -46,6 +46,7 @@ func (h *MCPHandler) Register(e *echo.Echo) {
// @Summary List MCP connections
// @Description List MCP connections for a bot
// @Tags mcp
// @Param bot_id path string true "Bot ID"
// @Success 200 {object} mcp.ListResponse
// @Failure 400 {object} ErrorResponse
// @Failure 403 {object} ErrorResponse
@@ -75,6 +76,7 @@ func (h *MCPHandler) List(c echo.Context) error {
// @Summary Create MCP connection
// @Description Create a MCP connection for a bot
// @Tags mcp
// @Param bot_id path string true "Bot ID"
// @Param payload body mcp.UpsertRequest true "MCP payload"
// @Success 201 {object} mcp.Connection
// @Failure 400 {object} ErrorResponse
@@ -109,6 +111,7 @@ func (h *MCPHandler) Create(c echo.Context) error {
// @Summary Get MCP connection
// @Description Get a MCP connection by ID
// @Tags mcp
// @Param bot_id path string true "Bot ID"
// @Param id path string true "MCP ID"
// @Success 200 {object} mcp.Connection
// @Failure 400 {object} ErrorResponse
@@ -146,6 +149,7 @@ func (h *MCPHandler) Get(c echo.Context) error {
// @Summary Update MCP connection
// @Description Update a MCP connection by ID
// @Tags mcp
// @Param bot_id path string true "Bot ID"
// @Param id path string true "MCP ID"
// @Param payload body mcp.UpsertRequest true "MCP payload"
// @Success 200 {object} mcp.Connection
@@ -188,6 +192,7 @@ func (h *MCPHandler) Update(c echo.Context) error {
// @Summary Delete MCP connection
// @Description Delete a MCP connection by ID
// @Tags mcp
// @Param bot_id path string true "Bot ID"
// @Param id path string true "MCP ID"
// @Success 204 "No Content"
// @Failure 400 {object} ErrorResponse
+8
View File
@@ -90,6 +90,7 @@ func (h *MemoryHandler) checkService() error {
// @Summary Embed and upsert memory
// @Description Embed text or multimodal input and upsert into memory store. Auth: Bearer JWT determines user_id (sub or user_id).
// @Tags memory
// @Param bot_id path string true "Bot ID"
// @Param payload body memoryEmbedUpsertPayload true "Embed upsert request"
// @Success 200 {object} memory.EmbedUpsertResponse
// @Failure 400 {object} ErrorResponse
@@ -144,6 +145,7 @@ func (h *MemoryHandler) EmbedUpsert(c echo.Context) error {
// @Summary Add memory
// @Description Add memory for a user via memory. Auth: Bearer JWT determines user_id (sub or user_id).
// @Tags memory
// @Param bot_id path string true "Bot ID"
// @Param payload body memoryAddPayload true "Add request"
// @Success 200 {object} memory.SearchResponse
// @Failure 400 {object} ErrorResponse
@@ -197,6 +199,7 @@ func (h *MemoryHandler) Add(c echo.Context) error {
// @Summary Search memories
// @Description Search memories for a user via memory. Auth: Bearer JWT determines user_id (sub or user_id).
// @Tags memory
// @Param bot_id path string true "Bot ID"
// @Param payload body memorySearchPayload true "Search request"
// @Success 200 {object} memory.SearchResponse
// @Failure 400 {object} ErrorResponse
@@ -249,6 +252,7 @@ func (h *MemoryHandler) Search(c echo.Context) error {
// @Summary Update memory
// @Description Update a memory by ID via memory. Auth: Bearer JWT determines user_id (sub or user_id).
// @Tags memory
// @Param bot_id path string true "Bot ID"
// @Param payload body memory.UpdateRequest true "Update request"
// @Success 200 {object} memory.MemoryItem
// @Failure 400 {object} ErrorResponse
@@ -296,6 +300,7 @@ func (h *MemoryHandler) Update(c echo.Context) error {
// @Summary Get memory
// @Description Get a memory by ID via memory. Auth: Bearer JWT determines user_id (sub or user_id).
// @Tags memory
// @Param bot_id path string true "Bot ID"
// @Param memoryId path string true "Memory ID"
// @Success 200 {object} memory.MemoryItem
// @Failure 400 {object} ErrorResponse
@@ -337,6 +342,7 @@ func (h *MemoryHandler) Get(c echo.Context) error {
// @Summary List memories
// @Description List memories for a user via memory. Auth: Bearer JWT determines user_id (sub or user_id).
// @Tags memory
// @Param bot_id path string true "Bot ID"
// @Param run_id query string false "Run ID"
// @Param limit query int false "Limit"
// @Success 200 {object} memory.SearchResponse
@@ -388,6 +394,7 @@ func (h *MemoryHandler) GetAll(c echo.Context) error {
// @Summary Delete memory
// @Description Delete a memory by ID via memory. Auth: Bearer JWT determines user_id (sub or user_id).
// @Tags memory
// @Param bot_id path string true "Bot ID"
// @Param memoryId path string true "Memory ID"
// @Success 200 {object} memory.DeleteResponse
// @Failure 400 {object} ErrorResponse
@@ -434,6 +441,7 @@ func (h *MemoryHandler) Delete(c echo.Context) error {
// @Summary Delete memories
// @Description Delete all memories for a user via memory. Auth: Bearer JWT determines user_id (sub or user_id).
// @Tags memory
// @Param bot_id path string true "Bot ID"
// @Param payload body memoryDeleteAllPayload true "Delete all request"
// @Success 200 {object} memory.DeleteResponse
// @Failure 400 {object} ErrorResponse
+5
View File
@@ -45,6 +45,7 @@ func (h *ScheduleHandler) Register(e *echo.Echo) {
// @Summary Create schedule
// @Description Create a schedule for current user
// @Tags schedule
// @Param bot_id path string true "Bot ID"
// @Param payload body schedule.CreateRequest true "Schedule payload"
// @Success 201 {object} schedule.Schedule
// @Failure 400 {object} ErrorResponse
@@ -77,6 +78,7 @@ func (h *ScheduleHandler) Create(c echo.Context) error {
// @Summary List schedules
// @Description List schedules for current user
// @Tags schedule
// @Param bot_id path string true "Bot ID"
// @Success 200 {object} schedule.ListResponse
// @Failure 400 {object} ErrorResponse
// @Failure 500 {object} ErrorResponse
@@ -104,6 +106,7 @@ func (h *ScheduleHandler) List(c echo.Context) error {
// @Summary Get schedule
// @Description Get a schedule by ID
// @Tags schedule
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Schedule ID"
// @Success 200 {object} schedule.Schedule
// @Failure 400 {object} ErrorResponse
@@ -140,6 +143,7 @@ func (h *ScheduleHandler) Get(c echo.Context) error {
// @Summary Update schedule
// @Description Update a schedule by ID
// @Tags schedule
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Schedule ID"
// @Param payload body schedule.UpdateRequest true "Schedule payload"
// @Success 200 {object} schedule.Schedule
@@ -184,6 +188,7 @@ func (h *ScheduleHandler) Update(c echo.Context) error {
// @Summary Delete schedule
// @Description Delete a schedule by ID
// @Tags schedule
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Schedule ID"
// @Success 204 "No Content"
// @Failure 400 {object} ErrorResponse
+3
View File
@@ -44,6 +44,7 @@ func (h *SettingsHandler) Register(e *echo.Echo) {
// @Summary Get user settings
// @Description Get agent settings for current user
// @Tags settings
// @Param bot_id path string true "Bot ID"
// @Success 200 {object} settings.Settings
// @Failure 400 {object} ErrorResponse
// @Failure 500 {object} ErrorResponse
@@ -71,6 +72,7 @@ func (h *SettingsHandler) Get(c echo.Context) error {
// @Summary Update user settings
// @Description Update or create agent settings for current user
// @Tags settings
// @Param bot_id path string true "Bot ID"
// @Param payload body settings.UpsertRequest true "Settings payload"
// @Success 200 {object} settings.Settings
// @Failure 400 {object} ErrorResponse
@@ -104,6 +106,7 @@ func (h *SettingsHandler) Upsert(c echo.Context) error {
// @Summary Delete user settings
// @Description Remove agent settings for current user
// @Tags settings
// @Param bot_id path string true "Bot ID"
// @Success 204 "No Content"
// @Failure 400 {object} ErrorResponse
// @Failure 500 {object} ErrorResponse
+10
View File
@@ -50,6 +50,7 @@ func (h *SubagentHandler) Register(e *echo.Echo) {
// @Summary Create subagent
// @Description Create a subagent for current user
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param payload body subagent.CreateRequest true "Subagent payload"
// @Success 201 {object} subagent.Subagent
// @Failure 400 {object} ErrorResponse
@@ -82,6 +83,7 @@ func (h *SubagentHandler) Create(c echo.Context) error {
// @Summary List subagents
// @Description List subagents for current user
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Success 200 {object} subagent.ListResponse
// @Failure 400 {object} ErrorResponse
// @Failure 500 {object} ErrorResponse
@@ -109,6 +111,7 @@ func (h *SubagentHandler) List(c echo.Context) error {
// @Summary Get subagent
// @Description Get a subagent by ID
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Subagent ID"
// @Success 200 {object} subagent.Subagent
// @Failure 400 {object} ErrorResponse
@@ -145,6 +148,7 @@ func (h *SubagentHandler) Get(c echo.Context) error {
// @Summary Update subagent
// @Description Update a subagent by ID
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Subagent ID"
// @Param payload body subagent.UpdateRequest true "Subagent payload"
// @Success 200 {object} subagent.Subagent
@@ -190,6 +194,7 @@ func (h *SubagentHandler) Update(c echo.Context) error {
// @Summary Delete subagent
// @Description Delete a subagent by ID
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Subagent ID"
// @Success 204 "No Content"
// @Failure 400 {object} ErrorResponse
@@ -229,6 +234,7 @@ func (h *SubagentHandler) Delete(c echo.Context) error {
// @Summary Get subagent context
// @Description Get a subagent's message context
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Subagent ID"
// @Success 200 {object} subagent.ContextResponse
// @Failure 400 {object} ErrorResponse
@@ -265,6 +271,7 @@ func (h *SubagentHandler) GetContext(c echo.Context) error {
// @Summary Update subagent context
// @Description Update a subagent's message context
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Subagent ID"
// @Param payload body subagent.UpdateContextRequest true "Context payload"
// @Success 200 {object} subagent.ContextResponse
@@ -310,6 +317,7 @@ func (h *SubagentHandler) UpdateContext(c echo.Context) error {
// @Summary Get subagent skills
// @Description Get a subagent's skills
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Subagent ID"
// @Success 200 {object} subagent.SkillsResponse
// @Failure 400 {object} ErrorResponse
@@ -346,6 +354,7 @@ func (h *SubagentHandler) GetSkills(c echo.Context) error {
// @Summary Update subagent skills
// @Description Replace a subagent's skills
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Subagent ID"
// @Param payload body subagent.UpdateSkillsRequest true "Skills payload"
// @Success 200 {object} subagent.SkillsResponse
@@ -391,6 +400,7 @@ func (h *SubagentHandler) UpdateSkills(c echo.Context) error {
// @Summary Add subagent skills
// @Description Add skills to a subagent
// @Tags subagent
// @Param bot_id path string true "Bot ID"
// @Param id path string true "Subagent ID"
// @Param payload body subagent.AddSkillsRequest true "Skills payload"
// @Success 200 {object} subagent.SkillsResponse
+8 -8
View File
@@ -14,14 +14,14 @@ import (
// Connection represents a stored MCP connection for a bot.
type Connection struct {
ID string `json:"id"`
BotID string `json:"bot_id"`
Name string `json:"name"`
Type string `json:"type"`
Config map[string]any `json:"config"`
Active bool `json:"active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID string `json:"id" validate:"required"`
BotID string `json:"bot_id" validate:"required"`
Name string `json:"name" validate:"required"`
Type string `json:"type" validate:"required"`
Config map[string]any `json:"config" validate:"required"`
Active bool `json:"active" validate:"required"`
CreatedAt time.Time `json:"created_at" validate:"required"`
UpdatedAt time.Time `json:"updated_at" validate:"required"`
}
// UpsertRequest is the payload for creating or updating MCP connections.
+7 -7
View File
@@ -32,13 +32,13 @@ const (
)
type Model struct {
ModelID string `json:"model_id"`
Name string `json:"name"`
LlmProviderID string `json:"llm_provider_id"`
IsMultimodal bool `json:"is_multimodal"`
Input []string `json:"input"`
Type ModelType `json:"type"`
Dimensions int `json:"dimensions"`
ModelID string `json:"model_id" validate:"required"`
Name string `json:"name" validate:"required"`
LlmProviderID string `json:"llm_provider_id" validate:"required"`
IsMultimodal bool `json:"is_multimodal"`
Input []string `json:"input"`
Type ModelType `json:"type" validate:"required"`
Dimensions int `json:"dimensions"`
}
func (m *Model) Validate() error {
+6 -6
View File
@@ -33,14 +33,14 @@ type UpdateRequest struct {
// GetResponse represents the response for getting a provider
type GetResponse struct {
ID string `json:"id"`
Name string `json:"name"`
ClientType string `json:"client_type"`
BaseURL string `json:"base_url"`
ID string `json:"id" validate:"required"`
Name string `json:"name" validate:"required"`
ClientType string `json:"client_type" validate:"required"`
BaseURL string `json:"base_url" validate:"required"`
APIKey string `json:"api_key,omitempty"` // masked in response
Metadata map[string]any `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at" validate:"required"`
UpdatedAt time.Time `json:"updated_at" validate:"required"`
}
// ListResponse represents the response for listing providers
+6 -6
View File
@@ -6,12 +6,12 @@ const (
)
type Settings struct {
ChatModelID string `json:"chat_model_id"`
MemoryModelID string `json:"memory_model_id"`
EmbeddingModelID string `json:"embedding_model_id"`
MaxContextLoadTime int `json:"max_context_load_time"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID string `json:"chat_model_id" validate:"required"`
MemoryModelID string `json:"memory_model_id" validate:"required"`
EmbeddingModelID string `json:"embedding_model_id" validate:"required"`
MaxContextLoadTime int `json:"max_context_load_time" validate:"required"`
Language string `json:"language" validate:"required"`
AllowGuest bool `json:"allow_guest" validate:"required"`
}
type UpsertRequest struct {