2025-06-25 15:25:18 +08:00
|
|
|
|
package domain
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/chaitin/MonkeyCode/backend/consts"
|
|
|
|
|
|
"github.com/chaitin/MonkeyCode/backend/db"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type ProxyUsecase interface {
|
|
|
|
|
|
SelectModelWithLoadBalancing(modelName string, modelType consts.ModelType) (*Model, error)
|
|
|
|
|
|
Record(ctx context.Context, record *RecordParam) error
|
|
|
|
|
|
ValidateApiKey(ctx context.Context, key string) (*ApiKey, error)
|
|
|
|
|
|
AcceptCompletion(ctx context.Context, req *AcceptCompletionReq) error
|
2025-07-18 17:12:52 +08:00
|
|
|
|
Report(ctx context.Context, req *ReportReq) error
|
2025-07-31 16:13:15 +08:00
|
|
|
|
CreateSecurityScanning(ctx context.Context, req *CreateSecurityScanningReq) (string, error)
|
|
|
|
|
|
ListSecurityScanning(ctx context.Context, req *ListSecurityScanningReq) (*ListSecurityScanningBriefResp, error)
|
2025-08-11 18:29:42 +08:00
|
|
|
|
ListSecurityDetail(ctx context.Context, req *ListSecurityScanningDetailReq) (*ListSecurityScanningDetailResp, error)
|
2025-06-25 15:25:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type ProxyRepo interface {
|
2025-06-30 19:04:09 +08:00
|
|
|
|
Record(ctx context.Context, record *RecordParam) error
|
|
|
|
|
|
UpdateByTaskID(ctx context.Context, taskID string, fn func(*db.TaskUpdateOne)) error
|
2025-07-04 17:24:31 +08:00
|
|
|
|
AcceptCompletion(ctx context.Context, req *AcceptCompletionReq) error
|
2025-07-24 16:46:19 +08:00
|
|
|
|
Report(ctx context.Context, model *db.Model, req *ReportReq) error
|
2025-06-25 15:25:18 +08:00
|
|
|
|
SelectModelWithLoadBalancing(modelName string, modelType consts.ModelType) (*db.Model, error)
|
|
|
|
|
|
ValidateApiKey(ctx context.Context, key string) (*db.ApiKey, error)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-04 20:17:49 +08:00
|
|
|
|
type VersionInfo struct {
|
|
|
|
|
|
Version string `json:"version"`
|
|
|
|
|
|
URL string `json:"url"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-25 15:25:18 +08:00
|
|
|
|
type AcceptCompletionReq struct {
|
|
|
|
|
|
ID string `json:"id"` // 记录ID
|
|
|
|
|
|
Completion string `json:"completion"` // 补全内容
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-18 17:12:52 +08:00
|
|
|
|
type ReportReq struct {
|
2025-07-22 18:42:12 +08:00
|
|
|
|
Action consts.ReportAction `json:"action"`
|
|
|
|
|
|
ID string `json:"id"` // task_id or resp_id
|
|
|
|
|
|
Content string `json:"content"` // 内容
|
|
|
|
|
|
Tool string `json:"tool"` // 工具
|
|
|
|
|
|
UserInput string `json:"user_input"` // 用户输入的新文本(用于reject action)
|
|
|
|
|
|
SourceCode string `json:"source_code"` // 当前文件的原文(用于reject action)
|
|
|
|
|
|
CursorPosition map[string]any `json:"cursor_position"` // 光标位置(用于reject action)
|
2025-07-24 16:46:19 +08:00
|
|
|
|
Mode string `json:"mode"` // 模式
|
|
|
|
|
|
UserID string `json:"-"`
|
2025-07-18 17:12:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-25 15:25:18 +08:00
|
|
|
|
type RecordParam struct {
|
2025-06-30 19:04:09 +08:00
|
|
|
|
RequestID string
|
2025-06-25 15:25:18 +08:00
|
|
|
|
TaskID string
|
|
|
|
|
|
UserID string
|
|
|
|
|
|
ModelID string
|
|
|
|
|
|
ModelType consts.ModelType
|
2025-07-03 10:15:35 +08:00
|
|
|
|
Role consts.ChatRole
|
2025-06-25 15:25:18 +08:00
|
|
|
|
Prompt string
|
|
|
|
|
|
ProgramLanguage string
|
|
|
|
|
|
InputTokens int64
|
|
|
|
|
|
OutputTokens int64
|
|
|
|
|
|
IsAccept bool
|
|
|
|
|
|
Completion string
|
|
|
|
|
|
WorkMode string
|
|
|
|
|
|
CodeLines int64
|
2025-07-18 17:12:52 +08:00
|
|
|
|
Code string
|
2025-07-22 18:42:12 +08:00
|
|
|
|
SourceCode string // 当前文件的原文
|
|
|
|
|
|
CursorPosition map[string]any // 光标位置
|
|
|
|
|
|
UserInput string // 用户实际输入的内容
|
2025-06-25 15:25:18 +08:00
|
|
|
|
}
|
2025-07-03 10:15:35 +08:00
|
|
|
|
|
|
|
|
|
|
func (r *RecordParam) Clone() *RecordParam {
|
|
|
|
|
|
return &RecordParam{
|
|
|
|
|
|
RequestID: r.RequestID,
|
|
|
|
|
|
TaskID: r.TaskID,
|
|
|
|
|
|
UserID: r.UserID,
|
|
|
|
|
|
ModelID: r.ModelID,
|
|
|
|
|
|
ModelType: r.ModelType,
|
|
|
|
|
|
Role: r.Role,
|
|
|
|
|
|
Prompt: r.Prompt,
|
|
|
|
|
|
ProgramLanguage: r.ProgramLanguage,
|
|
|
|
|
|
InputTokens: r.InputTokens,
|
|
|
|
|
|
OutputTokens: r.OutputTokens,
|
|
|
|
|
|
IsAccept: r.IsAccept,
|
|
|
|
|
|
Completion: r.Completion,
|
|
|
|
|
|
WorkMode: r.WorkMode,
|
|
|
|
|
|
CodeLines: r.CodeLines,
|
2025-07-21 15:14:38 +08:00
|
|
|
|
SourceCode: r.SourceCode,
|
|
|
|
|
|
CursorPosition: r.CursorPosition,
|
|
|
|
|
|
UserInput: r.UserInput,
|
2025-07-03 10:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|