Files
MyGoNavi/internal/ai/types.go
Syngnat 98e9e5686d feat(ai): 发布全新 AI Copilot 助手面板与工作区智能打通
- 核心架构:新增独立 AI 会话中枢,集成主流大模型生态(含私有部署中继版)的无感衔接发问
- 智能诊断:打破信息孤岛,大模型可通过关联工作区实时数据表 DDL 和错误栈,充当专属 DBA 排错及代码编写
- 视觉与多模态:支持极简发图读图交互体验,智能补全模型所需的缺省预警 Prompt,并兼容不规范中转端点图文并茂
- UI 与性能:重构聊天浮层挂靠逻辑与渲染阻断,应对长时间巨量问答引发的卡段内存泄漏,会话自动保存归档
2026-03-26 16:02:08 +08:00

116 lines
3.8 KiB
Go

package ai
// ToolCall 表示 AI 发出的工具调用
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"` // "function"
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
}
// ToolFunction 表示可使用的函数定义
type ToolFunction struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters any `json:"parameters"` // JSON Schema definitions
}
// Tool 工具申明
type Tool struct {
Type string `json:"type"` // "function"
Function ToolFunction `json:"function"`
}
// Message 表示一条对话消息
type Message struct {
Role string `json:"role"` // "system" | "user" | "assistant" | "tool"
Content string `json:"content"`
Images []string `json:"images,omitempty"` // base64 encoded images with data:image/png;base64,... prefix
ToolCallID string `json:"tool_call_id,omitempty"` // 当 role 为 "tool" 时必须传递
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // 当 role 为 "assistant" 并试图调工具时传递
}
// ChatRequest AI 对话请求
type ChatRequest struct {
Messages []Message `json:"messages"`
Temperature float64 `json:"temperature"`
MaxTokens int `json:"maxTokens"`
Tools []Tool `json:"tools,omitempty"`
}
// ChatResponse AI 对话响应
type ChatResponse struct {
Content string `json:"content"`
TokensUsed TokenUsage `json:"tokensUsed"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
// TokenUsage token 用量统计
type TokenUsage struct {
PromptTokens int `json:"promptTokens"`
CompletionTokens int `json:"completionTokens"`
TotalTokens int `json:"totalTokens"`
}
// StreamChunk 流式响应片段
type StreamChunk struct {
Content string `json:"content"`
Thinking string `json:"thinking,omitempty"`
Done bool `json:"done"`
Error string `json:"error,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
// ProviderConfig AI Provider 配置
type ProviderConfig struct {
ID string `json:"id"`
Type string `json:"type"` // openai | anthropic | gemini | custom
Name string `json:"name"`
APIKey string `json:"apiKey"`
BaseURL string `json:"baseUrl"`
Model string `json:"model"`
Models []string `json:"models,omitempty"`
APIFormat string `json:"apiFormat,omitempty"` // custom 专用: openai | anthropic | gemini
Headers map[string]string `json:"headers,omitempty"`
MaxTokens int `json:"maxTokens"`
Temperature float64 `json:"temperature"`
}
// SQLPermissionLevel AI SQL 执行权限级别
type SQLPermissionLevel string
const (
PermissionReadOnly SQLPermissionLevel = "readonly"
PermissionReadWrite SQLPermissionLevel = "readwrite"
PermissionFull SQLPermissionLevel = "full"
)
// ContextLevel AI 上下文传递级别
type ContextLevel string
const (
ContextSchemaOnly ContextLevel = "schema_only"
ContextWithSamples ContextLevel = "with_samples"
ContextWithResults ContextLevel = "with_results"
)
// SQLOperationType SQL 操作类型
type SQLOperationType string
const (
SQLOpQuery SQLOperationType = "query" // SELECT, SHOW, DESCRIBE, EXPLAIN
SQLOpDML SQLOperationType = "dml" // INSERT, UPDATE, DELETE
SQLOpDDL SQLOperationType = "ddl" // CREATE, ALTER, DROP, TRUNCATE
SQLOpOther SQLOperationType = "other"
)
// SafetyResult 安全检查结果
type SafetyResult struct {
Allowed bool `json:"allowed"`
OperationType SQLOperationType `json:"operationType"`
RequiresConfirm bool `json:"requiresConfirm"`
WarningMessage string `json:"warningMessage,omitempty"`
}