| package schema
|
|
|
| import (
|
| "entgo.io/contrib/entgql"
|
| "entgo.io/ent"
|
| "entgo.io/ent/schema"
|
| "entgo.io/ent/schema/edge"
|
| "entgo.io/ent/schema/field"
|
| "entgo.io/ent/schema/index"
|
|
|
| "github.com/looplj/axonhub/internal/objects"
|
| )
|
|
|
| type RequestExecution struct {
|
| ent.Schema
|
| }
|
|
|
| func (RequestExecution) Mixin() []ent.Mixin {
|
| return []ent.Mixin{
|
| TimeMixin{},
|
| }
|
| }
|
|
|
| func (RequestExecution) Indexes() []ent.Index {
|
| return []ent.Index{
|
|
|
| index.Fields("request_id", "status", "created_at").
|
| StorageKey("request_executions_by_request_id_status_created_at"),
|
| index.Fields("channel_id").
|
| StorageKey("request_executions_by_channel_id_created_at"),
|
| }
|
| }
|
|
|
| func (RequestExecution) Fields() []ent.Field {
|
| return []ent.Field{
|
| field.Int("project_id").Immutable().Default(1),
|
| field.Int("request_id").Immutable(),
|
| field.Int("channel_id").Immutable().Optional(),
|
| field.Int("data_storage_id").
|
| Optional().
|
| Immutable().
|
| Comment("Data Storage ID that this request belongs to"),
|
|
|
| field.String("external_id").Optional(),
|
| field.String("model_id").Immutable(),
|
|
|
| field.String("format").Immutable().Default("openai/chat_completions"),
|
|
|
|
|
| field.JSON("request_body", objects.JSONRawMessage{}).Immutable().Annotations(
|
| entgql.Directives(forceResolver()),
|
| ),
|
|
|
|
|
| field.JSON("response_body", objects.JSONRawMessage{}).Optional().Annotations(
|
| entgql.Directives(forceResolver()),
|
| ),
|
|
|
|
|
| field.JSON("response_chunks", []objects.JSONRawMessage{}).Optional().Annotations(
|
| entgql.Directives(forceResolver()),
|
| ),
|
| field.String("error_message").Optional(),
|
|
|
| field.Enum("status").Values("pending", "processing", "completed", "failed", "canceled"),
|
|
|
| field.Bool("stream").Default(false).Immutable(),
|
|
|
| field.Int64("metrics_latency_ms").Optional().Nillable(),
|
|
|
| field.Int64("metrics_first_token_latency_ms").Optional().Nillable(),
|
|
|
| field.JSON("request_headers", objects.JSONRawMessage{}).
|
| Optional().
|
| Comment("Request headers"),
|
| }
|
| }
|
|
|
| func (RequestExecution) Edges() []ent.Edge {
|
| return []ent.Edge{
|
| edge.From("request", Request.Type).
|
| Field("request_id").
|
| Ref("executions").
|
| Required().
|
| Immutable().
|
| Unique(),
|
| edge.From("channel", Channel.Type).
|
| Field("channel_id").
|
| Ref("executions").
|
| Annotations(
|
| entgql.Directives(forceResolver()),
|
| ).
|
| Immutable().
|
| Unique(),
|
| edge.From("data_storage", DataStorage.Type).
|
| Ref("executions").
|
| Field("data_storage_id").
|
| Immutable().
|
| Unique(),
|
| }
|
| }
|
|
|
| func (RequestExecution) Annotations() []schema.Annotation {
|
| return []schema.Annotation{
|
| entgql.RelayConnection(),
|
| }
|
| }
|
|
|