mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-13 00:13:33 +08:00
- 面板底部新增思考强度选择,按服务商 profile 动态选项 - ChatSendOptions 支持 thinkingIntensity,仅本次发送生效 - 从供应商表单移除思考强度配置,避免与面板控制重复 - 补齐多语言文案与相关前后端测试
274 lines
10 KiB
Go
274 lines
10 KiB
Go
package ai
|
||
|
||
// ToolCall 表示 AI 发出的工具调用
|
||
type ToolCall struct {
|
||
ID string `json:"id"`
|
||
Type string `json:"type"` // "function"
|
||
Function ToolCallFunction `json:"function"`
|
||
}
|
||
|
||
// ToolCallFunction 表示单次工具调用的函数信息
|
||
type ToolCallFunction struct {
|
||
Name string `json:"name"`
|
||
Arguments string `json:"arguments"`
|
||
}
|
||
|
||
// 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" 并试图调工具时传递
|
||
ReasoningContent string `json:"reasoning_content,omitempty"` // DeepSeek thinking mode 工具调用链路要求原样回传
|
||
}
|
||
|
||
// ChatRequest AI 对话请求
|
||
type ChatRequest struct {
|
||
Messages []Message `json:"messages"`
|
||
Temperature float64 `json:"temperature"`
|
||
MaxTokens int `json:"maxTokens"`
|
||
Tools []Tool `json:"tools,omitempty"`
|
||
ImageFallbackPrompt string `json:"-"`
|
||
ImageOmittedNotice string `json:"-"`
|
||
}
|
||
|
||
// ChatSendOptions 表示一次对话调用的临时覆盖选项,不写回 Provider 配置。
|
||
type ChatSendOptions struct {
|
||
Model string `json:"model,omitempty"`
|
||
Temperature float64 `json:"temperature,omitempty"`
|
||
MaxTokens int `json:"maxTokens,omitempty"`
|
||
ThinkingIntensity string `json:"thinkingIntensity,omitempty"` // 会话/面板级思考强度,仅本次请求生效
|
||
}
|
||
|
||
// ChatResponse AI 对话响应
|
||
type ChatResponse struct {
|
||
Content string `json:"content"`
|
||
ReasoningContent string `json:"reasoning_content,omitempty"`
|
||
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"`
|
||
ReasoningContent string `json:"reasoning_content,omitempty"`
|
||
Done bool `json:"done"`
|
||
Error string `json:"error,omitempty"`
|
||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
||
}
|
||
|
||
// ThinkingIntensity 控制模型思考/推理强度。
|
||
// 字面量按服务商差异保留,例如:
|
||
// - OpenAI: none | minimal | low | medium | high | xhigh
|
||
// - Anthropic: off | low | medium | high | xhigh | max
|
||
// - DeepSeek: off | low | medium | high
|
||
// - Gemini: off | minimal | low | medium | high
|
||
// 不同供应商再映射到 reasoning_effort / thinking / output_config.effort / thinking_level 等字段。
|
||
type ThinkingIntensity string
|
||
|
||
const (
|
||
ThinkingIntensityOff ThinkingIntensity = "off"
|
||
ThinkingIntensityLow ThinkingIntensity = "low"
|
||
ThinkingIntensityMedium ThinkingIntensity = "medium"
|
||
ThinkingIntensityHigh ThinkingIntensity = "high"
|
||
)
|
||
|
||
// 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"`
|
||
SecretRef string `json:"secretRef,omitempty"`
|
||
HasSecret bool `json:"hasSecret,omitempty"`
|
||
BaseURL string `json:"baseUrl"`
|
||
Model string `json:"model"`
|
||
InlineCompletionModel string `json:"inlineCompletionModel,omitempty"`
|
||
Models []string `json:"models,omitempty"`
|
||
APIFormat string `json:"apiFormat,omitempty"` // custom 专用: openai | anthropic | gemini | cursor-agent | claude-cli | codebuddy-cli
|
||
Headers map[string]string `json:"headers,omitempty"`
|
||
MaxTokens int `json:"maxTokens"`
|
||
Temperature float64 `json:"temperature"`
|
||
// ThinkingIntensity 可选:off/low/medium/high。空值表示沿用供应商默认(多数等价 medium)。
|
||
ThinkingIntensity string `json:"thinkingIntensity,omitempty"`
|
||
}
|
||
|
||
// UserPromptSettings 表示用户级自定义提示词配置
|
||
type UserPromptSettings struct {
|
||
Global string `json:"global"`
|
||
Database string `json:"database"`
|
||
JVM string `json:"jvm"`
|
||
JVMDiagnostic string `json:"jvmDiagnostic"`
|
||
}
|
||
|
||
// MCPTransport 表示 MCP 服务的传输方式
|
||
type MCPTransport string
|
||
|
||
const (
|
||
MCPTransportStdio MCPTransport = "stdio"
|
||
)
|
||
|
||
// MCPServerConfig 表示一个可配置的 MCP 服务
|
||
type MCPServerConfig struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"`
|
||
Transport MCPTransport `json:"transport"`
|
||
Command string `json:"command"`
|
||
Args []string `json:"args,omitempty"`
|
||
Env map[string]string `json:"env,omitempty"`
|
||
Enabled bool `json:"enabled"`
|
||
TimeoutSeconds int `json:"timeoutSeconds"`
|
||
}
|
||
|
||
// MCPToolDescriptor 表示暴露给模型和前端的 MCP 工具描述
|
||
type MCPToolDescriptor struct {
|
||
Alias string `json:"alias"`
|
||
ServerID string `json:"serverId"`
|
||
ServerName string `json:"serverName"`
|
||
OriginalName string `json:"originalName"`
|
||
Title string `json:"title,omitempty"`
|
||
Description string `json:"description,omitempty"`
|
||
InputSchema map[string]any `json:"inputSchema,omitempty"`
|
||
}
|
||
|
||
// MCPToolCallResult 表示一次 MCP 工具调用的结果
|
||
type MCPToolCallResult struct {
|
||
Alias string `json:"alias"`
|
||
ServerID string `json:"serverId"`
|
||
ServerName string `json:"serverName"`
|
||
OriginalName string `json:"originalName"`
|
||
Title string `json:"title,omitempty"`
|
||
Content string `json:"content"`
|
||
StructuredContent any `json:"structuredContent,omitempty"`
|
||
IsError bool `json:"isError"`
|
||
}
|
||
|
||
// MCPClientInstallResult 表示安装 GoNavi 到外部 MCP 客户端配置文件的结果。
|
||
type MCPClientInstallResult struct {
|
||
Success bool `json:"success"`
|
||
Client string `json:"client,omitempty"`
|
||
Message string `json:"message"`
|
||
ConfigPath string `json:"configPath,omitempty"`
|
||
Command string `json:"command,omitempty"`
|
||
Args []string `json:"args,omitempty"`
|
||
}
|
||
|
||
// MCPClientInstallStatus 表示 GoNavi MCP 在外部客户端中的当前安装状态。
|
||
type MCPClientInstallStatus struct {
|
||
Client string `json:"client"`
|
||
DisplayName string `json:"displayName"`
|
||
InstallMode string `json:"installMode,omitempty"`
|
||
Installed bool `json:"installed"`
|
||
MatchesCurrent bool `json:"matchesCurrent"`
|
||
ClientDetected bool `json:"clientDetected"`
|
||
ClientCommand string `json:"clientCommand,omitempty"`
|
||
ClientPath string `json:"clientPath,omitempty"`
|
||
Message string `json:"message"`
|
||
ConfigPath string `json:"configPath,omitempty"`
|
||
Command string `json:"command,omitempty"`
|
||
Args []string `json:"args,omitempty"`
|
||
}
|
||
|
||
// MCPHTTPServerOptions 表示从客户端启动 GoNavi Streamable HTTP MCP 的参数。
|
||
type MCPHTTPServerOptions struct {
|
||
Addr string `json:"addr,omitempty"`
|
||
Path string `json:"path,omitempty"`
|
||
Token string `json:"token,omitempty"`
|
||
SchemaOnly bool `json:"schemaOnly"`
|
||
}
|
||
|
||
// MCPHTTPServerStatus 表示客户端内置 HTTP MCP 服务运行状态。
|
||
type MCPHTTPServerStatus struct {
|
||
Running bool `json:"running"`
|
||
Addr string `json:"addr"`
|
||
Path string `json:"path"`
|
||
URL string `json:"url"`
|
||
SchemaOnly bool `json:"schemaOnly"`
|
||
Token string `json:"token,omitempty"`
|
||
AuthorizationHeader string `json:"authorizationHeader,omitempty"`
|
||
StartedAt int64 `json:"startedAt,omitempty"`
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// ClaudeCodeMCPInstallResult 兼容旧命名,便于平滑迁移到通用结果类型。
|
||
type ClaudeCodeMCPInstallResult = MCPClientInstallResult
|
||
|
||
// SkillScope 表示 Skill 的适用场景
|
||
type SkillScope string
|
||
|
||
const (
|
||
SkillScopeGlobal SkillScope = "global"
|
||
SkillScopeDatabase SkillScope = "database"
|
||
SkillScopeJVM SkillScope = "jvm"
|
||
SkillScopeJVMDiagnostic SkillScope = "jvmDiagnostic"
|
||
)
|
||
|
||
// SkillConfig 表示一个可配置的 Skill
|
||
type SkillConfig struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"`
|
||
Description string `json:"description,omitempty"`
|
||
SystemPrompt string `json:"systemPrompt"`
|
||
Enabled bool `json:"enabled"`
|
||
Scopes []string `json:"scopes,omitempty"`
|
||
RequiredTools []string `json:"requiredTools,omitempty"`
|
||
}
|
||
|
||
// 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"`
|
||
}
|