Files

344 lines
13 KiB
Go

// Code generated by ent, DO NOT EDIT.
package db
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/chaitin/MonkeyCode/backend/db/mcptool"
"github.com/chaitin/MonkeyCode/backend/db/mcptoolcall"
"github.com/chaitin/MonkeyCode/backend/db/mcpupstream"
"github.com/google/uuid"
)
// MCPToolCall is the model entity for the MCPToolCall schema.
type MCPToolCall struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// RequestID holds the value of the "request_id" field.
RequestID string `json:"request_id,omitempty"`
// TaskID holds the value of the "task_id" field.
TaskID uuid.UUID `json:"task_id,omitempty"`
// UserID holds the value of the "user_id" field.
UserID uuid.UUID `json:"user_id,omitempty"`
// UpstreamID holds the value of the "upstream_id" field.
UpstreamID uuid.UUID `json:"upstream_id,omitempty"`
// ToolID holds the value of the "tool_id" field.
ToolID uuid.UUID `json:"tool_id,omitempty"`
// ToolNameSnapshot holds the value of the "tool_name_snapshot" field.
ToolNameSnapshot string `json:"tool_name_snapshot,omitempty"`
// ToolScopeSnapshot holds the value of the "tool_scope_snapshot" field.
ToolScopeSnapshot mcptoolcall.ToolScopeSnapshot `json:"tool_scope_snapshot,omitempty"`
// PriceSnapshot holds the value of the "price_snapshot" field.
PriceSnapshot int64 `json:"price_snapshot,omitempty"`
// Status holds the value of the "status" field.
Status mcptoolcall.Status `json:"status,omitempty"`
// ArgsJSON holds the value of the "args_json" field.
ArgsJSON map[string]interface{} `json:"args_json,omitempty"`
// ResultJSON holds the value of the "result_json" field.
ResultJSON map[string]interface{} `json:"result_json,omitempty"`
// ErrorMessage holds the value of the "error_message" field.
ErrorMessage string `json:"error_message,omitempty"`
// UpstreamRequestID holds the value of the "upstream_request_id" field.
UpstreamRequestID string `json:"upstream_request_id,omitempty"`
// StartedAt holds the value of the "started_at" field.
StartedAt time.Time `json:"started_at,omitempty"`
// FinishedAt holds the value of the "finished_at" field.
FinishedAt *time.Time `json:"finished_at,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the MCPToolCallQuery when eager-loading is set.
Edges MCPToolCallEdges `json:"edges"`
selectValues sql.SelectValues
}
// MCPToolCallEdges holds the relations/edges for other nodes in the graph.
type MCPToolCallEdges struct {
// Upstream holds the value of the upstream edge.
Upstream *MCPUpstream `json:"upstream,omitempty"`
// Tool holds the value of the tool edge.
Tool *MCPTool `json:"tool,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// UpstreamOrErr returns the Upstream value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e MCPToolCallEdges) UpstreamOrErr() (*MCPUpstream, error) {
if e.Upstream != nil {
return e.Upstream, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: mcpupstream.Label}
}
return nil, &NotLoadedError{edge: "upstream"}
}
// ToolOrErr returns the Tool value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e MCPToolCallEdges) ToolOrErr() (*MCPTool, error) {
if e.Tool != nil {
return e.Tool, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: mcptool.Label}
}
return nil, &NotLoadedError{edge: "tool"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*MCPToolCall) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case mcptoolcall.FieldArgsJSON, mcptoolcall.FieldResultJSON:
values[i] = new([]byte)
case mcptoolcall.FieldPriceSnapshot:
values[i] = new(sql.NullInt64)
case mcptoolcall.FieldRequestID, mcptoolcall.FieldToolNameSnapshot, mcptoolcall.FieldToolScopeSnapshot, mcptoolcall.FieldStatus, mcptoolcall.FieldErrorMessage, mcptoolcall.FieldUpstreamRequestID:
values[i] = new(sql.NullString)
case mcptoolcall.FieldStartedAt, mcptoolcall.FieldFinishedAt, mcptoolcall.FieldCreatedAt, mcptoolcall.FieldUpdatedAt:
values[i] = new(sql.NullTime)
case mcptoolcall.FieldID, mcptoolcall.FieldTaskID, mcptoolcall.FieldUserID, mcptoolcall.FieldUpstreamID, mcptoolcall.FieldToolID:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the MCPToolCall fields.
func (_m *MCPToolCall) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case mcptoolcall.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
_m.ID = *value
}
case mcptoolcall.FieldRequestID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field request_id", values[i])
} else if value.Valid {
_m.RequestID = value.String
}
case mcptoolcall.FieldTaskID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field task_id", values[i])
} else if value != nil {
_m.TaskID = *value
}
case mcptoolcall.FieldUserID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i])
} else if value != nil {
_m.UserID = *value
}
case mcptoolcall.FieldUpstreamID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field upstream_id", values[i])
} else if value != nil {
_m.UpstreamID = *value
}
case mcptoolcall.FieldToolID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field tool_id", values[i])
} else if value != nil {
_m.ToolID = *value
}
case mcptoolcall.FieldToolNameSnapshot:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field tool_name_snapshot", values[i])
} else if value.Valid {
_m.ToolNameSnapshot = value.String
}
case mcptoolcall.FieldToolScopeSnapshot:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field tool_scope_snapshot", values[i])
} else if value.Valid {
_m.ToolScopeSnapshot = mcptoolcall.ToolScopeSnapshot(value.String)
}
case mcptoolcall.FieldPriceSnapshot:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field price_snapshot", values[i])
} else if value.Valid {
_m.PriceSnapshot = value.Int64
}
case mcptoolcall.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
_m.Status = mcptoolcall.Status(value.String)
}
case mcptoolcall.FieldArgsJSON:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field args_json", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.ArgsJSON); err != nil {
return fmt.Errorf("unmarshal field args_json: %w", err)
}
}
case mcptoolcall.FieldResultJSON:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field result_json", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.ResultJSON); err != nil {
return fmt.Errorf("unmarshal field result_json: %w", err)
}
}
case mcptoolcall.FieldErrorMessage:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field error_message", values[i])
} else if value.Valid {
_m.ErrorMessage = value.String
}
case mcptoolcall.FieldUpstreamRequestID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field upstream_request_id", values[i])
} else if value.Valid {
_m.UpstreamRequestID = value.String
}
case mcptoolcall.FieldStartedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field started_at", values[i])
} else if value.Valid {
_m.StartedAt = value.Time
}
case mcptoolcall.FieldFinishedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field finished_at", values[i])
} else if value.Valid {
_m.FinishedAt = new(time.Time)
*_m.FinishedAt = value.Time
}
case mcptoolcall.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case mcptoolcall.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the MCPToolCall.
// This includes values selected through modifiers, order, etc.
func (_m *MCPToolCall) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryUpstream queries the "upstream" edge of the MCPToolCall entity.
func (_m *MCPToolCall) QueryUpstream() *MCPUpstreamQuery {
return NewMCPToolCallClient(_m.config).QueryUpstream(_m)
}
// QueryTool queries the "tool" edge of the MCPToolCall entity.
func (_m *MCPToolCall) QueryTool() *MCPToolQuery {
return NewMCPToolCallClient(_m.config).QueryTool(_m)
}
// Update returns a builder for updating this MCPToolCall.
// Note that you need to call MCPToolCall.Unwrap() before calling this method if this MCPToolCall
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *MCPToolCall) Update() *MCPToolCallUpdateOne {
return NewMCPToolCallClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the MCPToolCall entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *MCPToolCall) Unwrap() *MCPToolCall {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("db: MCPToolCall is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *MCPToolCall) String() string {
var builder strings.Builder
builder.WriteString("MCPToolCall(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("request_id=")
builder.WriteString(_m.RequestID)
builder.WriteString(", ")
builder.WriteString("task_id=")
builder.WriteString(fmt.Sprintf("%v", _m.TaskID))
builder.WriteString(", ")
builder.WriteString("user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
builder.WriteString(", ")
builder.WriteString("upstream_id=")
builder.WriteString(fmt.Sprintf("%v", _m.UpstreamID))
builder.WriteString(", ")
builder.WriteString("tool_id=")
builder.WriteString(fmt.Sprintf("%v", _m.ToolID))
builder.WriteString(", ")
builder.WriteString("tool_name_snapshot=")
builder.WriteString(_m.ToolNameSnapshot)
builder.WriteString(", ")
builder.WriteString("tool_scope_snapshot=")
builder.WriteString(fmt.Sprintf("%v", _m.ToolScopeSnapshot))
builder.WriteString(", ")
builder.WriteString("price_snapshot=")
builder.WriteString(fmt.Sprintf("%v", _m.PriceSnapshot))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", _m.Status))
builder.WriteString(", ")
builder.WriteString("args_json=")
builder.WriteString(fmt.Sprintf("%v", _m.ArgsJSON))
builder.WriteString(", ")
builder.WriteString("result_json=")
builder.WriteString(fmt.Sprintf("%v", _m.ResultJSON))
builder.WriteString(", ")
builder.WriteString("error_message=")
builder.WriteString(_m.ErrorMessage)
builder.WriteString(", ")
builder.WriteString("upstream_request_id=")
builder.WriteString(_m.UpstreamRequestID)
builder.WriteString(", ")
builder.WriteString("started_at=")
builder.WriteString(_m.StartedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.FinishedAt; v != nil {
builder.WriteString("finished_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// MCPToolCalls is a parsable slice of MCPToolCall.
type MCPToolCalls []*MCPToolCall