Files
MyGoNavi/internal/ai/types.go
Syngnat 1bda751ada feat(ai-chat): 全面升级AI聊天面板并优化交互体验
- 消息管理:新增聊天气泡的重试、编辑与单条删除功能及相对应的持久化状态函数
- 快捷操作:支持长文一键滑动到底端,并在代码块内增加SQL一键送入编辑器的快捷执行机制
- 视觉优化:深化AI回复背景沉浸感,重绘AI洞察按钮并移除设置面板所有的冗余紫色调
- 设置调优:放宽模型初始必填限制,新增内置系统提示词(Builtin Prompt)全览面板
2026-03-22 20:54:29 +08:00

86 lines
2.6 KiB
Go

package ai
// Message 表示一条对话消息
type Message struct {
Role string `json:"role"` // "system" | "user" | "assistant"
Content string `json:"content"`
}
// ChatRequest AI 对话请求
type ChatRequest struct {
Messages []Message `json:"messages"`
Temperature float64 `json:"temperature"`
MaxTokens int `json:"maxTokens"`
}
// ChatResponse AI 对话响应
type ChatResponse struct {
Content string `json:"content"`
TokensUsed TokenUsage `json:"tokensUsed"`
}
// 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"`
Done bool `json:"done"`
Error string `json:"error,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"`
}