channelmonitor.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. "github.com/Wei-Shaw/sub2api/ent/channelmonitor"
  11. "github.com/Wei-Shaw/sub2api/ent/channelmonitorrequesttemplate"
  12. )
  13. // ChannelMonitor is the model entity for the ChannelMonitor schema.
  14. type ChannelMonitor struct {
  15. config `json:"-"`
  16. // ID of the ent.
  17. ID int64 `json:"id,omitempty"`
  18. // CreatedAt holds the value of the "created_at" field.
  19. CreatedAt time.Time `json:"created_at,omitempty"`
  20. // UpdatedAt holds the value of the "updated_at" field.
  21. UpdatedAt time.Time `json:"updated_at,omitempty"`
  22. // Name holds the value of the "name" field.
  23. Name string `json:"name,omitempty"`
  24. // Provider holds the value of the "provider" field.
  25. Provider channelmonitor.Provider `json:"provider,omitempty"`
  26. // probe = LLM probe (default); quota = account usage only; quota_probe = both
  27. CheckMode string `json:"check_mode,omitempty"`
  28. // AccountID holds the value of the "account_id" field.
  29. AccountID *int64 `json:"account_id,omitempty"`
  30. // OpenAI request protocol: chat_completions or responses; non-OpenAI uses chat_completions
  31. APIMode string `json:"api_mode,omitempty"`
  32. // Provider base origin, e.g. https://api.openai.com; empty for quota-only monitors
  33. Endpoint string `json:"endpoint,omitempty"`
  34. // AES-256-GCM encrypted API key
  35. APIKeyEncrypted string `json:"-"`
  36. // PrimaryModel holds the value of the "primary_model" field.
  37. PrimaryModel string `json:"primary_model,omitempty"`
  38. // Additional model names to test alongside primary_model
  39. ExtraModels []string `json:"extra_models,omitempty"`
  40. // GroupName holds the value of the "group_name" field.
  41. GroupName string `json:"group_name,omitempty"`
  42. // Enabled holds the value of the "enabled" field.
  43. Enabled bool `json:"enabled,omitempty"`
  44. // IntervalSeconds holds the value of the "interval_seconds" field.
  45. IntervalSeconds int `json:"interval_seconds,omitempty"`
  46. // 每次调度在 interval 基础上 ± [0, jitter] 的均匀随机偏移(秒);0 表示固定间隔。service 层另保证 interval - jitter >= 15
  47. JitterSeconds int `json:"jitter_seconds,omitempty"`
  48. // LastCheckedAt holds the value of the "last_checked_at" field.
  49. LastCheckedAt *time.Time `json:"last_checked_at,omitempty"`
  50. // CreatedBy holds the value of the "created_by" field.
  51. CreatedBy int64 `json:"created_by,omitempty"`
  52. // TemplateID holds the value of the "template_id" field.
  53. TemplateID *int64 `json:"template_id,omitempty"`
  54. // ExtraHeaders holds the value of the "extra_headers" field.
  55. ExtraHeaders map[string]string `json:"extra_headers,omitempty"`
  56. // BodyOverrideMode holds the value of the "body_override_mode" field.
  57. BodyOverrideMode string `json:"body_override_mode,omitempty"`
  58. // BodyOverride holds the value of the "body_override" field.
  59. BodyOverride map[string]interface{} `json:"body_override,omitempty"`
  60. // Edges holds the relations/edges for other nodes in the graph.
  61. // The values are being populated by the ChannelMonitorQuery when eager-loading is set.
  62. Edges ChannelMonitorEdges `json:"edges"`
  63. selectValues sql.SelectValues
  64. }
  65. // ChannelMonitorEdges holds the relations/edges for other nodes in the graph.
  66. type ChannelMonitorEdges struct {
  67. // History holds the value of the history edge.
  68. History []*ChannelMonitorHistory `json:"history,omitempty"`
  69. // DailyRollups holds the value of the daily_rollups edge.
  70. DailyRollups []*ChannelMonitorDailyRollup `json:"daily_rollups,omitempty"`
  71. // RequestTemplate holds the value of the request_template edge.
  72. RequestTemplate *ChannelMonitorRequestTemplate `json:"request_template,omitempty"`
  73. // loadedTypes holds the information for reporting if a
  74. // type was loaded (or requested) in eager-loading or not.
  75. loadedTypes [3]bool
  76. }
  77. // HistoryOrErr returns the History value or an error if the edge
  78. // was not loaded in eager-loading.
  79. func (e ChannelMonitorEdges) HistoryOrErr() ([]*ChannelMonitorHistory, error) {
  80. if e.loadedTypes[0] {
  81. return e.History, nil
  82. }
  83. return nil, &NotLoadedError{edge: "history"}
  84. }
  85. // DailyRollupsOrErr returns the DailyRollups value or an error if the edge
  86. // was not loaded in eager-loading.
  87. func (e ChannelMonitorEdges) DailyRollupsOrErr() ([]*ChannelMonitorDailyRollup, error) {
  88. if e.loadedTypes[1] {
  89. return e.DailyRollups, nil
  90. }
  91. return nil, &NotLoadedError{edge: "daily_rollups"}
  92. }
  93. // RequestTemplateOrErr returns the RequestTemplate value or an error if the edge
  94. // was not loaded in eager-loading, or loaded but was not found.
  95. func (e ChannelMonitorEdges) RequestTemplateOrErr() (*ChannelMonitorRequestTemplate, error) {
  96. if e.RequestTemplate != nil {
  97. return e.RequestTemplate, nil
  98. } else if e.loadedTypes[2] {
  99. return nil, &NotFoundError{label: channelmonitorrequesttemplate.Label}
  100. }
  101. return nil, &NotLoadedError{edge: "request_template"}
  102. }
  103. // scanValues returns the types for scanning values from sql.Rows.
  104. func (*ChannelMonitor) scanValues(columns []string) ([]any, error) {
  105. values := make([]any, len(columns))
  106. for i := range columns {
  107. switch columns[i] {
  108. case channelmonitor.FieldExtraModels, channelmonitor.FieldExtraHeaders, channelmonitor.FieldBodyOverride:
  109. values[i] = new([]byte)
  110. case channelmonitor.FieldEnabled:
  111. values[i] = new(sql.NullBool)
  112. case channelmonitor.FieldID, channelmonitor.FieldAccountID, channelmonitor.FieldIntervalSeconds, channelmonitor.FieldJitterSeconds, channelmonitor.FieldCreatedBy, channelmonitor.FieldTemplateID:
  113. values[i] = new(sql.NullInt64)
  114. case channelmonitor.FieldName, channelmonitor.FieldProvider, channelmonitor.FieldCheckMode, channelmonitor.FieldAPIMode, channelmonitor.FieldEndpoint, channelmonitor.FieldAPIKeyEncrypted, channelmonitor.FieldPrimaryModel, channelmonitor.FieldGroupName, channelmonitor.FieldBodyOverrideMode:
  115. values[i] = new(sql.NullString)
  116. case channelmonitor.FieldCreatedAt, channelmonitor.FieldUpdatedAt, channelmonitor.FieldLastCheckedAt:
  117. values[i] = new(sql.NullTime)
  118. default:
  119. values[i] = new(sql.UnknownType)
  120. }
  121. }
  122. return values, nil
  123. }
  124. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  125. // to the ChannelMonitor fields.
  126. func (_m *ChannelMonitor) assignValues(columns []string, values []any) error {
  127. if m, n := len(values), len(columns); m < n {
  128. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  129. }
  130. for i := range columns {
  131. switch columns[i] {
  132. case channelmonitor.FieldID:
  133. value, ok := values[i].(*sql.NullInt64)
  134. if !ok {
  135. return fmt.Errorf("unexpected type %T for field id", value)
  136. }
  137. _m.ID = int64(value.Int64)
  138. case channelmonitor.FieldCreatedAt:
  139. if value, ok := values[i].(*sql.NullTime); !ok {
  140. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  141. } else if value.Valid {
  142. _m.CreatedAt = value.Time
  143. }
  144. case channelmonitor.FieldUpdatedAt:
  145. if value, ok := values[i].(*sql.NullTime); !ok {
  146. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  147. } else if value.Valid {
  148. _m.UpdatedAt = value.Time
  149. }
  150. case channelmonitor.FieldName:
  151. if value, ok := values[i].(*sql.NullString); !ok {
  152. return fmt.Errorf("unexpected type %T for field name", values[i])
  153. } else if value.Valid {
  154. _m.Name = value.String
  155. }
  156. case channelmonitor.FieldProvider:
  157. if value, ok := values[i].(*sql.NullString); !ok {
  158. return fmt.Errorf("unexpected type %T for field provider", values[i])
  159. } else if value.Valid {
  160. _m.Provider = channelmonitor.Provider(value.String)
  161. }
  162. case channelmonitor.FieldCheckMode:
  163. if value, ok := values[i].(*sql.NullString); !ok {
  164. return fmt.Errorf("unexpected type %T for field check_mode", values[i])
  165. } else if value.Valid {
  166. _m.CheckMode = value.String
  167. }
  168. case channelmonitor.FieldAccountID:
  169. if value, ok := values[i].(*sql.NullInt64); !ok {
  170. return fmt.Errorf("unexpected type %T for field account_id", values[i])
  171. } else if value.Valid {
  172. _m.AccountID = new(int64)
  173. *_m.AccountID = value.Int64
  174. }
  175. case channelmonitor.FieldAPIMode:
  176. if value, ok := values[i].(*sql.NullString); !ok {
  177. return fmt.Errorf("unexpected type %T for field api_mode", values[i])
  178. } else if value.Valid {
  179. _m.APIMode = value.String
  180. }
  181. case channelmonitor.FieldEndpoint:
  182. if value, ok := values[i].(*sql.NullString); !ok {
  183. return fmt.Errorf("unexpected type %T for field endpoint", values[i])
  184. } else if value.Valid {
  185. _m.Endpoint = value.String
  186. }
  187. case channelmonitor.FieldAPIKeyEncrypted:
  188. if value, ok := values[i].(*sql.NullString); !ok {
  189. return fmt.Errorf("unexpected type %T for field api_key_encrypted", values[i])
  190. } else if value.Valid {
  191. _m.APIKeyEncrypted = value.String
  192. }
  193. case channelmonitor.FieldPrimaryModel:
  194. if value, ok := values[i].(*sql.NullString); !ok {
  195. return fmt.Errorf("unexpected type %T for field primary_model", values[i])
  196. } else if value.Valid {
  197. _m.PrimaryModel = value.String
  198. }
  199. case channelmonitor.FieldExtraModels:
  200. if value, ok := values[i].(*[]byte); !ok {
  201. return fmt.Errorf("unexpected type %T for field extra_models", values[i])
  202. } else if value != nil && len(*value) > 0 {
  203. if err := json.Unmarshal(*value, &_m.ExtraModels); err != nil {
  204. return fmt.Errorf("unmarshal field extra_models: %w", err)
  205. }
  206. }
  207. case channelmonitor.FieldGroupName:
  208. if value, ok := values[i].(*sql.NullString); !ok {
  209. return fmt.Errorf("unexpected type %T for field group_name", values[i])
  210. } else if value.Valid {
  211. _m.GroupName = value.String
  212. }
  213. case channelmonitor.FieldEnabled:
  214. if value, ok := values[i].(*sql.NullBool); !ok {
  215. return fmt.Errorf("unexpected type %T for field enabled", values[i])
  216. } else if value.Valid {
  217. _m.Enabled = value.Bool
  218. }
  219. case channelmonitor.FieldIntervalSeconds:
  220. if value, ok := values[i].(*sql.NullInt64); !ok {
  221. return fmt.Errorf("unexpected type %T for field interval_seconds", values[i])
  222. } else if value.Valid {
  223. _m.IntervalSeconds = int(value.Int64)
  224. }
  225. case channelmonitor.FieldJitterSeconds:
  226. if value, ok := values[i].(*sql.NullInt64); !ok {
  227. return fmt.Errorf("unexpected type %T for field jitter_seconds", values[i])
  228. } else if value.Valid {
  229. _m.JitterSeconds = int(value.Int64)
  230. }
  231. case channelmonitor.FieldLastCheckedAt:
  232. if value, ok := values[i].(*sql.NullTime); !ok {
  233. return fmt.Errorf("unexpected type %T for field last_checked_at", values[i])
  234. } else if value.Valid {
  235. _m.LastCheckedAt = new(time.Time)
  236. *_m.LastCheckedAt = value.Time
  237. }
  238. case channelmonitor.FieldCreatedBy:
  239. if value, ok := values[i].(*sql.NullInt64); !ok {
  240. return fmt.Errorf("unexpected type %T for field created_by", values[i])
  241. } else if value.Valid {
  242. _m.CreatedBy = value.Int64
  243. }
  244. case channelmonitor.FieldTemplateID:
  245. if value, ok := values[i].(*sql.NullInt64); !ok {
  246. return fmt.Errorf("unexpected type %T for field template_id", values[i])
  247. } else if value.Valid {
  248. _m.TemplateID = new(int64)
  249. *_m.TemplateID = value.Int64
  250. }
  251. case channelmonitor.FieldExtraHeaders:
  252. if value, ok := values[i].(*[]byte); !ok {
  253. return fmt.Errorf("unexpected type %T for field extra_headers", values[i])
  254. } else if value != nil && len(*value) > 0 {
  255. if err := json.Unmarshal(*value, &_m.ExtraHeaders); err != nil {
  256. return fmt.Errorf("unmarshal field extra_headers: %w", err)
  257. }
  258. }
  259. case channelmonitor.FieldBodyOverrideMode:
  260. if value, ok := values[i].(*sql.NullString); !ok {
  261. return fmt.Errorf("unexpected type %T for field body_override_mode", values[i])
  262. } else if value.Valid {
  263. _m.BodyOverrideMode = value.String
  264. }
  265. case channelmonitor.FieldBodyOverride:
  266. if value, ok := values[i].(*[]byte); !ok {
  267. return fmt.Errorf("unexpected type %T for field body_override", values[i])
  268. } else if value != nil && len(*value) > 0 {
  269. if err := json.Unmarshal(*value, &_m.BodyOverride); err != nil {
  270. return fmt.Errorf("unmarshal field body_override: %w", err)
  271. }
  272. }
  273. default:
  274. _m.selectValues.Set(columns[i], values[i])
  275. }
  276. }
  277. return nil
  278. }
  279. // Value returns the ent.Value that was dynamically selected and assigned to the ChannelMonitor.
  280. // This includes values selected through modifiers, order, etc.
  281. func (_m *ChannelMonitor) Value(name string) (ent.Value, error) {
  282. return _m.selectValues.Get(name)
  283. }
  284. // QueryHistory queries the "history" edge of the ChannelMonitor entity.
  285. func (_m *ChannelMonitor) QueryHistory() *ChannelMonitorHistoryQuery {
  286. return NewChannelMonitorClient(_m.config).QueryHistory(_m)
  287. }
  288. // QueryDailyRollups queries the "daily_rollups" edge of the ChannelMonitor entity.
  289. func (_m *ChannelMonitor) QueryDailyRollups() *ChannelMonitorDailyRollupQuery {
  290. return NewChannelMonitorClient(_m.config).QueryDailyRollups(_m)
  291. }
  292. // QueryRequestTemplate queries the "request_template" edge of the ChannelMonitor entity.
  293. func (_m *ChannelMonitor) QueryRequestTemplate() *ChannelMonitorRequestTemplateQuery {
  294. return NewChannelMonitorClient(_m.config).QueryRequestTemplate(_m)
  295. }
  296. // Update returns a builder for updating this ChannelMonitor.
  297. // Note that you need to call ChannelMonitor.Unwrap() before calling this method if this ChannelMonitor
  298. // was returned from a transaction, and the transaction was committed or rolled back.
  299. func (_m *ChannelMonitor) Update() *ChannelMonitorUpdateOne {
  300. return NewChannelMonitorClient(_m.config).UpdateOne(_m)
  301. }
  302. // Unwrap unwraps the ChannelMonitor entity that was returned from a transaction after it was closed,
  303. // so that all future queries will be executed through the driver which created the transaction.
  304. func (_m *ChannelMonitor) Unwrap() *ChannelMonitor {
  305. _tx, ok := _m.config.driver.(*txDriver)
  306. if !ok {
  307. panic("ent: ChannelMonitor is not a transactional entity")
  308. }
  309. _m.config.driver = _tx.drv
  310. return _m
  311. }
  312. // String implements the fmt.Stringer.
  313. func (_m *ChannelMonitor) String() string {
  314. var builder strings.Builder
  315. builder.WriteString("ChannelMonitor(")
  316. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  317. builder.WriteString("created_at=")
  318. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  319. builder.WriteString(", ")
  320. builder.WriteString("updated_at=")
  321. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  322. builder.WriteString(", ")
  323. builder.WriteString("name=")
  324. builder.WriteString(_m.Name)
  325. builder.WriteString(", ")
  326. builder.WriteString("provider=")
  327. builder.WriteString(fmt.Sprintf("%v", _m.Provider))
  328. builder.WriteString(", ")
  329. builder.WriteString("check_mode=")
  330. builder.WriteString(_m.CheckMode)
  331. builder.WriteString(", ")
  332. if v := _m.AccountID; v != nil {
  333. builder.WriteString("account_id=")
  334. builder.WriteString(fmt.Sprintf("%v", *v))
  335. }
  336. builder.WriteString(", ")
  337. builder.WriteString("api_mode=")
  338. builder.WriteString(_m.APIMode)
  339. builder.WriteString(", ")
  340. builder.WriteString("endpoint=")
  341. builder.WriteString(_m.Endpoint)
  342. builder.WriteString(", ")
  343. builder.WriteString("api_key_encrypted=<sensitive>")
  344. builder.WriteString(", ")
  345. builder.WriteString("primary_model=")
  346. builder.WriteString(_m.PrimaryModel)
  347. builder.WriteString(", ")
  348. builder.WriteString("extra_models=")
  349. builder.WriteString(fmt.Sprintf("%v", _m.ExtraModels))
  350. builder.WriteString(", ")
  351. builder.WriteString("group_name=")
  352. builder.WriteString(_m.GroupName)
  353. builder.WriteString(", ")
  354. builder.WriteString("enabled=")
  355. builder.WriteString(fmt.Sprintf("%v", _m.Enabled))
  356. builder.WriteString(", ")
  357. builder.WriteString("interval_seconds=")
  358. builder.WriteString(fmt.Sprintf("%v", _m.IntervalSeconds))
  359. builder.WriteString(", ")
  360. builder.WriteString("jitter_seconds=")
  361. builder.WriteString(fmt.Sprintf("%v", _m.JitterSeconds))
  362. builder.WriteString(", ")
  363. if v := _m.LastCheckedAt; v != nil {
  364. builder.WriteString("last_checked_at=")
  365. builder.WriteString(v.Format(time.ANSIC))
  366. }
  367. builder.WriteString(", ")
  368. builder.WriteString("created_by=")
  369. builder.WriteString(fmt.Sprintf("%v", _m.CreatedBy))
  370. builder.WriteString(", ")
  371. if v := _m.TemplateID; v != nil {
  372. builder.WriteString("template_id=")
  373. builder.WriteString(fmt.Sprintf("%v", *v))
  374. }
  375. builder.WriteString(", ")
  376. builder.WriteString("extra_headers=")
  377. builder.WriteString(fmt.Sprintf("%v", _m.ExtraHeaders))
  378. builder.WriteString(", ")
  379. builder.WriteString("body_override_mode=")
  380. builder.WriteString(_m.BodyOverrideMode)
  381. builder.WriteString(", ")
  382. builder.WriteString("body_override=")
  383. builder.WriteString(fmt.Sprintf("%v", _m.BodyOverride))
  384. builder.WriteByte(')')
  385. return builder.String()
  386. }
  387. // ChannelMonitors is a parsable slice of ChannelMonitor.
  388. type ChannelMonitors []*ChannelMonitor