From fb144c432da738f03ce142ad64a2a31f7d32dbcc Mon Sep 17 00:00:00 2001 From: benjamin Date: Tue, 19 May 2026 22:04:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(channel-monitor):=20=E6=8C=81=E4=B9=85?= =?UTF-8?q?=E5=8C=96=20API=20=E6=A8=A1=E5=BC=8F=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- backend/ent/channelmonitor.go | 13 +- backend/ent/channelmonitor/channelmonitor.go | 12 ++ backend/ent/channelmonitor/where.go | 70 +++++++++++ backend/ent/channelmonitor_create.go | 70 +++++++++++ backend/ent/channelmonitor_update.go | 44 +++++++ backend/ent/channelmonitorrequesttemplate.go | 13 +- .../channelmonitorrequesttemplate.go | 12 ++ .../channelmonitorrequesttemplate/where.go | 70 +++++++++++ .../channelmonitorrequesttemplate_create.go | 70 +++++++++++ .../channelmonitorrequesttemplate_update.go | 44 +++++++ backend/ent/migrate/schema.go | 20 +++- backend/ent/mutation.go | 112 +++++++++++++++++- backend/ent/runtime/runtime.go | 36 ++++-- backend/ent/schema/channel_monitor.go | 5 + .../channel_monitor_request_template.go | 5 + 15 files changed, 576 insertions(+), 20 deletions(-) diff --git a/backend/ent/channelmonitor.go b/backend/ent/channelmonitor.go index dbb73362..defd06c6 100644 --- a/backend/ent/channelmonitor.go +++ b/backend/ent/channelmonitor.go @@ -27,6 +27,8 @@ type ChannelMonitor struct { Name string `json:"name,omitempty"` // Provider holds the value of the "provider" field. Provider channelmonitor.Provider `json:"provider,omitempty"` + // OpenAI request protocol: chat_completions or responses; non-OpenAI uses chat_completions + APIMode string `json:"api_mode,omitempty"` // Provider base origin, e.g. https://api.openai.com Endpoint string `json:"endpoint,omitempty"` // AES-256-GCM encrypted API key @@ -112,7 +114,7 @@ func (*ChannelMonitor) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullBool) case channelmonitor.FieldID, channelmonitor.FieldIntervalSeconds, channelmonitor.FieldCreatedBy, channelmonitor.FieldTemplateID: values[i] = new(sql.NullInt64) - case channelmonitor.FieldName, channelmonitor.FieldProvider, channelmonitor.FieldEndpoint, channelmonitor.FieldAPIKeyEncrypted, channelmonitor.FieldPrimaryModel, channelmonitor.FieldGroupName, channelmonitor.FieldBodyOverrideMode: + case channelmonitor.FieldName, channelmonitor.FieldProvider, channelmonitor.FieldAPIMode, channelmonitor.FieldEndpoint, channelmonitor.FieldAPIKeyEncrypted, channelmonitor.FieldPrimaryModel, channelmonitor.FieldGroupName, channelmonitor.FieldBodyOverrideMode: values[i] = new(sql.NullString) case channelmonitor.FieldCreatedAt, channelmonitor.FieldUpdatedAt, channelmonitor.FieldLastCheckedAt: values[i] = new(sql.NullTime) @@ -161,6 +163,12 @@ func (_m *ChannelMonitor) assignValues(columns []string, values []any) error { } else if value.Valid { _m.Provider = channelmonitor.Provider(value.String) } + case channelmonitor.FieldAPIMode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field api_mode", values[i]) + } else if value.Valid { + _m.APIMode = value.String + } case channelmonitor.FieldEndpoint: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field endpoint", values[i]) @@ -310,6 +318,9 @@ func (_m *ChannelMonitor) String() string { builder.WriteString("provider=") builder.WriteString(fmt.Sprintf("%v", _m.Provider)) builder.WriteString(", ") + builder.WriteString("api_mode=") + builder.WriteString(_m.APIMode) + builder.WriteString(", ") builder.WriteString("endpoint=") builder.WriteString(_m.Endpoint) builder.WriteString(", ") diff --git a/backend/ent/channelmonitor/channelmonitor.go b/backend/ent/channelmonitor/channelmonitor.go index e5a6bfe7..0723ad0d 100644 --- a/backend/ent/channelmonitor/channelmonitor.go +++ b/backend/ent/channelmonitor/channelmonitor.go @@ -23,6 +23,8 @@ const ( FieldName = "name" // FieldProvider holds the string denoting the provider field in the database. FieldProvider = "provider" + // FieldAPIMode holds the string denoting the api_mode field in the database. + FieldAPIMode = "api_mode" // FieldEndpoint holds the string denoting the endpoint field in the database. FieldEndpoint = "endpoint" // FieldAPIKeyEncrypted holds the string denoting the api_key_encrypted field in the database. @@ -87,6 +89,7 @@ var Columns = []string{ FieldUpdatedAt, FieldName, FieldProvider, + FieldAPIMode, FieldEndpoint, FieldAPIKeyEncrypted, FieldPrimaryModel, @@ -121,6 +124,10 @@ var ( UpdateDefaultUpdatedAt func() time.Time // NameValidator is a validator for the "name" field. It is called by the builders before save. NameValidator func(string) error + // DefaultAPIMode holds the default value on creation for the "api_mode" field. + DefaultAPIMode string + // APIModeValidator is a validator for the "api_mode" field. It is called by the builders before save. + APIModeValidator func(string) error // EndpointValidator is a validator for the "endpoint" field. It is called by the builders before save. EndpointValidator func(string) error // APIKeyEncryptedValidator is a validator for the "api_key_encrypted" field. It is called by the builders before save. @@ -197,6 +204,11 @@ func ByProvider(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldProvider, opts...).ToFunc() } +// ByAPIMode orders the results by the api_mode field. +func ByAPIMode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAPIMode, opts...).ToFunc() +} + // ByEndpoint orders the results by the endpoint field. func ByEndpoint(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldEndpoint, opts...).ToFunc() diff --git a/backend/ent/channelmonitor/where.go b/backend/ent/channelmonitor/where.go index 755d83a3..8bd8f627 100644 --- a/backend/ent/channelmonitor/where.go +++ b/backend/ent/channelmonitor/where.go @@ -70,6 +70,11 @@ func Name(v string) predicate.ChannelMonitor { return predicate.ChannelMonitor(sql.FieldEQ(FieldName, v)) } +// APIMode applies equality check predicate on the "api_mode" field. It's identical to APIModeEQ. +func APIMode(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldEQ(FieldAPIMode, v)) +} + // Endpoint applies equality check predicate on the "endpoint" field. It's identical to EndpointEQ. func Endpoint(v string) predicate.ChannelMonitor { return predicate.ChannelMonitor(sql.FieldEQ(FieldEndpoint, v)) @@ -285,6 +290,71 @@ func ProviderNotIn(vs ...Provider) predicate.ChannelMonitor { return predicate.ChannelMonitor(sql.FieldNotIn(FieldProvider, vs...)) } +// APIModeEQ applies the EQ predicate on the "api_mode" field. +func APIModeEQ(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldEQ(FieldAPIMode, v)) +} + +// APIModeNEQ applies the NEQ predicate on the "api_mode" field. +func APIModeNEQ(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldNEQ(FieldAPIMode, v)) +} + +// APIModeIn applies the In predicate on the "api_mode" field. +func APIModeIn(vs ...string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldIn(FieldAPIMode, vs...)) +} + +// APIModeNotIn applies the NotIn predicate on the "api_mode" field. +func APIModeNotIn(vs ...string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldNotIn(FieldAPIMode, vs...)) +} + +// APIModeGT applies the GT predicate on the "api_mode" field. +func APIModeGT(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldGT(FieldAPIMode, v)) +} + +// APIModeGTE applies the GTE predicate on the "api_mode" field. +func APIModeGTE(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldGTE(FieldAPIMode, v)) +} + +// APIModeLT applies the LT predicate on the "api_mode" field. +func APIModeLT(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldLT(FieldAPIMode, v)) +} + +// APIModeLTE applies the LTE predicate on the "api_mode" field. +func APIModeLTE(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldLTE(FieldAPIMode, v)) +} + +// APIModeContains applies the Contains predicate on the "api_mode" field. +func APIModeContains(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldContains(FieldAPIMode, v)) +} + +// APIModeHasPrefix applies the HasPrefix predicate on the "api_mode" field. +func APIModeHasPrefix(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldHasPrefix(FieldAPIMode, v)) +} + +// APIModeHasSuffix applies the HasSuffix predicate on the "api_mode" field. +func APIModeHasSuffix(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldHasSuffix(FieldAPIMode, v)) +} + +// APIModeEqualFold applies the EqualFold predicate on the "api_mode" field. +func APIModeEqualFold(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldEqualFold(FieldAPIMode, v)) +} + +// APIModeContainsFold applies the ContainsFold predicate on the "api_mode" field. +func APIModeContainsFold(v string) predicate.ChannelMonitor { + return predicate.ChannelMonitor(sql.FieldContainsFold(FieldAPIMode, v)) +} + // EndpointEQ applies the EQ predicate on the "endpoint" field. func EndpointEQ(v string) predicate.ChannelMonitor { return predicate.ChannelMonitor(sql.FieldEQ(FieldEndpoint, v)) diff --git a/backend/ent/channelmonitor_create.go b/backend/ent/channelmonitor_create.go index 2f70c300..2593893f 100644 --- a/backend/ent/channelmonitor_create.go +++ b/backend/ent/channelmonitor_create.go @@ -65,6 +65,20 @@ func (_c *ChannelMonitorCreate) SetProvider(v channelmonitor.Provider) *ChannelM return _c } +// SetAPIMode sets the "api_mode" field. +func (_c *ChannelMonitorCreate) SetAPIMode(v string) *ChannelMonitorCreate { + _c.mutation.SetAPIMode(v) + return _c +} + +// SetNillableAPIMode sets the "api_mode" field if the given value is not nil. +func (_c *ChannelMonitorCreate) SetNillableAPIMode(v *string) *ChannelMonitorCreate { + if v != nil { + _c.SetAPIMode(*v) + } + return _c +} + // SetEndpoint sets the "endpoint" field. func (_c *ChannelMonitorCreate) SetEndpoint(v string) *ChannelMonitorCreate { _c.mutation.SetEndpoint(v) @@ -275,6 +289,10 @@ func (_c *ChannelMonitorCreate) defaults() { v := channelmonitor.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } + if _, ok := _c.mutation.APIMode(); !ok { + v := channelmonitor.DefaultAPIMode + _c.mutation.SetAPIMode(v) + } if _, ok := _c.mutation.ExtraModels(); !ok { v := channelmonitor.DefaultExtraModels _c.mutation.SetExtraModels(v) @@ -321,6 +339,14 @@ func (_c *ChannelMonitorCreate) check() error { return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.provider": %w`, err)} } } + if _, ok := _c.mutation.APIMode(); !ok { + return &ValidationError{Name: "api_mode", err: errors.New(`ent: missing required field "ChannelMonitor.api_mode"`)} + } + if v, ok := _c.mutation.APIMode(); ok { + if err := channelmonitor.APIModeValidator(v); err != nil { + return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_mode": %w`, err)} + } + } if _, ok := _c.mutation.Endpoint(); !ok { return &ValidationError{Name: "endpoint", err: errors.New(`ent: missing required field "ChannelMonitor.endpoint"`)} } @@ -421,6 +447,10 @@ func (_c *ChannelMonitorCreate) createSpec() (*ChannelMonitor, *sqlgraph.CreateS _spec.SetField(channelmonitor.FieldProvider, field.TypeEnum, value) _node.Provider = value } + if value, ok := _c.mutation.APIMode(); ok { + _spec.SetField(channelmonitor.FieldAPIMode, field.TypeString, value) + _node.APIMode = value + } if value, ok := _c.mutation.Endpoint(); ok { _spec.SetField(channelmonitor.FieldEndpoint, field.TypeString, value) _node.Endpoint = value @@ -606,6 +636,18 @@ func (u *ChannelMonitorUpsert) UpdateProvider() *ChannelMonitorUpsert { return u } +// SetAPIMode sets the "api_mode" field. +func (u *ChannelMonitorUpsert) SetAPIMode(v string) *ChannelMonitorUpsert { + u.Set(channelmonitor.FieldAPIMode, v) + return u +} + +// UpdateAPIMode sets the "api_mode" field to the value that was provided on create. +func (u *ChannelMonitorUpsert) UpdateAPIMode() *ChannelMonitorUpsert { + u.SetExcluded(channelmonitor.FieldAPIMode) + return u +} + // SetEndpoint sets the "endpoint" field. func (u *ChannelMonitorUpsert) SetEndpoint(v string) *ChannelMonitorUpsert { u.Set(channelmonitor.FieldEndpoint, v) @@ -885,6 +927,20 @@ func (u *ChannelMonitorUpsertOne) UpdateProvider() *ChannelMonitorUpsertOne { }) } +// SetAPIMode sets the "api_mode" field. +func (u *ChannelMonitorUpsertOne) SetAPIMode(v string) *ChannelMonitorUpsertOne { + return u.Update(func(s *ChannelMonitorUpsert) { + s.SetAPIMode(v) + }) +} + +// UpdateAPIMode sets the "api_mode" field to the value that was provided on create. +func (u *ChannelMonitorUpsertOne) UpdateAPIMode() *ChannelMonitorUpsertOne { + return u.Update(func(s *ChannelMonitorUpsert) { + s.UpdateAPIMode() + }) +} + // SetEndpoint sets the "endpoint" field. func (u *ChannelMonitorUpsertOne) SetEndpoint(v string) *ChannelMonitorUpsertOne { return u.Update(func(s *ChannelMonitorUpsert) { @@ -1362,6 +1418,20 @@ func (u *ChannelMonitorUpsertBulk) UpdateProvider() *ChannelMonitorUpsertBulk { }) } +// SetAPIMode sets the "api_mode" field. +func (u *ChannelMonitorUpsertBulk) SetAPIMode(v string) *ChannelMonitorUpsertBulk { + return u.Update(func(s *ChannelMonitorUpsert) { + s.SetAPIMode(v) + }) +} + +// UpdateAPIMode sets the "api_mode" field to the value that was provided on create. +func (u *ChannelMonitorUpsertBulk) UpdateAPIMode() *ChannelMonitorUpsertBulk { + return u.Update(func(s *ChannelMonitorUpsert) { + s.UpdateAPIMode() + }) +} + // SetEndpoint sets the "endpoint" field. func (u *ChannelMonitorUpsertBulk) SetEndpoint(v string) *ChannelMonitorUpsertBulk { return u.Update(func(s *ChannelMonitorUpsert) { diff --git a/backend/ent/channelmonitor_update.go b/backend/ent/channelmonitor_update.go index 4bbcd564..2cd5e656 100644 --- a/backend/ent/channelmonitor_update.go +++ b/backend/ent/channelmonitor_update.go @@ -66,6 +66,20 @@ func (_u *ChannelMonitorUpdate) SetNillableProvider(v *channelmonitor.Provider) return _u } +// SetAPIMode sets the "api_mode" field. +func (_u *ChannelMonitorUpdate) SetAPIMode(v string) *ChannelMonitorUpdate { + _u.mutation.SetAPIMode(v) + return _u +} + +// SetNillableAPIMode sets the "api_mode" field if the given value is not nil. +func (_u *ChannelMonitorUpdate) SetNillableAPIMode(v *string) *ChannelMonitorUpdate { + if v != nil { + _u.SetAPIMode(*v) + } + return _u +} + // SetEndpoint sets the "endpoint" field. func (_u *ChannelMonitorUpdate) SetEndpoint(v string) *ChannelMonitorUpdate { _u.mutation.SetEndpoint(v) @@ -418,6 +432,11 @@ func (_u *ChannelMonitorUpdate) check() error { return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.provider": %w`, err)} } } + if v, ok := _u.mutation.APIMode(); ok { + if err := channelmonitor.APIModeValidator(v); err != nil { + return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_mode": %w`, err)} + } + } if v, ok := _u.mutation.Endpoint(); ok { if err := channelmonitor.EndpointValidator(v); err != nil { return &ValidationError{Name: "endpoint", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.endpoint": %w`, err)} @@ -472,6 +491,9 @@ func (_u *ChannelMonitorUpdate) sqlSave(ctx context.Context) (_node int, err err if value, ok := _u.mutation.Provider(); ok { _spec.SetField(channelmonitor.FieldProvider, field.TypeEnum, value) } + if value, ok := _u.mutation.APIMode(); ok { + _spec.SetField(channelmonitor.FieldAPIMode, field.TypeString, value) + } if value, ok := _u.mutation.Endpoint(); ok { _spec.SetField(channelmonitor.FieldEndpoint, field.TypeString, value) } @@ -701,6 +723,20 @@ func (_u *ChannelMonitorUpdateOne) SetNillableProvider(v *channelmonitor.Provide return _u } +// SetAPIMode sets the "api_mode" field. +func (_u *ChannelMonitorUpdateOne) SetAPIMode(v string) *ChannelMonitorUpdateOne { + _u.mutation.SetAPIMode(v) + return _u +} + +// SetNillableAPIMode sets the "api_mode" field if the given value is not nil. +func (_u *ChannelMonitorUpdateOne) SetNillableAPIMode(v *string) *ChannelMonitorUpdateOne { + if v != nil { + _u.SetAPIMode(*v) + } + return _u +} + // SetEndpoint sets the "endpoint" field. func (_u *ChannelMonitorUpdateOne) SetEndpoint(v string) *ChannelMonitorUpdateOne { _u.mutation.SetEndpoint(v) @@ -1066,6 +1102,11 @@ func (_u *ChannelMonitorUpdateOne) check() error { return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.provider": %w`, err)} } } + if v, ok := _u.mutation.APIMode(); ok { + if err := channelmonitor.APIModeValidator(v); err != nil { + return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_mode": %w`, err)} + } + } if v, ok := _u.mutation.Endpoint(); ok { if err := channelmonitor.EndpointValidator(v); err != nil { return &ValidationError{Name: "endpoint", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.endpoint": %w`, err)} @@ -1137,6 +1178,9 @@ func (_u *ChannelMonitorUpdateOne) sqlSave(ctx context.Context) (_node *ChannelM if value, ok := _u.mutation.Provider(); ok { _spec.SetField(channelmonitor.FieldProvider, field.TypeEnum, value) } + if value, ok := _u.mutation.APIMode(); ok { + _spec.SetField(channelmonitor.FieldAPIMode, field.TypeString, value) + } if value, ok := _u.mutation.Endpoint(); ok { _spec.SetField(channelmonitor.FieldEndpoint, field.TypeString, value) } diff --git a/backend/ent/channelmonitorrequesttemplate.go b/backend/ent/channelmonitorrequesttemplate.go index b8429a4d..7f417efb 100644 --- a/backend/ent/channelmonitorrequesttemplate.go +++ b/backend/ent/channelmonitorrequesttemplate.go @@ -26,6 +26,8 @@ type ChannelMonitorRequestTemplate struct { Name string `json:"name,omitempty"` // Provider holds the value of the "provider" field. Provider channelmonitorrequesttemplate.Provider `json:"provider,omitempty"` + // OpenAI request protocol: chat_completions or responses; non-OpenAI uses chat_completions + APIMode string `json:"api_mode,omitempty"` // Description holds the value of the "description" field. Description string `json:"description,omitempty"` // ExtraHeaders holds the value of the "extra_headers" field. @@ -67,7 +69,7 @@ func (*ChannelMonitorRequestTemplate) scanValues(columns []string) ([]any, error values[i] = new([]byte) case channelmonitorrequesttemplate.FieldID: values[i] = new(sql.NullInt64) - case channelmonitorrequesttemplate.FieldName, channelmonitorrequesttemplate.FieldProvider, channelmonitorrequesttemplate.FieldDescription, channelmonitorrequesttemplate.FieldBodyOverrideMode: + case channelmonitorrequesttemplate.FieldName, channelmonitorrequesttemplate.FieldProvider, channelmonitorrequesttemplate.FieldAPIMode, channelmonitorrequesttemplate.FieldDescription, channelmonitorrequesttemplate.FieldBodyOverrideMode: values[i] = new(sql.NullString) case channelmonitorrequesttemplate.FieldCreatedAt, channelmonitorrequesttemplate.FieldUpdatedAt: values[i] = new(sql.NullTime) @@ -116,6 +118,12 @@ func (_m *ChannelMonitorRequestTemplate) assignValues(columns []string, values [ } else if value.Valid { _m.Provider = channelmonitorrequesttemplate.Provider(value.String) } + case channelmonitorrequesttemplate.FieldAPIMode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field api_mode", values[i]) + } else if value.Valid { + _m.APIMode = value.String + } case channelmonitorrequesttemplate.FieldDescription: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field description", values[i]) @@ -197,6 +205,9 @@ func (_m *ChannelMonitorRequestTemplate) String() string { builder.WriteString("provider=") builder.WriteString(fmt.Sprintf("%v", _m.Provider)) builder.WriteString(", ") + builder.WriteString("api_mode=") + builder.WriteString(_m.APIMode) + builder.WriteString(", ") builder.WriteString("description=") builder.WriteString(_m.Description) builder.WriteString(", ") diff --git a/backend/ent/channelmonitorrequesttemplate/channelmonitorrequesttemplate.go b/backend/ent/channelmonitorrequesttemplate/channelmonitorrequesttemplate.go index 65b8d641..db04aee1 100644 --- a/backend/ent/channelmonitorrequesttemplate/channelmonitorrequesttemplate.go +++ b/backend/ent/channelmonitorrequesttemplate/channelmonitorrequesttemplate.go @@ -23,6 +23,8 @@ const ( FieldName = "name" // FieldProvider holds the string denoting the provider field in the database. FieldProvider = "provider" + // FieldAPIMode holds the string denoting the api_mode field in the database. + FieldAPIMode = "api_mode" // FieldDescription holds the string denoting the description field in the database. FieldDescription = "description" // FieldExtraHeaders holds the string denoting the extra_headers field in the database. @@ -51,6 +53,7 @@ var Columns = []string{ FieldUpdatedAt, FieldName, FieldProvider, + FieldAPIMode, FieldDescription, FieldExtraHeaders, FieldBodyOverrideMode, @@ -76,6 +79,10 @@ var ( UpdateDefaultUpdatedAt func() time.Time // NameValidator is a validator for the "name" field. It is called by the builders before save. NameValidator func(string) error + // DefaultAPIMode holds the default value on creation for the "api_mode" field. + DefaultAPIMode string + // APIModeValidator is a validator for the "api_mode" field. It is called by the builders before save. + APIModeValidator func(string) error // DefaultDescription holds the default value on creation for the "description" field. DefaultDescription string // DescriptionValidator is a validator for the "description" field. It is called by the builders before save. @@ -140,6 +147,11 @@ func ByProvider(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldProvider, opts...).ToFunc() } +// ByAPIMode orders the results by the api_mode field. +func ByAPIMode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAPIMode, opts...).ToFunc() +} + // ByDescription orders the results by the description field. func ByDescription(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldDescription, opts...).ToFunc() diff --git a/backend/ent/channelmonitorrequesttemplate/where.go b/backend/ent/channelmonitorrequesttemplate/where.go index b95e5df0..9f6d7333 100644 --- a/backend/ent/channelmonitorrequesttemplate/where.go +++ b/backend/ent/channelmonitorrequesttemplate/where.go @@ -70,6 +70,11 @@ func Name(v string) predicate.ChannelMonitorRequestTemplate { return predicate.ChannelMonitorRequestTemplate(sql.FieldEQ(FieldName, v)) } +// APIMode applies equality check predicate on the "api_mode" field. It's identical to APIModeEQ. +func APIMode(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldEQ(FieldAPIMode, v)) +} + // Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. func Description(v string) predicate.ChannelMonitorRequestTemplate { return predicate.ChannelMonitorRequestTemplate(sql.FieldEQ(FieldDescription, v)) @@ -245,6 +250,71 @@ func ProviderNotIn(vs ...Provider) predicate.ChannelMonitorRequestTemplate { return predicate.ChannelMonitorRequestTemplate(sql.FieldNotIn(FieldProvider, vs...)) } +// APIModeEQ applies the EQ predicate on the "api_mode" field. +func APIModeEQ(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldEQ(FieldAPIMode, v)) +} + +// APIModeNEQ applies the NEQ predicate on the "api_mode" field. +func APIModeNEQ(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldNEQ(FieldAPIMode, v)) +} + +// APIModeIn applies the In predicate on the "api_mode" field. +func APIModeIn(vs ...string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldIn(FieldAPIMode, vs...)) +} + +// APIModeNotIn applies the NotIn predicate on the "api_mode" field. +func APIModeNotIn(vs ...string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldNotIn(FieldAPIMode, vs...)) +} + +// APIModeGT applies the GT predicate on the "api_mode" field. +func APIModeGT(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldGT(FieldAPIMode, v)) +} + +// APIModeGTE applies the GTE predicate on the "api_mode" field. +func APIModeGTE(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldGTE(FieldAPIMode, v)) +} + +// APIModeLT applies the LT predicate on the "api_mode" field. +func APIModeLT(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldLT(FieldAPIMode, v)) +} + +// APIModeLTE applies the LTE predicate on the "api_mode" field. +func APIModeLTE(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldLTE(FieldAPIMode, v)) +} + +// APIModeContains applies the Contains predicate on the "api_mode" field. +func APIModeContains(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldContains(FieldAPIMode, v)) +} + +// APIModeHasPrefix applies the HasPrefix predicate on the "api_mode" field. +func APIModeHasPrefix(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldHasPrefix(FieldAPIMode, v)) +} + +// APIModeHasSuffix applies the HasSuffix predicate on the "api_mode" field. +func APIModeHasSuffix(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldHasSuffix(FieldAPIMode, v)) +} + +// APIModeEqualFold applies the EqualFold predicate on the "api_mode" field. +func APIModeEqualFold(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldEqualFold(FieldAPIMode, v)) +} + +// APIModeContainsFold applies the ContainsFold predicate on the "api_mode" field. +func APIModeContainsFold(v string) predicate.ChannelMonitorRequestTemplate { + return predicate.ChannelMonitorRequestTemplate(sql.FieldContainsFold(FieldAPIMode, v)) +} + // DescriptionEQ applies the EQ predicate on the "description" field. func DescriptionEQ(v string) predicate.ChannelMonitorRequestTemplate { return predicate.ChannelMonitorRequestTemplate(sql.FieldEQ(FieldDescription, v)) diff --git a/backend/ent/channelmonitorrequesttemplate_create.go b/backend/ent/channelmonitorrequesttemplate_create.go index 1ba842cd..45405270 100644 --- a/backend/ent/channelmonitorrequesttemplate_create.go +++ b/backend/ent/channelmonitorrequesttemplate_create.go @@ -63,6 +63,20 @@ func (_c *ChannelMonitorRequestTemplateCreate) SetProvider(v channelmonitorreque return _c } +// SetAPIMode sets the "api_mode" field. +func (_c *ChannelMonitorRequestTemplateCreate) SetAPIMode(v string) *ChannelMonitorRequestTemplateCreate { + _c.mutation.SetAPIMode(v) + return _c +} + +// SetNillableAPIMode sets the "api_mode" field if the given value is not nil. +func (_c *ChannelMonitorRequestTemplateCreate) SetNillableAPIMode(v *string) *ChannelMonitorRequestTemplateCreate { + if v != nil { + _c.SetAPIMode(*v) + } + return _c +} + // SetDescription sets the "description" field. func (_c *ChannelMonitorRequestTemplateCreate) SetDescription(v string) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetDescription(v) @@ -161,6 +175,10 @@ func (_c *ChannelMonitorRequestTemplateCreate) defaults() { v := channelmonitorrequesttemplate.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } + if _, ok := _c.mutation.APIMode(); !ok { + v := channelmonitorrequesttemplate.DefaultAPIMode + _c.mutation.SetAPIMode(v) + } if _, ok := _c.mutation.Description(); !ok { v := channelmonitorrequesttemplate.DefaultDescription _c.mutation.SetDescription(v) @@ -199,6 +217,14 @@ func (_c *ChannelMonitorRequestTemplateCreate) check() error { return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.provider": %w`, err)} } } + if _, ok := _c.mutation.APIMode(); !ok { + return &ValidationError{Name: "api_mode", err: errors.New(`ent: missing required field "ChannelMonitorRequestTemplate.api_mode"`)} + } + if v, ok := _c.mutation.APIMode(); ok { + if err := channelmonitorrequesttemplate.APIModeValidator(v); err != nil { + return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.api_mode": %w`, err)} + } + } if v, ok := _c.mutation.Description(); ok { if err := channelmonitorrequesttemplate.DescriptionValidator(v); err != nil { return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.description": %w`, err)} @@ -258,6 +284,10 @@ func (_c *ChannelMonitorRequestTemplateCreate) createSpec() (*ChannelMonitorRequ _spec.SetField(channelmonitorrequesttemplate.FieldProvider, field.TypeEnum, value) _node.Provider = value } + if value, ok := _c.mutation.APIMode(); ok { + _spec.SetField(channelmonitorrequesttemplate.FieldAPIMode, field.TypeString, value) + _node.APIMode = value + } if value, ok := _c.mutation.Description(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldDescription, field.TypeString, value) _node.Description = value @@ -378,6 +408,18 @@ func (u *ChannelMonitorRequestTemplateUpsert) UpdateProvider() *ChannelMonitorRe return u } +// SetAPIMode sets the "api_mode" field. +func (u *ChannelMonitorRequestTemplateUpsert) SetAPIMode(v string) *ChannelMonitorRequestTemplateUpsert { + u.Set(channelmonitorrequesttemplate.FieldAPIMode, v) + return u +} + +// UpdateAPIMode sets the "api_mode" field to the value that was provided on create. +func (u *ChannelMonitorRequestTemplateUpsert) UpdateAPIMode() *ChannelMonitorRequestTemplateUpsert { + u.SetExcluded(channelmonitorrequesttemplate.FieldAPIMode) + return u +} + // SetDescription sets the "description" field. func (u *ChannelMonitorRequestTemplateUpsert) SetDescription(v string) *ChannelMonitorRequestTemplateUpsert { u.Set(channelmonitorrequesttemplate.FieldDescription, v) @@ -525,6 +567,20 @@ func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateProvider() *ChannelMonito }) } +// SetAPIMode sets the "api_mode" field. +func (u *ChannelMonitorRequestTemplateUpsertOne) SetAPIMode(v string) *ChannelMonitorRequestTemplateUpsertOne { + return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { + s.SetAPIMode(v) + }) +} + +// UpdateAPIMode sets the "api_mode" field to the value that was provided on create. +func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateAPIMode() *ChannelMonitorRequestTemplateUpsertOne { + return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { + s.UpdateAPIMode() + }) +} + // SetDescription sets the "description" field. func (u *ChannelMonitorRequestTemplateUpsertOne) SetDescription(v string) *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { @@ -848,6 +904,20 @@ func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateProvider() *ChannelMonit }) } +// SetAPIMode sets the "api_mode" field. +func (u *ChannelMonitorRequestTemplateUpsertBulk) SetAPIMode(v string) *ChannelMonitorRequestTemplateUpsertBulk { + return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { + s.SetAPIMode(v) + }) +} + +// UpdateAPIMode sets the "api_mode" field to the value that was provided on create. +func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateAPIMode() *ChannelMonitorRequestTemplateUpsertBulk { + return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { + s.UpdateAPIMode() + }) +} + // SetDescription sets the "description" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) SetDescription(v string) *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { diff --git a/backend/ent/channelmonitorrequesttemplate_update.go b/backend/ent/channelmonitorrequesttemplate_update.go index 8f55ba04..f27cac1c 100644 --- a/backend/ent/channelmonitorrequesttemplate_update.go +++ b/backend/ent/channelmonitorrequesttemplate_update.go @@ -63,6 +63,20 @@ func (_u *ChannelMonitorRequestTemplateUpdate) SetNillableProvider(v *channelmon return _u } +// SetAPIMode sets the "api_mode" field. +func (_u *ChannelMonitorRequestTemplateUpdate) SetAPIMode(v string) *ChannelMonitorRequestTemplateUpdate { + _u.mutation.SetAPIMode(v) + return _u +} + +// SetNillableAPIMode sets the "api_mode" field if the given value is not nil. +func (_u *ChannelMonitorRequestTemplateUpdate) SetNillableAPIMode(v *string) *ChannelMonitorRequestTemplateUpdate { + if v != nil { + _u.SetAPIMode(*v) + } + return _u +} + // SetDescription sets the "description" field. func (_u *ChannelMonitorRequestTemplateUpdate) SetDescription(v string) *ChannelMonitorRequestTemplateUpdate { _u.mutation.SetDescription(v) @@ -204,6 +218,11 @@ func (_u *ChannelMonitorRequestTemplateUpdate) check() error { return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.provider": %w`, err)} } } + if v, ok := _u.mutation.APIMode(); ok { + if err := channelmonitorrequesttemplate.APIModeValidator(v); err != nil { + return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.api_mode": %w`, err)} + } + } if v, ok := _u.mutation.Description(); ok { if err := channelmonitorrequesttemplate.DescriptionValidator(v); err != nil { return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.description": %w`, err)} @@ -238,6 +257,9 @@ func (_u *ChannelMonitorRequestTemplateUpdate) sqlSave(ctx context.Context) (_no if value, ok := _u.mutation.Provider(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldProvider, field.TypeEnum, value) } + if value, ok := _u.mutation.APIMode(); ok { + _spec.SetField(channelmonitorrequesttemplate.FieldAPIMode, field.TypeString, value) + } if value, ok := _u.mutation.Description(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldDescription, field.TypeString, value) } @@ -355,6 +377,20 @@ func (_u *ChannelMonitorRequestTemplateUpdateOne) SetNillableProvider(v *channel return _u } +// SetAPIMode sets the "api_mode" field. +func (_u *ChannelMonitorRequestTemplateUpdateOne) SetAPIMode(v string) *ChannelMonitorRequestTemplateUpdateOne { + _u.mutation.SetAPIMode(v) + return _u +} + +// SetNillableAPIMode sets the "api_mode" field if the given value is not nil. +func (_u *ChannelMonitorRequestTemplateUpdateOne) SetNillableAPIMode(v *string) *ChannelMonitorRequestTemplateUpdateOne { + if v != nil { + _u.SetAPIMode(*v) + } + return _u +} + // SetDescription sets the "description" field. func (_u *ChannelMonitorRequestTemplateUpdateOne) SetDescription(v string) *ChannelMonitorRequestTemplateUpdateOne { _u.mutation.SetDescription(v) @@ -509,6 +545,11 @@ func (_u *ChannelMonitorRequestTemplateUpdateOne) check() error { return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.provider": %w`, err)} } } + if v, ok := _u.mutation.APIMode(); ok { + if err := channelmonitorrequesttemplate.APIModeValidator(v); err != nil { + return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.api_mode": %w`, err)} + } + } if v, ok := _u.mutation.Description(); ok { if err := channelmonitorrequesttemplate.DescriptionValidator(v); err != nil { return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.description": %w`, err)} @@ -560,6 +601,9 @@ func (_u *ChannelMonitorRequestTemplateUpdateOne) sqlSave(ctx context.Context) ( if value, ok := _u.mutation.Provider(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldProvider, field.TypeEnum, value) } + if value, ok := _u.mutation.APIMode(); ok { + _spec.SetField(channelmonitorrequesttemplate.FieldAPIMode, field.TypeString, value) + } if value, ok := _u.mutation.Description(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldDescription, field.TypeString, value) } diff --git a/backend/ent/migrate/schema.go b/backend/ent/migrate/schema.go index f98761ea..b1731a35 100644 --- a/backend/ent/migrate/schema.go +++ b/backend/ent/migrate/schema.go @@ -428,6 +428,7 @@ var ( {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}}, {Name: "name", Type: field.TypeString, Size: 100}, {Name: "provider", Type: field.TypeEnum, Enums: []string{"openai", "anthropic", "gemini"}}, + {Name: "api_mode", Type: field.TypeString, Size: 32, Default: "chat_completions"}, {Name: "endpoint", Type: field.TypeString, Size: 500}, {Name: "api_key_encrypted", Type: field.TypeString}, {Name: "primary_model", Type: field.TypeString, Size: 200}, @@ -450,7 +451,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "channel_monitors_channel_monitor_request_templates_request_template", - Columns: []*schema.Column{ChannelMonitorsColumns[17]}, + Columns: []*schema.Column{ChannelMonitorsColumns[18]}, RefColumns: []*schema.Column{ChannelMonitorRequestTemplatesColumns[0]}, OnDelete: schema.SetNull, }, @@ -459,22 +460,27 @@ var ( { Name: "channelmonitor_enabled_last_checked_at", Unique: false, - Columns: []*schema.Column{ChannelMonitorsColumns[10], ChannelMonitorsColumns[12]}, + Columns: []*schema.Column{ChannelMonitorsColumns[11], ChannelMonitorsColumns[13]}, }, { Name: "channelmonitor_provider", Unique: false, Columns: []*schema.Column{ChannelMonitorsColumns[4]}, }, + { + Name: "channelmonitor_provider_api_mode", + Unique: false, + Columns: []*schema.Column{ChannelMonitorsColumns[4], ChannelMonitorsColumns[5]}, + }, { Name: "channelmonitor_group_name", Unique: false, - Columns: []*schema.Column{ChannelMonitorsColumns[9]}, + Columns: []*schema.Column{ChannelMonitorsColumns[10]}, }, { Name: "channelmonitor_template_id", Unique: false, - Columns: []*schema.Column{ChannelMonitorsColumns[17]}, + Columns: []*schema.Column{ChannelMonitorsColumns[18]}, }, }, } @@ -566,6 +572,7 @@ var ( {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}}, {Name: "name", Type: field.TypeString, Size: 100}, {Name: "provider", Type: field.TypeEnum, Enums: []string{"openai", "anthropic", "gemini"}}, + {Name: "api_mode", Type: field.TypeString, Size: 32, Default: "chat_completions"}, {Name: "description", Type: field.TypeString, Nullable: true, Size: 500, Default: ""}, {Name: "extra_headers", Type: field.TypeJSON}, {Name: "body_override_mode", Type: field.TypeString, Size: 10, Default: "off"}, @@ -582,6 +589,11 @@ var ( Unique: true, Columns: []*schema.Column{ChannelMonitorRequestTemplatesColumns[4], ChannelMonitorRequestTemplatesColumns[3]}, }, + { + Name: "channelmonitorrequesttemplate_provider_api_mode", + Unique: false, + Columns: []*schema.Column{ChannelMonitorRequestTemplatesColumns[4], ChannelMonitorRequestTemplatesColumns[5]}, + }, }, } // ErrorPassthroughRulesColumns holds the columns for the "error_passthrough_rules" table. diff --git a/backend/ent/mutation.go b/backend/ent/mutation.go index 45c56314..af0edc68 100644 --- a/backend/ent/mutation.go +++ b/backend/ent/mutation.go @@ -8752,6 +8752,7 @@ type ChannelMonitorMutation struct { updated_at *time.Time name *string provider *channelmonitor.Provider + api_mode *string endpoint *string api_key_encrypted *string primary_model *string @@ -9023,6 +9024,42 @@ func (m *ChannelMonitorMutation) ResetProvider() { m.provider = nil } +// SetAPIMode sets the "api_mode" field. +func (m *ChannelMonitorMutation) SetAPIMode(s string) { + m.api_mode = &s +} + +// APIMode returns the value of the "api_mode" field in the mutation. +func (m *ChannelMonitorMutation) APIMode() (r string, exists bool) { + v := m.api_mode + if v == nil { + return + } + return *v, true +} + +// OldAPIMode returns the old "api_mode" field's value of the ChannelMonitor entity. +// If the ChannelMonitor object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChannelMonitorMutation) OldAPIMode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAPIMode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAPIMode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAPIMode: %w", err) + } + return oldValue.APIMode, nil +} + +// ResetAPIMode resets all changes to the "api_mode" field. +func (m *ChannelMonitorMutation) ResetAPIMode() { + m.api_mode = nil +} + // SetEndpoint sets the "endpoint" field. func (m *ChannelMonitorMutation) SetEndpoint(s string) { m.endpoint = &s @@ -9780,7 +9817,7 @@ func (m *ChannelMonitorMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ChannelMonitorMutation) Fields() []string { - fields := make([]string, 0, 17) + fields := make([]string, 0, 18) if m.created_at != nil { fields = append(fields, channelmonitor.FieldCreatedAt) } @@ -9793,6 +9830,9 @@ func (m *ChannelMonitorMutation) Fields() []string { if m.provider != nil { fields = append(fields, channelmonitor.FieldProvider) } + if m.api_mode != nil { + fields = append(fields, channelmonitor.FieldAPIMode) + } if m.endpoint != nil { fields = append(fields, channelmonitor.FieldEndpoint) } @@ -9848,6 +9888,8 @@ func (m *ChannelMonitorMutation) Field(name string) (ent.Value, bool) { return m.Name() case channelmonitor.FieldProvider: return m.Provider() + case channelmonitor.FieldAPIMode: + return m.APIMode() case channelmonitor.FieldEndpoint: return m.Endpoint() case channelmonitor.FieldAPIKeyEncrypted: @@ -9891,6 +9933,8 @@ func (m *ChannelMonitorMutation) OldField(ctx context.Context, name string) (ent return m.OldName(ctx) case channelmonitor.FieldProvider: return m.OldProvider(ctx) + case channelmonitor.FieldAPIMode: + return m.OldAPIMode(ctx) case channelmonitor.FieldEndpoint: return m.OldEndpoint(ctx) case channelmonitor.FieldAPIKeyEncrypted: @@ -9954,6 +9998,13 @@ func (m *ChannelMonitorMutation) SetField(name string, value ent.Value) error { } m.SetProvider(v) return nil + case channelmonitor.FieldAPIMode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAPIMode(v) + return nil case channelmonitor.FieldEndpoint: v, ok := value.(string) if !ok { @@ -10160,6 +10211,9 @@ func (m *ChannelMonitorMutation) ResetField(name string) error { case channelmonitor.FieldProvider: m.ResetProvider() return nil + case channelmonitor.FieldAPIMode: + m.ResetAPIMode() + return nil case channelmonitor.FieldEndpoint: m.ResetEndpoint() return nil @@ -12591,6 +12645,7 @@ type ChannelMonitorRequestTemplateMutation struct { updated_at *time.Time name *string provider *channelmonitorrequesttemplate.Provider + api_mode *string description *string extra_headers *map[string]string body_override_mode *string @@ -12846,6 +12901,42 @@ func (m *ChannelMonitorRequestTemplateMutation) ResetProvider() { m.provider = nil } +// SetAPIMode sets the "api_mode" field. +func (m *ChannelMonitorRequestTemplateMutation) SetAPIMode(s string) { + m.api_mode = &s +} + +// APIMode returns the value of the "api_mode" field in the mutation. +func (m *ChannelMonitorRequestTemplateMutation) APIMode() (r string, exists bool) { + v := m.api_mode + if v == nil { + return + } + return *v, true +} + +// OldAPIMode returns the old "api_mode" field's value of the ChannelMonitorRequestTemplate entity. +// If the ChannelMonitorRequestTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ChannelMonitorRequestTemplateMutation) OldAPIMode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAPIMode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAPIMode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAPIMode: %w", err) + } + return oldValue.APIMode, nil +} + +// ResetAPIMode resets all changes to the "api_mode" field. +func (m *ChannelMonitorRequestTemplateMutation) ResetAPIMode() { + m.api_mode = nil +} + // SetDescription sets the "description" field. func (m *ChannelMonitorRequestTemplateMutation) SetDescription(s string) { m.description = &s @@ -13104,7 +13195,7 @@ func (m *ChannelMonitorRequestTemplateMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ChannelMonitorRequestTemplateMutation) Fields() []string { - fields := make([]string, 0, 8) + fields := make([]string, 0, 9) if m.created_at != nil { fields = append(fields, channelmonitorrequesttemplate.FieldCreatedAt) } @@ -13117,6 +13208,9 @@ func (m *ChannelMonitorRequestTemplateMutation) Fields() []string { if m.provider != nil { fields = append(fields, channelmonitorrequesttemplate.FieldProvider) } + if m.api_mode != nil { + fields = append(fields, channelmonitorrequesttemplate.FieldAPIMode) + } if m.description != nil { fields = append(fields, channelmonitorrequesttemplate.FieldDescription) } @@ -13145,6 +13239,8 @@ func (m *ChannelMonitorRequestTemplateMutation) Field(name string) (ent.Value, b return m.Name() case channelmonitorrequesttemplate.FieldProvider: return m.Provider() + case channelmonitorrequesttemplate.FieldAPIMode: + return m.APIMode() case channelmonitorrequesttemplate.FieldDescription: return m.Description() case channelmonitorrequesttemplate.FieldExtraHeaders: @@ -13170,6 +13266,8 @@ func (m *ChannelMonitorRequestTemplateMutation) OldField(ctx context.Context, na return m.OldName(ctx) case channelmonitorrequesttemplate.FieldProvider: return m.OldProvider(ctx) + case channelmonitorrequesttemplate.FieldAPIMode: + return m.OldAPIMode(ctx) case channelmonitorrequesttemplate.FieldDescription: return m.OldDescription(ctx) case channelmonitorrequesttemplate.FieldExtraHeaders: @@ -13215,6 +13313,13 @@ func (m *ChannelMonitorRequestTemplateMutation) SetField(name string, value ent. } m.SetProvider(v) return nil + case channelmonitorrequesttemplate.FieldAPIMode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAPIMode(v) + return nil case channelmonitorrequesttemplate.FieldDescription: v, ok := value.(string) if !ok { @@ -13319,6 +13424,9 @@ func (m *ChannelMonitorRequestTemplateMutation) ResetField(name string) error { case channelmonitorrequesttemplate.FieldProvider: m.ResetProvider() return nil + case channelmonitorrequesttemplate.FieldAPIMode: + m.ResetAPIMode() + return nil case channelmonitorrequesttemplate.FieldDescription: m.ResetDescription() return nil diff --git a/backend/ent/runtime/runtime.go b/backend/ent/runtime/runtime.go index b1899173..6d541e2f 100644 --- a/backend/ent/runtime/runtime.go +++ b/backend/ent/runtime/runtime.go @@ -464,8 +464,14 @@ func init() { return nil } }() + // channelmonitorDescAPIMode is the schema descriptor for api_mode field. + channelmonitorDescAPIMode := channelmonitorFields[2].Descriptor() + // channelmonitor.DefaultAPIMode holds the default value on creation for the api_mode field. + channelmonitor.DefaultAPIMode = channelmonitorDescAPIMode.Default.(string) + // channelmonitor.APIModeValidator is a validator for the "api_mode" field. It is called by the builders before save. + channelmonitor.APIModeValidator = channelmonitorDescAPIMode.Validators[0].(func(string) error) // channelmonitorDescEndpoint is the schema descriptor for endpoint field. - channelmonitorDescEndpoint := channelmonitorFields[2].Descriptor() + channelmonitorDescEndpoint := channelmonitorFields[3].Descriptor() // channelmonitor.EndpointValidator is a validator for the "endpoint" field. It is called by the builders before save. channelmonitor.EndpointValidator = func() func(string) error { validators := channelmonitorDescEndpoint.Validators @@ -483,11 +489,11 @@ func init() { } }() // channelmonitorDescAPIKeyEncrypted is the schema descriptor for api_key_encrypted field. - channelmonitorDescAPIKeyEncrypted := channelmonitorFields[3].Descriptor() + channelmonitorDescAPIKeyEncrypted := channelmonitorFields[4].Descriptor() // channelmonitor.APIKeyEncryptedValidator is a validator for the "api_key_encrypted" field. It is called by the builders before save. channelmonitor.APIKeyEncryptedValidator = channelmonitorDescAPIKeyEncrypted.Validators[0].(func(string) error) // channelmonitorDescPrimaryModel is the schema descriptor for primary_model field. - channelmonitorDescPrimaryModel := channelmonitorFields[4].Descriptor() + channelmonitorDescPrimaryModel := channelmonitorFields[5].Descriptor() // channelmonitor.PrimaryModelValidator is a validator for the "primary_model" field. It is called by the builders before save. channelmonitor.PrimaryModelValidator = func() func(string) error { validators := channelmonitorDescPrimaryModel.Validators @@ -505,29 +511,29 @@ func init() { } }() // channelmonitorDescExtraModels is the schema descriptor for extra_models field. - channelmonitorDescExtraModels := channelmonitorFields[5].Descriptor() + channelmonitorDescExtraModels := channelmonitorFields[6].Descriptor() // channelmonitor.DefaultExtraModels holds the default value on creation for the extra_models field. channelmonitor.DefaultExtraModels = channelmonitorDescExtraModels.Default.([]string) // channelmonitorDescGroupName is the schema descriptor for group_name field. - channelmonitorDescGroupName := channelmonitorFields[6].Descriptor() + channelmonitorDescGroupName := channelmonitorFields[7].Descriptor() // channelmonitor.DefaultGroupName holds the default value on creation for the group_name field. channelmonitor.DefaultGroupName = channelmonitorDescGroupName.Default.(string) // channelmonitor.GroupNameValidator is a validator for the "group_name" field. It is called by the builders before save. channelmonitor.GroupNameValidator = channelmonitorDescGroupName.Validators[0].(func(string) error) // channelmonitorDescEnabled is the schema descriptor for enabled field. - channelmonitorDescEnabled := channelmonitorFields[7].Descriptor() + channelmonitorDescEnabled := channelmonitorFields[8].Descriptor() // channelmonitor.DefaultEnabled holds the default value on creation for the enabled field. channelmonitor.DefaultEnabled = channelmonitorDescEnabled.Default.(bool) // channelmonitorDescIntervalSeconds is the schema descriptor for interval_seconds field. - channelmonitorDescIntervalSeconds := channelmonitorFields[8].Descriptor() + channelmonitorDescIntervalSeconds := channelmonitorFields[9].Descriptor() // channelmonitor.IntervalSecondsValidator is a validator for the "interval_seconds" field. It is called by the builders before save. channelmonitor.IntervalSecondsValidator = channelmonitorDescIntervalSeconds.Validators[0].(func(int) error) // channelmonitorDescExtraHeaders is the schema descriptor for extra_headers field. - channelmonitorDescExtraHeaders := channelmonitorFields[12].Descriptor() + channelmonitorDescExtraHeaders := channelmonitorFields[13].Descriptor() // channelmonitor.DefaultExtraHeaders holds the default value on creation for the extra_headers field. channelmonitor.DefaultExtraHeaders = channelmonitorDescExtraHeaders.Default.(map[string]string) // channelmonitorDescBodyOverrideMode is the schema descriptor for body_override_mode field. - channelmonitorDescBodyOverrideMode := channelmonitorFields[13].Descriptor() + channelmonitorDescBodyOverrideMode := channelmonitorFields[14].Descriptor() // channelmonitor.DefaultBodyOverrideMode holds the default value on creation for the body_override_mode field. channelmonitor.DefaultBodyOverrideMode = channelmonitorDescBodyOverrideMode.Default.(string) // channelmonitor.BodyOverrideModeValidator is a validator for the "body_override_mode" field. It is called by the builders before save. @@ -661,18 +667,24 @@ func init() { return nil } }() + // channelmonitorrequesttemplateDescAPIMode is the schema descriptor for api_mode field. + channelmonitorrequesttemplateDescAPIMode := channelmonitorrequesttemplateFields[2].Descriptor() + // channelmonitorrequesttemplate.DefaultAPIMode holds the default value on creation for the api_mode field. + channelmonitorrequesttemplate.DefaultAPIMode = channelmonitorrequesttemplateDescAPIMode.Default.(string) + // channelmonitorrequesttemplate.APIModeValidator is a validator for the "api_mode" field. It is called by the builders before save. + channelmonitorrequesttemplate.APIModeValidator = channelmonitorrequesttemplateDescAPIMode.Validators[0].(func(string) error) // channelmonitorrequesttemplateDescDescription is the schema descriptor for description field. - channelmonitorrequesttemplateDescDescription := channelmonitorrequesttemplateFields[2].Descriptor() + channelmonitorrequesttemplateDescDescription := channelmonitorrequesttemplateFields[3].Descriptor() // channelmonitorrequesttemplate.DefaultDescription holds the default value on creation for the description field. channelmonitorrequesttemplate.DefaultDescription = channelmonitorrequesttemplateDescDescription.Default.(string) // channelmonitorrequesttemplate.DescriptionValidator is a validator for the "description" field. It is called by the builders before save. channelmonitorrequesttemplate.DescriptionValidator = channelmonitorrequesttemplateDescDescription.Validators[0].(func(string) error) // channelmonitorrequesttemplateDescExtraHeaders is the schema descriptor for extra_headers field. - channelmonitorrequesttemplateDescExtraHeaders := channelmonitorrequesttemplateFields[3].Descriptor() + channelmonitorrequesttemplateDescExtraHeaders := channelmonitorrequesttemplateFields[4].Descriptor() // channelmonitorrequesttemplate.DefaultExtraHeaders holds the default value on creation for the extra_headers field. channelmonitorrequesttemplate.DefaultExtraHeaders = channelmonitorrequesttemplateDescExtraHeaders.Default.(map[string]string) // channelmonitorrequesttemplateDescBodyOverrideMode is the schema descriptor for body_override_mode field. - channelmonitorrequesttemplateDescBodyOverrideMode := channelmonitorrequesttemplateFields[4].Descriptor() + channelmonitorrequesttemplateDescBodyOverrideMode := channelmonitorrequesttemplateFields[5].Descriptor() // channelmonitorrequesttemplate.DefaultBodyOverrideMode holds the default value on creation for the body_override_mode field. channelmonitorrequesttemplate.DefaultBodyOverrideMode = channelmonitorrequesttemplateDescBodyOverrideMode.Default.(string) // channelmonitorrequesttemplate.BodyOverrideModeValidator is a validator for the "body_override_mode" field. It is called by the builders before save. diff --git a/backend/ent/schema/channel_monitor.go b/backend/ent/schema/channel_monitor.go index 355ade4b..431ab9c8 100644 --- a/backend/ent/schema/channel_monitor.go +++ b/backend/ent/schema/channel_monitor.go @@ -36,6 +36,10 @@ func (ChannelMonitor) Fields() []ent.Field { MaxLen(100), field.Enum("provider"). Values("openai", "anthropic", "gemini"), + field.String("api_mode"). + Default("chat_completions"). + MaxLen(32). + Comment("OpenAI request protocol: chat_completions or responses; non-OpenAI uses chat_completions"), field.String("endpoint"). NotEmpty(). MaxLen(500). @@ -104,6 +108,7 @@ func (ChannelMonitor) Indexes() []ent.Index { return []ent.Index{ index.Fields("enabled", "last_checked_at"), index.Fields("provider"), + index.Fields("provider", "api_mode"), index.Fields("group_name"), index.Fields("template_id"), } diff --git a/backend/ent/schema/channel_monitor_request_template.go b/backend/ent/schema/channel_monitor_request_template.go index 59df2f29..0e0ce3a0 100644 --- a/backend/ent/schema/channel_monitor_request_template.go +++ b/backend/ent/schema/channel_monitor_request_template.go @@ -40,6 +40,10 @@ func (ChannelMonitorRequestTemplate) Fields() []ent.Field { MaxLen(100), field.Enum("provider"). Values("openai", "anthropic", "gemini"), + field.String("api_mode"). + Default("chat_completions"). + MaxLen(32). + Comment("OpenAI request protocol: chat_completions or responses; non-OpenAI uses chat_completions"), field.String("description"). Optional(). Default(""). @@ -76,5 +80,6 @@ func (ChannelMonitorRequestTemplate) Indexes() []ent.Index { return []ent.Index{ // 同一 provider 内 name 唯一:允许 Anthropic + OpenAI 重名 "伪装官方客户端"。 index.Fields("provider", "name").Unique(), + index.Fields("provider", "api_mode"), } }