diff --git a/.gitignore b/.gitignore index 274eb02..7b6e02f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ data/ *.so *.dylib .DS_Store +IDEATION_CHAT*.md diff --git a/README.md b/README.md index 097a2d6..c2fa5c6 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,9 @@ export DB_DSN="postgres://user:pass@localhost/specui?sslmode=disable" | `/api/views/{id}` | GET | Get a specific view | | `/api/views/{id}` | PUT | Update a view | | `/api/views/{id}` | DELETE | Delete a view | +| `/api/registry/agents` | GET | List registered agent definitions | +| `/api/registry/teams` | GET | List registered team definitions with resolved members | +| `/api/registry/sync` | POST | Re-scan spec directories and upsert the registry | ## Development diff --git a/cmd/specui/main.go b/cmd/specui/main.go index 2f5a11e..011603a 100644 --- a/cmd/specui/main.go +++ b/cmd/specui/main.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" + "github.com/plexusone/agentplexus/internal/registry" "github.com/plexusone/agentplexus/internal/server" "github.com/plexusone/agentplexus/internal/storage" ) @@ -56,6 +57,16 @@ func main() { for _, d := range dirs { fmt.Printf(" %s\n", d) } + + syncResult, err := registry.Sync(ctx, db, dirs) + if err != nil { + log.Fatalf("error syncing agent registry: %v", err) + } + fmt.Printf("registry sync: %s\n", syncResult) + for _, warning := range syncResult.Warnings { + fmt.Fprintf(os.Stderr, "registry warning: %s\n", warning) + } + fmt.Printf("listening on http://localhost:%d\n", port) srv := server.New(dirs, port, db) diff --git a/go.mod b/go.mod index 02dddb2..f6522cd 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/fsnotify/fsnotify v1.10.1 github.com/google/uuid v1.6.0 github.com/grokify/brandkit v0.4.0 - github.com/plexusone/multi-agent-spec/sdk/go v0.8.0 + github.com/plexusone/multi-agent-spec v0.10.0 modernc.org/sqlite v1.60.1 ) @@ -20,28 +20,28 @@ require ( github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/bmatcuk/doublestar v1.3.4 // indirect github.com/buger/jsonparser v1.6.1 // indirect - github.com/dustin/go-humanize v1.0.1 // indirect - github.com/go-openapi/inflect v1.0.0 // indirect + github.com/dustin/go-humanize v1.1.0 // indirect + github.com/go-openapi/inflect v1.0.1 // indirect github.com/google/go-cmp v0.7.0 // indirect - github.com/hashicorp/hcl/v2 v2.24.0 // indirect + github.com/hashicorp/hcl/v2 v2.25.0 // indirect github.com/invopop/jsonschema v0.14.0 // indirect github.com/mattn/go-isatty v0.0.24 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect - github.com/ncruces/go-strftime v1.0.0 // indirect - github.com/pb33f/ordered-map/v2 v2.3.1 // indirect + github.com/ncruces/go-strftime v1.1.0 // indirect + github.com/pb33f/go-yaml v0.1.1 // indirect + github.com/pb33f/ordered-map/v2 v2.3.2 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rogpeppe/go-internal v1.14.1 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/quicktemplate v1.8.0 // indirect github.com/zclconf/go-cty v1.19.0 // indirect github.com/zclconf/go-cty-yaml v1.2.0 // indirect - go.yaml.in/yaml/v4 v4.0.0-rc.6 // indirect golang.org/x/mod v0.41.0 // indirect golang.org/x/net v0.59.0 // indirect golang.org/x/sync v0.23.0 // indirect golang.org/x/sys v0.48.0 // indirect golang.org/x/text v0.42.0 // indirect - golang.org/x/tools v0.50.0 // indirect + golang.org/x/tools v0.51.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect modernc.org/libc v1.77.1 // indirect modernc.org/mathutil v1.7.1 // indirect diff --git a/go.sum b/go.sum index f55e5ab..3e1bf70 100644 --- a/go.sum +++ b/go.sum @@ -20,12 +20,12 @@ github.com/buger/jsonparser v1.6.1 h1:I0phFv0PlbLHnM7TZAVjZ2MJ2/eWRTDyuO7GLR98IE github.com/buger/jsonparser v1.6.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/dustin/go-humanize v1.1.0 h1:dbKTrvD0klcbBV/h4AWJdMuZogJACoMlvWIWZ5b2xWg= +github.com/dustin/go-humanize v1.1.0/go.mod h1:hc1CvRkJMsgxqjmjMQF3QNRAZBwY8AXBAzKYoSX9sFI= github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho= github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo= -github.com/go-openapi/inflect v1.0.0 h1:IzG7K5YBu97odaCXhjODGGt25WaNtEYLJc9NfUcW4AI= -github.com/go-openapi/inflect v1.0.0/go.mod h1:ksYcnLD7j24H79hdqOMmWaLXjFXd0LTkRoBA0UazLW8= +github.com/go-openapi/inflect v1.0.1 h1:gqN2BW4CxqueOg9FO861a592OZKBNJ7GV1XE+gDI1DU= +github.com/go-openapi/inflect v1.0.1/go.mod h1:lxYFcPUUAw+O6UXnm1tPRgWDTLnH/Rwz4xdKInO0ccA= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -38,8 +38,8 @@ github.com/grokify/brandkit v0.4.0 h1:zf9IcwZvJEFaiNg0xxXcrT1/ENZKdrGovwjlxrz7u5 github.com/grokify/brandkit v0.4.0/go.mod h1:eBbbMKVqVA1UAk/c5flSTrbPZZyP/kwYv76JO9i4vtE= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/hashicorp/hcl/v2 v2.24.0 h1:2QJdZ454DSsYGoaE6QheQZjtKZSUs9Nh2izTWiwQxvE= -github.com/hashicorp/hcl/v2 v2.24.0/go.mod h1:oGoO1FIQYfn/AgyOhlg9qLC6/nOJPX3qGbkZpYAcqfM= +github.com/hashicorp/hcl/v2 v2.25.0 h1:HmmQVYRny4MaBo4b20TjmL46wyuUxpnMWkPZ4+NTbWk= +github.com/hashicorp/hcl/v2 v2.25.0/go.mod h1:vR+FKETxoZAmRlHgFfKmuqivj+C4Izm/c66XkmZ3r7M= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= @@ -52,12 +52,14 @@ github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEu github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= -github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= -github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= -github.com/pb33f/ordered-map/v2 v2.3.1 h1:5319HDO0aw4DA4gzi+zv4FXU9UlSs3xGZ40wcP1nBjY= -github.com/pb33f/ordered-map/v2 v2.3.1/go.mod h1:qxFQgd0PkVUtOMCkTapqotNgzRhMPL7VvaHKbd1HnmQ= -github.com/plexusone/multi-agent-spec/sdk/go v0.8.0 h1:rut0+qqBhY2rQmw6eNwofEN/s+iPskTuxP/PA1vYUmY= -github.com/plexusone/multi-agent-spec/sdk/go v0.8.0/go.mod h1:zpg+h9URlxNWbYguq6SFxw0OioulKXNKnSJ0dT2AWic= +github.com/ncruces/go-strftime v1.1.0 h1:vtPmPWMkb539RGV9WpWT9EwJGvrOCKvMNI4obWL47Hk= +github.com/ncruces/go-strftime v1.1.0/go.mod h1:yVaq7iwCN09vHRrKBrrflXT0M9tTMG2KmZ9Fj7xeG/g= +github.com/pb33f/go-yaml v0.1.1 h1:yWGmhVdwzionRnSc/hEJwcfq6PaZL2QdYzyReXBbX7Q= +github.com/pb33f/go-yaml v0.1.1/go.mod h1:QvWdkHP5VjFYAeHMQUkaPQqREaQnBNOXmWzAjNrnSdo= +github.com/pb33f/ordered-map/v2 v2.3.2 h1:wDyaZ2Pv9QLh64X4utCeD5Zoi9nIv2aW3lwv172O5PQ= +github.com/pb33f/ordered-map/v2 v2.3.2/go.mod h1:1OhFrXu3OYw3kM+FXF+Ug3ugmmZ9LE8z0JfQMLvtV0w= +github.com/plexusone/multi-agent-spec v0.10.0 h1:bAvDTEIrLFRVa6Skk268o+SiBCn8ph4jrF3UvKh7yUM= +github.com/plexusone/multi-agent-spec v0.10.0/go.mod h1:XLyEqfdOZcd6B91BM6iH0oL8ni3h8PsYiUSpTHwBrcs= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= @@ -76,8 +78,6 @@ github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6 github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= github.com/zclconf/go-cty-yaml v1.2.0 h1:GDyL4+e/Qe/S0B7YaecMLbVvAR/Mp21CXMOSiCTOi1M= github.com/zclconf/go-cty-yaml v1.2.0/go.mod h1:9YLUH4g7lOhVWqUbctnVlZ5KLpg7JAprQNgxSZ1Gyxs= -go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4= -go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues= @@ -88,8 +88,8 @@ golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= -golang.org/x/tools v0.50.0 h1:c2ifzfcuY7L90lZ2aKd8S4K2NpASF08SZx9ZuJkHmSU= -golang.org/x/tools v0.50.0/go.mod h1:7ulVMw3831Mwi5EZD6RomGyffr4VFjuNYXf2BbCEAV0= +golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI= +golang.org/x/tools v0.51.0/go.mod h1:9eEncMayCV6zRMGhR5eZEC2iBx98qWcF1HZ9Z7wJOoA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/internal/ent/agentdefinition.go b/internal/ent/agentdefinition.go new file mode 100644 index 0000000..336a81f --- /dev/null +++ b/internal/ent/agentdefinition.go @@ -0,0 +1,366 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" +) + +// AgentDefinition is the model entity for the AgentDefinition schema. +type AgentDefinition struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // Owning repository, e.g. agent-team-release + RepoName string `json:"repo_name,omitempty"` + // Subdirectory namespace, if any + Namespace string `json:"namespace,omitempty"` + // Agent name from spec frontmatter + Name string `json:"name,omitempty"` + // repo_name/namespace/name, for display and lookup + QualifiedName string `json:"qualified_name,omitempty"` + // User-facing Go-style source path, e.g. github.com/plexusone/agent-team-release/agents/release-reviewer + SourceRef string `json:"source_ref,omitempty"` + // Internal registry identity, xrn:agentplexus:agent-definition: + RegistryXrn string `json:"registry_xrn,omitempty"` + // Description holds the value of the "description" field. + Description string `json:"description,omitempty"` + // Model holds the value of the "model" field. + Model string `json:"model,omitempty"` + // Icon holds the value of the "icon" field. + Icon string `json:"icon,omitempty"` + // Role holds the value of the "role" field. + Role string `json:"role,omitempty"` + // Tools holds the value of the "tools" field. + Tools []string `json:"tools,omitempty"` + // AllowedTools holds the value of the "allowed_tools" field. + AllowedTools []string `json:"allowed_tools,omitempty"` + // Skills holds the value of the "skills" field. + Skills []string `json:"skills,omitempty"` + // Dependencies holds the value of the "dependencies" field. + Dependencies []string `json:"dependencies,omitempty"` + // Requires holds the value of the "requires" field. + Requires []string `json:"requires,omitempty"` + // Absolute path to the agent markdown file + SourcePath string `json:"source_path,omitempty"` + // sha256 of the source file, for drift detection + ContentHash string `json:"content_hash,omitempty"` + // FirstSeenAt holds the value of the "first_seen_at" field. + FirstSeenAt time.Time `json:"first_seen_at,omitempty"` + // Updated on every successful registration sync + LastSeenAt time.Time `json:"last_seen_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 AgentDefinitionQuery when eager-loading is set. + Edges AgentDefinitionEdges `json:"edges"` + selectValues sql.SelectValues +} + +// AgentDefinitionEdges holds the relations/edges for other nodes in the graph. +type AgentDefinitionEdges struct { + // Teams holds the value of the teams edge. + Teams []*TeamDefinition `json:"teams,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// TeamsOrErr returns the Teams value or an error if the edge +// was not loaded in eager-loading. +func (e AgentDefinitionEdges) TeamsOrErr() ([]*TeamDefinition, error) { + if e.loadedTypes[0] { + return e.Teams, nil + } + return nil, &NotLoadedError{edge: "teams"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*AgentDefinition) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case agentdefinition.FieldTools, agentdefinition.FieldAllowedTools, agentdefinition.FieldSkills, agentdefinition.FieldDependencies, agentdefinition.FieldRequires: + values[i] = new([]byte) + case agentdefinition.FieldRepoName, agentdefinition.FieldNamespace, agentdefinition.FieldName, agentdefinition.FieldQualifiedName, agentdefinition.FieldSourceRef, agentdefinition.FieldRegistryXrn, agentdefinition.FieldDescription, agentdefinition.FieldModel, agentdefinition.FieldIcon, agentdefinition.FieldRole, agentdefinition.FieldSourcePath, agentdefinition.FieldContentHash: + values[i] = new(sql.NullString) + case agentdefinition.FieldFirstSeenAt, agentdefinition.FieldLastSeenAt, agentdefinition.FieldCreatedAt, agentdefinition.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case agentdefinition.FieldID: + 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 AgentDefinition fields. +func (_m *AgentDefinition) 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 agentdefinition.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 agentdefinition.FieldRepoName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field repo_name", values[i]) + } else if value.Valid { + _m.RepoName = value.String + } + case agentdefinition.FieldNamespace: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field namespace", values[i]) + } else if value.Valid { + _m.Namespace = value.String + } + case agentdefinition.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case agentdefinition.FieldQualifiedName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field qualified_name", values[i]) + } else if value.Valid { + _m.QualifiedName = value.String + } + case agentdefinition.FieldSourceRef: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field source_ref", values[i]) + } else if value.Valid { + _m.SourceRef = value.String + } + case agentdefinition.FieldRegistryXrn: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field registry_xrn", values[i]) + } else if value.Valid { + _m.RegistryXrn = value.String + } + case agentdefinition.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + _m.Description = value.String + } + case agentdefinition.FieldModel: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field model", values[i]) + } else if value.Valid { + _m.Model = value.String + } + case agentdefinition.FieldIcon: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field icon", values[i]) + } else if value.Valid { + _m.Icon = value.String + } + case agentdefinition.FieldRole: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field role", values[i]) + } else if value.Valid { + _m.Role = value.String + } + case agentdefinition.FieldTools: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field tools", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Tools); err != nil { + return fmt.Errorf("unmarshal field tools: %w", err) + } + } + case agentdefinition.FieldAllowedTools: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field allowed_tools", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.AllowedTools); err != nil { + return fmt.Errorf("unmarshal field allowed_tools: %w", err) + } + } + case agentdefinition.FieldSkills: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field skills", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Skills); err != nil { + return fmt.Errorf("unmarshal field skills: %w", err) + } + } + case agentdefinition.FieldDependencies: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field dependencies", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Dependencies); err != nil { + return fmt.Errorf("unmarshal field dependencies: %w", err) + } + } + case agentdefinition.FieldRequires: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field requires", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Requires); err != nil { + return fmt.Errorf("unmarshal field requires: %w", err) + } + } + case agentdefinition.FieldSourcePath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field source_path", values[i]) + } else if value.Valid { + _m.SourcePath = value.String + } + case agentdefinition.FieldContentHash: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field content_hash", values[i]) + } else if value.Valid { + _m.ContentHash = value.String + } + case agentdefinition.FieldFirstSeenAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field first_seen_at", values[i]) + } else if value.Valid { + _m.FirstSeenAt = value.Time + } + case agentdefinition.FieldLastSeenAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field last_seen_at", values[i]) + } else if value.Valid { + _m.LastSeenAt = value.Time + } + case agentdefinition.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 agentdefinition.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 AgentDefinition. +// This includes values selected through modifiers, order, etc. +func (_m *AgentDefinition) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryTeams queries the "teams" edge of the AgentDefinition entity. +func (_m *AgentDefinition) QueryTeams() *TeamDefinitionQuery { + return NewAgentDefinitionClient(_m.config).QueryTeams(_m) +} + +// Update returns a builder for updating this AgentDefinition. +// Note that you need to call AgentDefinition.Unwrap() before calling this method if this AgentDefinition +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *AgentDefinition) Update() *AgentDefinitionUpdateOne { + return NewAgentDefinitionClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the AgentDefinition 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 *AgentDefinition) Unwrap() *AgentDefinition { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: AgentDefinition is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *AgentDefinition) String() string { + var builder strings.Builder + builder.WriteString("AgentDefinition(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("repo_name=") + builder.WriteString(_m.RepoName) + builder.WriteString(", ") + builder.WriteString("namespace=") + builder.WriteString(_m.Namespace) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("qualified_name=") + builder.WriteString(_m.QualifiedName) + builder.WriteString(", ") + builder.WriteString("source_ref=") + builder.WriteString(_m.SourceRef) + builder.WriteString(", ") + builder.WriteString("registry_xrn=") + builder.WriteString(_m.RegistryXrn) + builder.WriteString(", ") + builder.WriteString("description=") + builder.WriteString(_m.Description) + builder.WriteString(", ") + builder.WriteString("model=") + builder.WriteString(_m.Model) + builder.WriteString(", ") + builder.WriteString("icon=") + builder.WriteString(_m.Icon) + builder.WriteString(", ") + builder.WriteString("role=") + builder.WriteString(_m.Role) + builder.WriteString(", ") + builder.WriteString("tools=") + builder.WriteString(fmt.Sprintf("%v", _m.Tools)) + builder.WriteString(", ") + builder.WriteString("allowed_tools=") + builder.WriteString(fmt.Sprintf("%v", _m.AllowedTools)) + builder.WriteString(", ") + builder.WriteString("skills=") + builder.WriteString(fmt.Sprintf("%v", _m.Skills)) + builder.WriteString(", ") + builder.WriteString("dependencies=") + builder.WriteString(fmt.Sprintf("%v", _m.Dependencies)) + builder.WriteString(", ") + builder.WriteString("requires=") + builder.WriteString(fmt.Sprintf("%v", _m.Requires)) + builder.WriteString(", ") + builder.WriteString("source_path=") + builder.WriteString(_m.SourcePath) + builder.WriteString(", ") + builder.WriteString("content_hash=") + builder.WriteString(_m.ContentHash) + builder.WriteString(", ") + builder.WriteString("first_seen_at=") + builder.WriteString(_m.FirstSeenAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("last_seen_at=") + builder.WriteString(_m.LastSeenAt.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() +} + +// AgentDefinitions is a parsable slice of AgentDefinition. +type AgentDefinitions []*AgentDefinition diff --git a/internal/ent/agentdefinition/agentdefinition.go b/internal/ent/agentdefinition/agentdefinition.go new file mode 100644 index 0000000..1587cea --- /dev/null +++ b/internal/ent/agentdefinition/agentdefinition.go @@ -0,0 +1,247 @@ +// Code generated by ent, DO NOT EDIT. + +package agentdefinition + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the agentdefinition type in the database. + Label = "agent_definition" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldRepoName holds the string denoting the repo_name field in the database. + FieldRepoName = "repo_name" + // FieldNamespace holds the string denoting the namespace field in the database. + FieldNamespace = "namespace" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldQualifiedName holds the string denoting the qualified_name field in the database. + FieldQualifiedName = "qualified_name" + // FieldSourceRef holds the string denoting the source_ref field in the database. + FieldSourceRef = "source_ref" + // FieldRegistryXrn holds the string denoting the registry_xrn field in the database. + FieldRegistryXrn = "registry_xrn" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // FieldModel holds the string denoting the model field in the database. + FieldModel = "model" + // FieldIcon holds the string denoting the icon field in the database. + FieldIcon = "icon" + // FieldRole holds the string denoting the role field in the database. + FieldRole = "role" + // FieldTools holds the string denoting the tools field in the database. + FieldTools = "tools" + // FieldAllowedTools holds the string denoting the allowed_tools field in the database. + FieldAllowedTools = "allowed_tools" + // FieldSkills holds the string denoting the skills field in the database. + FieldSkills = "skills" + // FieldDependencies holds the string denoting the dependencies field in the database. + FieldDependencies = "dependencies" + // FieldRequires holds the string denoting the requires field in the database. + FieldRequires = "requires" + // FieldSourcePath holds the string denoting the source_path field in the database. + FieldSourcePath = "source_path" + // FieldContentHash holds the string denoting the content_hash field in the database. + FieldContentHash = "content_hash" + // FieldFirstSeenAt holds the string denoting the first_seen_at field in the database. + FieldFirstSeenAt = "first_seen_at" + // FieldLastSeenAt holds the string denoting the last_seen_at field in the database. + FieldLastSeenAt = "last_seen_at" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeTeams holds the string denoting the teams edge name in mutations. + EdgeTeams = "teams" + // Table holds the table name of the agentdefinition in the database. + Table = "agent_definitions" + // TeamsTable is the table that holds the teams relation/edge. The primary key declared below. + TeamsTable = "team_definition_agents" + // TeamsInverseTable is the table name for the TeamDefinition entity. + // It exists in this package in order to avoid circular dependency with the "teamdefinition" package. + TeamsInverseTable = "team_definitions" +) + +// Columns holds all SQL columns for agentdefinition fields. +var Columns = []string{ + FieldID, + FieldRepoName, + FieldNamespace, + FieldName, + FieldQualifiedName, + FieldSourceRef, + FieldRegistryXrn, + FieldDescription, + FieldModel, + FieldIcon, + FieldRole, + FieldTools, + FieldAllowedTools, + FieldSkills, + FieldDependencies, + FieldRequires, + FieldSourcePath, + FieldContentHash, + FieldFirstSeenAt, + FieldLastSeenAt, + FieldCreatedAt, + FieldUpdatedAt, +} + +var ( + // TeamsPrimaryKey and TeamsColumn2 are the table columns denoting the + // primary key for the teams relation (M2M). + TeamsPrimaryKey = []string{"team_definition_id", "agent_definition_id"} +) + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // RepoNameValidator is a validator for the "repo_name" field. It is called by the builders before save. + RepoNameValidator func(string) error + // DefaultNamespace holds the default value on creation for the "namespace" field. + DefaultNamespace string + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // QualifiedNameValidator is a validator for the "qualified_name" field. It is called by the builders before save. + QualifiedNameValidator func(string) error + // SourcePathValidator is a validator for the "source_path" field. It is called by the builders before save. + SourcePathValidator func(string) error + // ContentHashValidator is a validator for the "content_hash" field. It is called by the builders before save. + ContentHashValidator func(string) error + // DefaultFirstSeenAt holds the default value on creation for the "first_seen_at" field. + DefaultFirstSeenAt func() time.Time + // DefaultLastSeenAt holds the default value on creation for the "last_seen_at" field. + DefaultLastSeenAt func() time.Time + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the AgentDefinition queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByRepoName orders the results by the repo_name field. +func ByRepoName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRepoName, opts...).ToFunc() +} + +// ByNamespace orders the results by the namespace field. +func ByNamespace(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNamespace, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByQualifiedName orders the results by the qualified_name field. +func ByQualifiedName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldQualifiedName, opts...).ToFunc() +} + +// BySourceRef orders the results by the source_ref field. +func BySourceRef(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSourceRef, opts...).ToFunc() +} + +// ByRegistryXrn orders the results by the registry_xrn field. +func ByRegistryXrn(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRegistryXrn, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByModel orders the results by the model field. +func ByModel(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldModel, opts...).ToFunc() +} + +// ByIcon orders the results by the icon field. +func ByIcon(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIcon, opts...).ToFunc() +} + +// ByRole orders the results by the role field. +func ByRole(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRole, opts...).ToFunc() +} + +// BySourcePath orders the results by the source_path field. +func BySourcePath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSourcePath, opts...).ToFunc() +} + +// ByContentHash orders the results by the content_hash field. +func ByContentHash(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldContentHash, opts...).ToFunc() +} + +// ByFirstSeenAt orders the results by the first_seen_at field. +func ByFirstSeenAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFirstSeenAt, opts...).ToFunc() +} + +// ByLastSeenAt orders the results by the last_seen_at field. +func ByLastSeenAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLastSeenAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByTeamsCount orders the results by teams count. +func ByTeamsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTeamsStep(), opts...) + } +} + +// ByTeams orders the results by teams terms. +func ByTeams(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTeamsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newTeamsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TeamsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, TeamsTable, TeamsPrimaryKey...), + ) +} diff --git a/internal/ent/agentdefinition/where.go b/internal/ent/agentdefinition/where.go new file mode 100644 index 0000000..8b90658 --- /dev/null +++ b/internal/ent/agentdefinition/where.go @@ -0,0 +1,1225 @@ +// Code generated by ent, DO NOT EDIT. + +package agentdefinition + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldID, id)) +} + +// RepoName applies equality check predicate on the "repo_name" field. It's identical to RepoNameEQ. +func RepoName(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldRepoName, v)) +} + +// Namespace applies equality check predicate on the "namespace" field. It's identical to NamespaceEQ. +func Namespace(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldNamespace, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldName, v)) +} + +// QualifiedName applies equality check predicate on the "qualified_name" field. It's identical to QualifiedNameEQ. +func QualifiedName(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldQualifiedName, v)) +} + +// SourceRef applies equality check predicate on the "source_ref" field. It's identical to SourceRefEQ. +func SourceRef(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldSourceRef, v)) +} + +// RegistryXrn applies equality check predicate on the "registry_xrn" field. It's identical to RegistryXrnEQ. +func RegistryXrn(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldRegistryXrn, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldDescription, v)) +} + +// Model applies equality check predicate on the "model" field. It's identical to ModelEQ. +func Model(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldModel, v)) +} + +// Icon applies equality check predicate on the "icon" field. It's identical to IconEQ. +func Icon(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldIcon, v)) +} + +// Role applies equality check predicate on the "role" field. It's identical to RoleEQ. +func Role(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldRole, v)) +} + +// SourcePath applies equality check predicate on the "source_path" field. It's identical to SourcePathEQ. +func SourcePath(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldSourcePath, v)) +} + +// ContentHash applies equality check predicate on the "content_hash" field. It's identical to ContentHashEQ. +func ContentHash(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldContentHash, v)) +} + +// FirstSeenAt applies equality check predicate on the "first_seen_at" field. It's identical to FirstSeenAtEQ. +func FirstSeenAt(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldFirstSeenAt, v)) +} + +// LastSeenAt applies equality check predicate on the "last_seen_at" field. It's identical to LastSeenAtEQ. +func LastSeenAt(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldLastSeenAt, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// RepoNameEQ applies the EQ predicate on the "repo_name" field. +func RepoNameEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldRepoName, v)) +} + +// RepoNameNEQ applies the NEQ predicate on the "repo_name" field. +func RepoNameNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldRepoName, v)) +} + +// RepoNameIn applies the In predicate on the "repo_name" field. +func RepoNameIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldRepoName, vs...)) +} + +// RepoNameNotIn applies the NotIn predicate on the "repo_name" field. +func RepoNameNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldRepoName, vs...)) +} + +// RepoNameGT applies the GT predicate on the "repo_name" field. +func RepoNameGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldRepoName, v)) +} + +// RepoNameGTE applies the GTE predicate on the "repo_name" field. +func RepoNameGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldRepoName, v)) +} + +// RepoNameLT applies the LT predicate on the "repo_name" field. +func RepoNameLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldRepoName, v)) +} + +// RepoNameLTE applies the LTE predicate on the "repo_name" field. +func RepoNameLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldRepoName, v)) +} + +// RepoNameContains applies the Contains predicate on the "repo_name" field. +func RepoNameContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldRepoName, v)) +} + +// RepoNameHasPrefix applies the HasPrefix predicate on the "repo_name" field. +func RepoNameHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldRepoName, v)) +} + +// RepoNameHasSuffix applies the HasSuffix predicate on the "repo_name" field. +func RepoNameHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldRepoName, v)) +} + +// RepoNameEqualFold applies the EqualFold predicate on the "repo_name" field. +func RepoNameEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldRepoName, v)) +} + +// RepoNameContainsFold applies the ContainsFold predicate on the "repo_name" field. +func RepoNameContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldRepoName, v)) +} + +// NamespaceEQ applies the EQ predicate on the "namespace" field. +func NamespaceEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldNamespace, v)) +} + +// NamespaceNEQ applies the NEQ predicate on the "namespace" field. +func NamespaceNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldNamespace, v)) +} + +// NamespaceIn applies the In predicate on the "namespace" field. +func NamespaceIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldNamespace, vs...)) +} + +// NamespaceNotIn applies the NotIn predicate on the "namespace" field. +func NamespaceNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldNamespace, vs...)) +} + +// NamespaceGT applies the GT predicate on the "namespace" field. +func NamespaceGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldNamespace, v)) +} + +// NamespaceGTE applies the GTE predicate on the "namespace" field. +func NamespaceGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldNamespace, v)) +} + +// NamespaceLT applies the LT predicate on the "namespace" field. +func NamespaceLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldNamespace, v)) +} + +// NamespaceLTE applies the LTE predicate on the "namespace" field. +func NamespaceLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldNamespace, v)) +} + +// NamespaceContains applies the Contains predicate on the "namespace" field. +func NamespaceContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldNamespace, v)) +} + +// NamespaceHasPrefix applies the HasPrefix predicate on the "namespace" field. +func NamespaceHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldNamespace, v)) +} + +// NamespaceHasSuffix applies the HasSuffix predicate on the "namespace" field. +func NamespaceHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldNamespace, v)) +} + +// NamespaceEqualFold applies the EqualFold predicate on the "namespace" field. +func NamespaceEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldNamespace, v)) +} + +// NamespaceContainsFold applies the ContainsFold predicate on the "namespace" field. +func NamespaceContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldNamespace, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldName, v)) +} + +// QualifiedNameEQ applies the EQ predicate on the "qualified_name" field. +func QualifiedNameEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldQualifiedName, v)) +} + +// QualifiedNameNEQ applies the NEQ predicate on the "qualified_name" field. +func QualifiedNameNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldQualifiedName, v)) +} + +// QualifiedNameIn applies the In predicate on the "qualified_name" field. +func QualifiedNameIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldQualifiedName, vs...)) +} + +// QualifiedNameNotIn applies the NotIn predicate on the "qualified_name" field. +func QualifiedNameNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldQualifiedName, vs...)) +} + +// QualifiedNameGT applies the GT predicate on the "qualified_name" field. +func QualifiedNameGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldQualifiedName, v)) +} + +// QualifiedNameGTE applies the GTE predicate on the "qualified_name" field. +func QualifiedNameGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldQualifiedName, v)) +} + +// QualifiedNameLT applies the LT predicate on the "qualified_name" field. +func QualifiedNameLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldQualifiedName, v)) +} + +// QualifiedNameLTE applies the LTE predicate on the "qualified_name" field. +func QualifiedNameLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldQualifiedName, v)) +} + +// QualifiedNameContains applies the Contains predicate on the "qualified_name" field. +func QualifiedNameContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldQualifiedName, v)) +} + +// QualifiedNameHasPrefix applies the HasPrefix predicate on the "qualified_name" field. +func QualifiedNameHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldQualifiedName, v)) +} + +// QualifiedNameHasSuffix applies the HasSuffix predicate on the "qualified_name" field. +func QualifiedNameHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldQualifiedName, v)) +} + +// QualifiedNameEqualFold applies the EqualFold predicate on the "qualified_name" field. +func QualifiedNameEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldQualifiedName, v)) +} + +// QualifiedNameContainsFold applies the ContainsFold predicate on the "qualified_name" field. +func QualifiedNameContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldQualifiedName, v)) +} + +// SourceRefEQ applies the EQ predicate on the "source_ref" field. +func SourceRefEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldSourceRef, v)) +} + +// SourceRefNEQ applies the NEQ predicate on the "source_ref" field. +func SourceRefNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldSourceRef, v)) +} + +// SourceRefIn applies the In predicate on the "source_ref" field. +func SourceRefIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldSourceRef, vs...)) +} + +// SourceRefNotIn applies the NotIn predicate on the "source_ref" field. +func SourceRefNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldSourceRef, vs...)) +} + +// SourceRefGT applies the GT predicate on the "source_ref" field. +func SourceRefGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldSourceRef, v)) +} + +// SourceRefGTE applies the GTE predicate on the "source_ref" field. +func SourceRefGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldSourceRef, v)) +} + +// SourceRefLT applies the LT predicate on the "source_ref" field. +func SourceRefLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldSourceRef, v)) +} + +// SourceRefLTE applies the LTE predicate on the "source_ref" field. +func SourceRefLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldSourceRef, v)) +} + +// SourceRefContains applies the Contains predicate on the "source_ref" field. +func SourceRefContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldSourceRef, v)) +} + +// SourceRefHasPrefix applies the HasPrefix predicate on the "source_ref" field. +func SourceRefHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldSourceRef, v)) +} + +// SourceRefHasSuffix applies the HasSuffix predicate on the "source_ref" field. +func SourceRefHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldSourceRef, v)) +} + +// SourceRefIsNil applies the IsNil predicate on the "source_ref" field. +func SourceRefIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldSourceRef)) +} + +// SourceRefNotNil applies the NotNil predicate on the "source_ref" field. +func SourceRefNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldSourceRef)) +} + +// SourceRefEqualFold applies the EqualFold predicate on the "source_ref" field. +func SourceRefEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldSourceRef, v)) +} + +// SourceRefContainsFold applies the ContainsFold predicate on the "source_ref" field. +func SourceRefContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldSourceRef, v)) +} + +// RegistryXrnEQ applies the EQ predicate on the "registry_xrn" field. +func RegistryXrnEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldRegistryXrn, v)) +} + +// RegistryXrnNEQ applies the NEQ predicate on the "registry_xrn" field. +func RegistryXrnNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldRegistryXrn, v)) +} + +// RegistryXrnIn applies the In predicate on the "registry_xrn" field. +func RegistryXrnIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldRegistryXrn, vs...)) +} + +// RegistryXrnNotIn applies the NotIn predicate on the "registry_xrn" field. +func RegistryXrnNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldRegistryXrn, vs...)) +} + +// RegistryXrnGT applies the GT predicate on the "registry_xrn" field. +func RegistryXrnGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldRegistryXrn, v)) +} + +// RegistryXrnGTE applies the GTE predicate on the "registry_xrn" field. +func RegistryXrnGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldRegistryXrn, v)) +} + +// RegistryXrnLT applies the LT predicate on the "registry_xrn" field. +func RegistryXrnLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldRegistryXrn, v)) +} + +// RegistryXrnLTE applies the LTE predicate on the "registry_xrn" field. +func RegistryXrnLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldRegistryXrn, v)) +} + +// RegistryXrnContains applies the Contains predicate on the "registry_xrn" field. +func RegistryXrnContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldRegistryXrn, v)) +} + +// RegistryXrnHasPrefix applies the HasPrefix predicate on the "registry_xrn" field. +func RegistryXrnHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldRegistryXrn, v)) +} + +// RegistryXrnHasSuffix applies the HasSuffix predicate on the "registry_xrn" field. +func RegistryXrnHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldRegistryXrn, v)) +} + +// RegistryXrnIsNil applies the IsNil predicate on the "registry_xrn" field. +func RegistryXrnIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldRegistryXrn)) +} + +// RegistryXrnNotNil applies the NotNil predicate on the "registry_xrn" field. +func RegistryXrnNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldRegistryXrn)) +} + +// RegistryXrnEqualFold applies the EqualFold predicate on the "registry_xrn" field. +func RegistryXrnEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldRegistryXrn, v)) +} + +// RegistryXrnContainsFold applies the ContainsFold predicate on the "registry_xrn" field. +func RegistryXrnContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldRegistryXrn, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldDescription, v)) +} + +// ModelEQ applies the EQ predicate on the "model" field. +func ModelEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldModel, v)) +} + +// ModelNEQ applies the NEQ predicate on the "model" field. +func ModelNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldModel, v)) +} + +// ModelIn applies the In predicate on the "model" field. +func ModelIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldModel, vs...)) +} + +// ModelNotIn applies the NotIn predicate on the "model" field. +func ModelNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldModel, vs...)) +} + +// ModelGT applies the GT predicate on the "model" field. +func ModelGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldModel, v)) +} + +// ModelGTE applies the GTE predicate on the "model" field. +func ModelGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldModel, v)) +} + +// ModelLT applies the LT predicate on the "model" field. +func ModelLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldModel, v)) +} + +// ModelLTE applies the LTE predicate on the "model" field. +func ModelLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldModel, v)) +} + +// ModelContains applies the Contains predicate on the "model" field. +func ModelContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldModel, v)) +} + +// ModelHasPrefix applies the HasPrefix predicate on the "model" field. +func ModelHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldModel, v)) +} + +// ModelHasSuffix applies the HasSuffix predicate on the "model" field. +func ModelHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldModel, v)) +} + +// ModelIsNil applies the IsNil predicate on the "model" field. +func ModelIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldModel)) +} + +// ModelNotNil applies the NotNil predicate on the "model" field. +func ModelNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldModel)) +} + +// ModelEqualFold applies the EqualFold predicate on the "model" field. +func ModelEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldModel, v)) +} + +// ModelContainsFold applies the ContainsFold predicate on the "model" field. +func ModelContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldModel, v)) +} + +// IconEQ applies the EQ predicate on the "icon" field. +func IconEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldIcon, v)) +} + +// IconNEQ applies the NEQ predicate on the "icon" field. +func IconNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldIcon, v)) +} + +// IconIn applies the In predicate on the "icon" field. +func IconIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldIcon, vs...)) +} + +// IconNotIn applies the NotIn predicate on the "icon" field. +func IconNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldIcon, vs...)) +} + +// IconGT applies the GT predicate on the "icon" field. +func IconGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldIcon, v)) +} + +// IconGTE applies the GTE predicate on the "icon" field. +func IconGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldIcon, v)) +} + +// IconLT applies the LT predicate on the "icon" field. +func IconLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldIcon, v)) +} + +// IconLTE applies the LTE predicate on the "icon" field. +func IconLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldIcon, v)) +} + +// IconContains applies the Contains predicate on the "icon" field. +func IconContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldIcon, v)) +} + +// IconHasPrefix applies the HasPrefix predicate on the "icon" field. +func IconHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldIcon, v)) +} + +// IconHasSuffix applies the HasSuffix predicate on the "icon" field. +func IconHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldIcon, v)) +} + +// IconIsNil applies the IsNil predicate on the "icon" field. +func IconIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldIcon)) +} + +// IconNotNil applies the NotNil predicate on the "icon" field. +func IconNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldIcon)) +} + +// IconEqualFold applies the EqualFold predicate on the "icon" field. +func IconEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldIcon, v)) +} + +// IconContainsFold applies the ContainsFold predicate on the "icon" field. +func IconContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldIcon, v)) +} + +// RoleEQ applies the EQ predicate on the "role" field. +func RoleEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldRole, v)) +} + +// RoleNEQ applies the NEQ predicate on the "role" field. +func RoleNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldRole, v)) +} + +// RoleIn applies the In predicate on the "role" field. +func RoleIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldRole, vs...)) +} + +// RoleNotIn applies the NotIn predicate on the "role" field. +func RoleNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldRole, vs...)) +} + +// RoleGT applies the GT predicate on the "role" field. +func RoleGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldRole, v)) +} + +// RoleGTE applies the GTE predicate on the "role" field. +func RoleGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldRole, v)) +} + +// RoleLT applies the LT predicate on the "role" field. +func RoleLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldRole, v)) +} + +// RoleLTE applies the LTE predicate on the "role" field. +func RoleLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldRole, v)) +} + +// RoleContains applies the Contains predicate on the "role" field. +func RoleContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldRole, v)) +} + +// RoleHasPrefix applies the HasPrefix predicate on the "role" field. +func RoleHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldRole, v)) +} + +// RoleHasSuffix applies the HasSuffix predicate on the "role" field. +func RoleHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldRole, v)) +} + +// RoleIsNil applies the IsNil predicate on the "role" field. +func RoleIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldRole)) +} + +// RoleNotNil applies the NotNil predicate on the "role" field. +func RoleNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldRole)) +} + +// RoleEqualFold applies the EqualFold predicate on the "role" field. +func RoleEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldRole, v)) +} + +// RoleContainsFold applies the ContainsFold predicate on the "role" field. +func RoleContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldRole, v)) +} + +// ToolsIsNil applies the IsNil predicate on the "tools" field. +func ToolsIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldTools)) +} + +// ToolsNotNil applies the NotNil predicate on the "tools" field. +func ToolsNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldTools)) +} + +// AllowedToolsIsNil applies the IsNil predicate on the "allowed_tools" field. +func AllowedToolsIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldAllowedTools)) +} + +// AllowedToolsNotNil applies the NotNil predicate on the "allowed_tools" field. +func AllowedToolsNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldAllowedTools)) +} + +// SkillsIsNil applies the IsNil predicate on the "skills" field. +func SkillsIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldSkills)) +} + +// SkillsNotNil applies the NotNil predicate on the "skills" field. +func SkillsNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldSkills)) +} + +// DependenciesIsNil applies the IsNil predicate on the "dependencies" field. +func DependenciesIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldDependencies)) +} + +// DependenciesNotNil applies the NotNil predicate on the "dependencies" field. +func DependenciesNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldDependencies)) +} + +// RequiresIsNil applies the IsNil predicate on the "requires" field. +func RequiresIsNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIsNull(FieldRequires)) +} + +// RequiresNotNil applies the NotNil predicate on the "requires" field. +func RequiresNotNil() predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotNull(FieldRequires)) +} + +// SourcePathEQ applies the EQ predicate on the "source_path" field. +func SourcePathEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldSourcePath, v)) +} + +// SourcePathNEQ applies the NEQ predicate on the "source_path" field. +func SourcePathNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldSourcePath, v)) +} + +// SourcePathIn applies the In predicate on the "source_path" field. +func SourcePathIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldSourcePath, vs...)) +} + +// SourcePathNotIn applies the NotIn predicate on the "source_path" field. +func SourcePathNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldSourcePath, vs...)) +} + +// SourcePathGT applies the GT predicate on the "source_path" field. +func SourcePathGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldSourcePath, v)) +} + +// SourcePathGTE applies the GTE predicate on the "source_path" field. +func SourcePathGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldSourcePath, v)) +} + +// SourcePathLT applies the LT predicate on the "source_path" field. +func SourcePathLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldSourcePath, v)) +} + +// SourcePathLTE applies the LTE predicate on the "source_path" field. +func SourcePathLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldSourcePath, v)) +} + +// SourcePathContains applies the Contains predicate on the "source_path" field. +func SourcePathContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldSourcePath, v)) +} + +// SourcePathHasPrefix applies the HasPrefix predicate on the "source_path" field. +func SourcePathHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldSourcePath, v)) +} + +// SourcePathHasSuffix applies the HasSuffix predicate on the "source_path" field. +func SourcePathHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldSourcePath, v)) +} + +// SourcePathEqualFold applies the EqualFold predicate on the "source_path" field. +func SourcePathEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldSourcePath, v)) +} + +// SourcePathContainsFold applies the ContainsFold predicate on the "source_path" field. +func SourcePathContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldSourcePath, v)) +} + +// ContentHashEQ applies the EQ predicate on the "content_hash" field. +func ContentHashEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldContentHash, v)) +} + +// ContentHashNEQ applies the NEQ predicate on the "content_hash" field. +func ContentHashNEQ(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldContentHash, v)) +} + +// ContentHashIn applies the In predicate on the "content_hash" field. +func ContentHashIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldContentHash, vs...)) +} + +// ContentHashNotIn applies the NotIn predicate on the "content_hash" field. +func ContentHashNotIn(vs ...string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldContentHash, vs...)) +} + +// ContentHashGT applies the GT predicate on the "content_hash" field. +func ContentHashGT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldContentHash, v)) +} + +// ContentHashGTE applies the GTE predicate on the "content_hash" field. +func ContentHashGTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldContentHash, v)) +} + +// ContentHashLT applies the LT predicate on the "content_hash" field. +func ContentHashLT(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldContentHash, v)) +} + +// ContentHashLTE applies the LTE predicate on the "content_hash" field. +func ContentHashLTE(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldContentHash, v)) +} + +// ContentHashContains applies the Contains predicate on the "content_hash" field. +func ContentHashContains(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContains(FieldContentHash, v)) +} + +// ContentHashHasPrefix applies the HasPrefix predicate on the "content_hash" field. +func ContentHashHasPrefix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasPrefix(FieldContentHash, v)) +} + +// ContentHashHasSuffix applies the HasSuffix predicate on the "content_hash" field. +func ContentHashHasSuffix(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldHasSuffix(FieldContentHash, v)) +} + +// ContentHashEqualFold applies the EqualFold predicate on the "content_hash" field. +func ContentHashEqualFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEqualFold(FieldContentHash, v)) +} + +// ContentHashContainsFold applies the ContainsFold predicate on the "content_hash" field. +func ContentHashContainsFold(v string) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldContainsFold(FieldContentHash, v)) +} + +// FirstSeenAtEQ applies the EQ predicate on the "first_seen_at" field. +func FirstSeenAtEQ(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldFirstSeenAt, v)) +} + +// FirstSeenAtNEQ applies the NEQ predicate on the "first_seen_at" field. +func FirstSeenAtNEQ(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldFirstSeenAt, v)) +} + +// FirstSeenAtIn applies the In predicate on the "first_seen_at" field. +func FirstSeenAtIn(vs ...time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldFirstSeenAt, vs...)) +} + +// FirstSeenAtNotIn applies the NotIn predicate on the "first_seen_at" field. +func FirstSeenAtNotIn(vs ...time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldFirstSeenAt, vs...)) +} + +// FirstSeenAtGT applies the GT predicate on the "first_seen_at" field. +func FirstSeenAtGT(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldFirstSeenAt, v)) +} + +// FirstSeenAtGTE applies the GTE predicate on the "first_seen_at" field. +func FirstSeenAtGTE(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldFirstSeenAt, v)) +} + +// FirstSeenAtLT applies the LT predicate on the "first_seen_at" field. +func FirstSeenAtLT(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldFirstSeenAt, v)) +} + +// FirstSeenAtLTE applies the LTE predicate on the "first_seen_at" field. +func FirstSeenAtLTE(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldFirstSeenAt, v)) +} + +// LastSeenAtEQ applies the EQ predicate on the "last_seen_at" field. +func LastSeenAtEQ(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldLastSeenAt, v)) +} + +// LastSeenAtNEQ applies the NEQ predicate on the "last_seen_at" field. +func LastSeenAtNEQ(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldLastSeenAt, v)) +} + +// LastSeenAtIn applies the In predicate on the "last_seen_at" field. +func LastSeenAtIn(vs ...time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldLastSeenAt, vs...)) +} + +// LastSeenAtNotIn applies the NotIn predicate on the "last_seen_at" field. +func LastSeenAtNotIn(vs ...time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldLastSeenAt, vs...)) +} + +// LastSeenAtGT applies the GT predicate on the "last_seen_at" field. +func LastSeenAtGT(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldLastSeenAt, v)) +} + +// LastSeenAtGTE applies the GTE predicate on the "last_seen_at" field. +func LastSeenAtGTE(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldLastSeenAt, v)) +} + +// LastSeenAtLT applies the LT predicate on the "last_seen_at" field. +func LastSeenAtLT(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldLastSeenAt, v)) +} + +// LastSeenAtLTE applies the LTE predicate on the "last_seen_at" field. +func LastSeenAtLTE(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldLastSeenAt, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasTeams applies the HasEdge predicate on the "teams" edge. +func HasTeams() predicate.AgentDefinition { + return predicate.AgentDefinition(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, TeamsTable, TeamsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTeamsWith applies the HasEdge predicate on the "teams" edge with a given conditions (other predicates). +func HasTeamsWith(preds ...predicate.TeamDefinition) predicate.AgentDefinition { + return predicate.AgentDefinition(func(s *sql.Selector) { + step := newTeamsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.AgentDefinition) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.AgentDefinition) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.AgentDefinition) predicate.AgentDefinition { + return predicate.AgentDefinition(sql.NotPredicates(p)) +} diff --git a/internal/ent/agentdefinition_create.go b/internal/ent/agentdefinition_create.go new file mode 100644 index 0000000..70e13b8 --- /dev/null +++ b/internal/ent/agentdefinition_create.go @@ -0,0 +1,606 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// AgentDefinitionCreate is the builder for creating a AgentDefinition entity. +type AgentDefinitionCreate struct { + config + mutation *AgentDefinitionMutation + hooks []Hook +} + +// SetRepoName sets the "repo_name" field. +func (_c *AgentDefinitionCreate) SetRepoName(v string) *AgentDefinitionCreate { + _c.mutation.SetRepoName(v) + return _c +} + +// SetNamespace sets the "namespace" field. +func (_c *AgentDefinitionCreate) SetNamespace(v string) *AgentDefinitionCreate { + _c.mutation.SetNamespace(v) + return _c +} + +// SetNillableNamespace sets the "namespace" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableNamespace(v *string) *AgentDefinitionCreate { + if v != nil { + _c.SetNamespace(*v) + } + return _c +} + +// SetName sets the "name" field. +func (_c *AgentDefinitionCreate) SetName(v string) *AgentDefinitionCreate { + _c.mutation.SetName(v) + return _c +} + +// SetQualifiedName sets the "qualified_name" field. +func (_c *AgentDefinitionCreate) SetQualifiedName(v string) *AgentDefinitionCreate { + _c.mutation.SetQualifiedName(v) + return _c +} + +// SetSourceRef sets the "source_ref" field. +func (_c *AgentDefinitionCreate) SetSourceRef(v string) *AgentDefinitionCreate { + _c.mutation.SetSourceRef(v) + return _c +} + +// SetNillableSourceRef sets the "source_ref" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableSourceRef(v *string) *AgentDefinitionCreate { + if v != nil { + _c.SetSourceRef(*v) + } + return _c +} + +// SetRegistryXrn sets the "registry_xrn" field. +func (_c *AgentDefinitionCreate) SetRegistryXrn(v string) *AgentDefinitionCreate { + _c.mutation.SetRegistryXrn(v) + return _c +} + +// SetNillableRegistryXrn sets the "registry_xrn" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableRegistryXrn(v *string) *AgentDefinitionCreate { + if v != nil { + _c.SetRegistryXrn(*v) + } + return _c +} + +// SetDescription sets the "description" field. +func (_c *AgentDefinitionCreate) SetDescription(v string) *AgentDefinitionCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableDescription(v *string) *AgentDefinitionCreate { + if v != nil { + _c.SetDescription(*v) + } + return _c +} + +// SetModel sets the "model" field. +func (_c *AgentDefinitionCreate) SetModel(v string) *AgentDefinitionCreate { + _c.mutation.SetModel(v) + return _c +} + +// SetNillableModel sets the "model" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableModel(v *string) *AgentDefinitionCreate { + if v != nil { + _c.SetModel(*v) + } + return _c +} + +// SetIcon sets the "icon" field. +func (_c *AgentDefinitionCreate) SetIcon(v string) *AgentDefinitionCreate { + _c.mutation.SetIcon(v) + return _c +} + +// SetNillableIcon sets the "icon" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableIcon(v *string) *AgentDefinitionCreate { + if v != nil { + _c.SetIcon(*v) + } + return _c +} + +// SetRole sets the "role" field. +func (_c *AgentDefinitionCreate) SetRole(v string) *AgentDefinitionCreate { + _c.mutation.SetRole(v) + return _c +} + +// SetNillableRole sets the "role" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableRole(v *string) *AgentDefinitionCreate { + if v != nil { + _c.SetRole(*v) + } + return _c +} + +// SetTools sets the "tools" field. +func (_c *AgentDefinitionCreate) SetTools(v []string) *AgentDefinitionCreate { + _c.mutation.SetTools(v) + return _c +} + +// SetAllowedTools sets the "allowed_tools" field. +func (_c *AgentDefinitionCreate) SetAllowedTools(v []string) *AgentDefinitionCreate { + _c.mutation.SetAllowedTools(v) + return _c +} + +// SetSkills sets the "skills" field. +func (_c *AgentDefinitionCreate) SetSkills(v []string) *AgentDefinitionCreate { + _c.mutation.SetSkills(v) + return _c +} + +// SetDependencies sets the "dependencies" field. +func (_c *AgentDefinitionCreate) SetDependencies(v []string) *AgentDefinitionCreate { + _c.mutation.SetDependencies(v) + return _c +} + +// SetRequires sets the "requires" field. +func (_c *AgentDefinitionCreate) SetRequires(v []string) *AgentDefinitionCreate { + _c.mutation.SetRequires(v) + return _c +} + +// SetSourcePath sets the "source_path" field. +func (_c *AgentDefinitionCreate) SetSourcePath(v string) *AgentDefinitionCreate { + _c.mutation.SetSourcePath(v) + return _c +} + +// SetContentHash sets the "content_hash" field. +func (_c *AgentDefinitionCreate) SetContentHash(v string) *AgentDefinitionCreate { + _c.mutation.SetContentHash(v) + return _c +} + +// SetFirstSeenAt sets the "first_seen_at" field. +func (_c *AgentDefinitionCreate) SetFirstSeenAt(v time.Time) *AgentDefinitionCreate { + _c.mutation.SetFirstSeenAt(v) + return _c +} + +// SetNillableFirstSeenAt sets the "first_seen_at" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableFirstSeenAt(v *time.Time) *AgentDefinitionCreate { + if v != nil { + _c.SetFirstSeenAt(*v) + } + return _c +} + +// SetLastSeenAt sets the "last_seen_at" field. +func (_c *AgentDefinitionCreate) SetLastSeenAt(v time.Time) *AgentDefinitionCreate { + _c.mutation.SetLastSeenAt(v) + return _c +} + +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableLastSeenAt(v *time.Time) *AgentDefinitionCreate { + if v != nil { + _c.SetLastSeenAt(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *AgentDefinitionCreate) SetCreatedAt(v time.Time) *AgentDefinitionCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableCreatedAt(v *time.Time) *AgentDefinitionCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *AgentDefinitionCreate) SetUpdatedAt(v time.Time) *AgentDefinitionCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableUpdatedAt(v *time.Time) *AgentDefinitionCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *AgentDefinitionCreate) SetID(v uuid.UUID) *AgentDefinitionCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *AgentDefinitionCreate) SetNillableID(v *uuid.UUID) *AgentDefinitionCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// AddTeamIDs adds the "teams" edge to the TeamDefinition entity by IDs. +func (_c *AgentDefinitionCreate) AddTeamIDs(ids ...uuid.UUID) *AgentDefinitionCreate { + _c.mutation.AddTeamIDs(ids...) + return _c +} + +// AddTeams adds the "teams" edges to the TeamDefinition entity. +func (_c *AgentDefinitionCreate) AddTeams(v ...*TeamDefinition) *AgentDefinitionCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddTeamIDs(ids...) +} + +// Mutation returns the AgentDefinitionMutation object of the builder. +func (_c *AgentDefinitionCreate) Mutation() *AgentDefinitionMutation { + return _c.mutation +} + +// Save creates the AgentDefinition in the database. +func (_c *AgentDefinitionCreate) Save(ctx context.Context) (*AgentDefinition, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *AgentDefinitionCreate) SaveX(ctx context.Context) *AgentDefinition { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *AgentDefinitionCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *AgentDefinitionCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *AgentDefinitionCreate) defaults() { + if _, ok := _c.mutation.Namespace(); !ok { + v := agentdefinition.DefaultNamespace + _c.mutation.SetNamespace(v) + } + if _, ok := _c.mutation.FirstSeenAt(); !ok { + v := agentdefinition.DefaultFirstSeenAt() + _c.mutation.SetFirstSeenAt(v) + } + if _, ok := _c.mutation.LastSeenAt(); !ok { + v := agentdefinition.DefaultLastSeenAt() + _c.mutation.SetLastSeenAt(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := agentdefinition.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := agentdefinition.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := agentdefinition.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *AgentDefinitionCreate) check() error { + if _, ok := _c.mutation.RepoName(); !ok { + return &ValidationError{Name: "repo_name", err: errors.New(`ent: missing required field "AgentDefinition.repo_name"`)} + } + if v, ok := _c.mutation.RepoName(); ok { + if err := agentdefinition.RepoNameValidator(v); err != nil { + return &ValidationError{Name: "repo_name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.repo_name": %w`, err)} + } + } + if _, ok := _c.mutation.Namespace(); !ok { + return &ValidationError{Name: "namespace", err: errors.New(`ent: missing required field "AgentDefinition.namespace"`)} + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "AgentDefinition.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := agentdefinition.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.name": %w`, err)} + } + } + if _, ok := _c.mutation.QualifiedName(); !ok { + return &ValidationError{Name: "qualified_name", err: errors.New(`ent: missing required field "AgentDefinition.qualified_name"`)} + } + if v, ok := _c.mutation.QualifiedName(); ok { + if err := agentdefinition.QualifiedNameValidator(v); err != nil { + return &ValidationError{Name: "qualified_name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.qualified_name": %w`, err)} + } + } + if _, ok := _c.mutation.SourcePath(); !ok { + return &ValidationError{Name: "source_path", err: errors.New(`ent: missing required field "AgentDefinition.source_path"`)} + } + if v, ok := _c.mutation.SourcePath(); ok { + if err := agentdefinition.SourcePathValidator(v); err != nil { + return &ValidationError{Name: "source_path", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.source_path": %w`, err)} + } + } + if _, ok := _c.mutation.ContentHash(); !ok { + return &ValidationError{Name: "content_hash", err: errors.New(`ent: missing required field "AgentDefinition.content_hash"`)} + } + if v, ok := _c.mutation.ContentHash(); ok { + if err := agentdefinition.ContentHashValidator(v); err != nil { + return &ValidationError{Name: "content_hash", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.content_hash": %w`, err)} + } + } + if _, ok := _c.mutation.FirstSeenAt(); !ok { + return &ValidationError{Name: "first_seen_at", err: errors.New(`ent: missing required field "AgentDefinition.first_seen_at"`)} + } + if _, ok := _c.mutation.LastSeenAt(); !ok { + return &ValidationError{Name: "last_seen_at", err: errors.New(`ent: missing required field "AgentDefinition.last_seen_at"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AgentDefinition.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AgentDefinition.updated_at"`)} + } + return nil +} + +func (_c *AgentDefinitionCreate) sqlSave(ctx context.Context) (*AgentDefinition, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *AgentDefinitionCreate) createSpec() (*AgentDefinition, *sqlgraph.CreateSpec) { + var ( + _node = &AgentDefinition{config: _c.config} + _spec = sqlgraph.NewCreateSpec(agentdefinition.Table, sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.RepoName(); ok { + _spec.SetField(agentdefinition.FieldRepoName, field.TypeString, value) + _node.RepoName = value + } + if value, ok := _c.mutation.Namespace(); ok { + _spec.SetField(agentdefinition.FieldNamespace, field.TypeString, value) + _node.Namespace = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(agentdefinition.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.QualifiedName(); ok { + _spec.SetField(agentdefinition.FieldQualifiedName, field.TypeString, value) + _node.QualifiedName = value + } + if value, ok := _c.mutation.SourceRef(); ok { + _spec.SetField(agentdefinition.FieldSourceRef, field.TypeString, value) + _node.SourceRef = value + } + if value, ok := _c.mutation.RegistryXrn(); ok { + _spec.SetField(agentdefinition.FieldRegistryXrn, field.TypeString, value) + _node.RegistryXrn = value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(agentdefinition.FieldDescription, field.TypeString, value) + _node.Description = value + } + if value, ok := _c.mutation.Model(); ok { + _spec.SetField(agentdefinition.FieldModel, field.TypeString, value) + _node.Model = value + } + if value, ok := _c.mutation.Icon(); ok { + _spec.SetField(agentdefinition.FieldIcon, field.TypeString, value) + _node.Icon = value + } + if value, ok := _c.mutation.Role(); ok { + _spec.SetField(agentdefinition.FieldRole, field.TypeString, value) + _node.Role = value + } + if value, ok := _c.mutation.Tools(); ok { + _spec.SetField(agentdefinition.FieldTools, field.TypeJSON, value) + _node.Tools = value + } + if value, ok := _c.mutation.AllowedTools(); ok { + _spec.SetField(agentdefinition.FieldAllowedTools, field.TypeJSON, value) + _node.AllowedTools = value + } + if value, ok := _c.mutation.Skills(); ok { + _spec.SetField(agentdefinition.FieldSkills, field.TypeJSON, value) + _node.Skills = value + } + if value, ok := _c.mutation.Dependencies(); ok { + _spec.SetField(agentdefinition.FieldDependencies, field.TypeJSON, value) + _node.Dependencies = value + } + if value, ok := _c.mutation.Requires(); ok { + _spec.SetField(agentdefinition.FieldRequires, field.TypeJSON, value) + _node.Requires = value + } + if value, ok := _c.mutation.SourcePath(); ok { + _spec.SetField(agentdefinition.FieldSourcePath, field.TypeString, value) + _node.SourcePath = value + } + if value, ok := _c.mutation.ContentHash(); ok { + _spec.SetField(agentdefinition.FieldContentHash, field.TypeString, value) + _node.ContentHash = value + } + if value, ok := _c.mutation.FirstSeenAt(); ok { + _spec.SetField(agentdefinition.FieldFirstSeenAt, field.TypeTime, value) + _node.FirstSeenAt = value + } + if value, ok := _c.mutation.LastSeenAt(); ok { + _spec.SetField(agentdefinition.FieldLastSeenAt, field.TypeTime, value) + _node.LastSeenAt = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(agentdefinition.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(agentdefinition.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.TeamsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: agentdefinition.TeamsTable, + Columns: agentdefinition.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// AgentDefinitionCreateBulk is the builder for creating many AgentDefinition entities in bulk. +type AgentDefinitionCreateBulk struct { + config + err error + builders []*AgentDefinitionCreate +} + +// Save creates the AgentDefinition entities in the database. +func (_c *AgentDefinitionCreateBulk) Save(ctx context.Context) ([]*AgentDefinition, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*AgentDefinition, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AgentDefinitionMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *AgentDefinitionCreateBulk) SaveX(ctx context.Context) []*AgentDefinition { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *AgentDefinitionCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *AgentDefinitionCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/ent/agentdefinition_delete.go b/internal/ent/agentdefinition_delete.go new file mode 100644 index 0000000..a326613 --- /dev/null +++ b/internal/ent/agentdefinition_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/predicate" +) + +// AgentDefinitionDelete is the builder for deleting a AgentDefinition entity. +type AgentDefinitionDelete struct { + config + hooks []Hook + mutation *AgentDefinitionMutation +} + +// Where appends a list predicates to the AgentDefinitionDelete builder. +func (_d *AgentDefinitionDelete) Where(ps ...predicate.AgentDefinition) *AgentDefinitionDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *AgentDefinitionDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *AgentDefinitionDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *AgentDefinitionDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(agentdefinition.Table, sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// AgentDefinitionDeleteOne is the builder for deleting a single AgentDefinition entity. +type AgentDefinitionDeleteOne struct { + _d *AgentDefinitionDelete +} + +// Where appends a list predicates to the AgentDefinitionDelete builder. +func (_d *AgentDefinitionDeleteOne) Where(ps ...predicate.AgentDefinition) *AgentDefinitionDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *AgentDefinitionDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{agentdefinition.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *AgentDefinitionDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/ent/agentdefinition_query.go b/internal/ent/agentdefinition_query.go new file mode 100644 index 0000000..c0c7504 --- /dev/null +++ b/internal/ent/agentdefinition_query.go @@ -0,0 +1,638 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/predicate" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// AgentDefinitionQuery is the builder for querying AgentDefinition entities. +type AgentDefinitionQuery struct { + config + ctx *QueryContext + order []agentdefinition.OrderOption + inters []Interceptor + predicates []predicate.AgentDefinition + withTeams *TeamDefinitionQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the AgentDefinitionQuery builder. +func (_q *AgentDefinitionQuery) Where(ps ...predicate.AgentDefinition) *AgentDefinitionQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *AgentDefinitionQuery) Limit(limit int) *AgentDefinitionQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *AgentDefinitionQuery) Offset(offset int) *AgentDefinitionQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *AgentDefinitionQuery) Unique(unique bool) *AgentDefinitionQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *AgentDefinitionQuery) Order(o ...agentdefinition.OrderOption) *AgentDefinitionQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryTeams chains the current query on the "teams" edge. +func (_q *AgentDefinitionQuery) QueryTeams() *TeamDefinitionQuery { + query := (&TeamDefinitionClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(agentdefinition.Table, agentdefinition.FieldID, selector), + sqlgraph.To(teamdefinition.Table, teamdefinition.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, agentdefinition.TeamsTable, agentdefinition.TeamsPrimaryKey...), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first AgentDefinition entity from the query. +// Returns a *NotFoundError when no AgentDefinition was found. +func (_q *AgentDefinitionQuery) First(ctx context.Context) (*AgentDefinition, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{agentdefinition.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *AgentDefinitionQuery) FirstX(ctx context.Context) *AgentDefinition { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first AgentDefinition ID from the query. +// Returns a *NotFoundError when no AgentDefinition ID was found. +func (_q *AgentDefinitionQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{agentdefinition.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *AgentDefinitionQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single AgentDefinition entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one AgentDefinition entity is found. +// Returns a *NotFoundError when no AgentDefinition entities are found. +func (_q *AgentDefinitionQuery) Only(ctx context.Context) (*AgentDefinition, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{agentdefinition.Label} + default: + return nil, &NotSingularError{agentdefinition.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *AgentDefinitionQuery) OnlyX(ctx context.Context) *AgentDefinition { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only AgentDefinition ID in the query. +// Returns a *NotSingularError when more than one AgentDefinition ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *AgentDefinitionQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{agentdefinition.Label} + default: + err = &NotSingularError{agentdefinition.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *AgentDefinitionQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of AgentDefinitions. +func (_q *AgentDefinitionQuery) All(ctx context.Context) ([]*AgentDefinition, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*AgentDefinition, *AgentDefinitionQuery]() + return withInterceptors[[]*AgentDefinition](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *AgentDefinitionQuery) AllX(ctx context.Context) []*AgentDefinition { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of AgentDefinition IDs. +func (_q *AgentDefinitionQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(agentdefinition.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *AgentDefinitionQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *AgentDefinitionQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*AgentDefinitionQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *AgentDefinitionQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *AgentDefinitionQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *AgentDefinitionQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the AgentDefinitionQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *AgentDefinitionQuery) Clone() *AgentDefinitionQuery { + if _q == nil { + return nil + } + return &AgentDefinitionQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]agentdefinition.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.AgentDefinition{}, _q.predicates...), + withTeams: _q.withTeams.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithTeams tells the query-builder to eager-load the nodes that are connected to +// the "teams" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *AgentDefinitionQuery) WithTeams(opts ...func(*TeamDefinitionQuery)) *AgentDefinitionQuery { + query := (&TeamDefinitionClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTeams = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// RepoName string `json:"repo_name,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.AgentDefinition.Query(). +// GroupBy(agentdefinition.FieldRepoName). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *AgentDefinitionQuery) GroupBy(field string, fields ...string) *AgentDefinitionGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &AgentDefinitionGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = agentdefinition.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// RepoName string `json:"repo_name,omitempty"` +// } +// +// client.AgentDefinition.Query(). +// Select(agentdefinition.FieldRepoName). +// Scan(ctx, &v) +func (_q *AgentDefinitionQuery) Select(fields ...string) *AgentDefinitionSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &AgentDefinitionSelect{AgentDefinitionQuery: _q} + sbuild.label = agentdefinition.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a AgentDefinitionSelect configured with the given aggregations. +func (_q *AgentDefinitionQuery) Aggregate(fns ...AggregateFunc) *AgentDefinitionSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *AgentDefinitionQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !agentdefinition.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *AgentDefinitionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AgentDefinition, error) { + var ( + nodes = []*AgentDefinition{} + _spec = _q.querySpec() + loadedTypes = [1]bool{ + _q.withTeams != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*AgentDefinition).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &AgentDefinition{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withTeams; query != nil { + if err := _q.loadTeams(ctx, query, nodes, + func(n *AgentDefinition) { n.Edges.Teams = []*TeamDefinition{} }, + func(n *AgentDefinition, e *TeamDefinition) { n.Edges.Teams = append(n.Edges.Teams, e) }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *AgentDefinitionQuery) loadTeams(ctx context.Context, query *TeamDefinitionQuery, nodes []*AgentDefinition, init func(*AgentDefinition), assign func(*AgentDefinition, *TeamDefinition)) error { + edgeIDs := make([]driver.Value, len(nodes)) + byID := make(map[uuid.UUID]*AgentDefinition) + nids := make(map[uuid.UUID]map[*AgentDefinition]struct{}) + for i, node := range nodes { + edgeIDs[i] = node.ID + byID[node.ID] = node + if init != nil { + init(node) + } + } + query.Where(func(s *sql.Selector) { + joinT := sql.Table(agentdefinition.TeamsTable) + s.Join(joinT).On(s.C(teamdefinition.FieldID), joinT.C(agentdefinition.TeamsPrimaryKey[0])) + s.Where(sql.InValues(joinT.C(agentdefinition.TeamsPrimaryKey[1]), edgeIDs...)) + columns := s.SelectedColumns() + s.Select(joinT.C(agentdefinition.TeamsPrimaryKey[1])) + s.AppendSelect(columns...) + s.SetDistinct(false) + }) + if err := query.prepareQuery(ctx); err != nil { + return err + } + qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { + assign := spec.Assign + values := spec.ScanValues + spec.ScanValues = func(columns []string) ([]any, error) { + values, err := values(columns[1:]) + if err != nil { + return nil, err + } + return append([]any{new(uuid.UUID)}, values...), nil + } + spec.Assign = func(columns []string, values []any) error { + outValue := *values[0].(*uuid.UUID) + inValue := *values[1].(*uuid.UUID) + if nids[inValue] == nil { + nids[inValue] = map[*AgentDefinition]struct{}{byID[outValue]: {}} + return assign(columns[1:], values[1:]) + } + nids[inValue][byID[outValue]] = struct{}{} + return nil + } + }) + }) + neighbors, err := withInterceptors[[]*TeamDefinition](ctx, query, qr, query.inters) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nids[n.ID] + if !ok { + return fmt.Errorf(`unexpected "teams" node returned %v`, n.ID) + } + for kn := range nodes { + assign(kn, n) + } + } + return nil +} + +func (_q *AgentDefinitionQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *AgentDefinitionQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(agentdefinition.Table, agentdefinition.Columns, sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, agentdefinition.FieldID) + for i := range fields { + if fields[i] != agentdefinition.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *AgentDefinitionQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(agentdefinition.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = agentdefinition.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// AgentDefinitionGroupBy is the group-by builder for AgentDefinition entities. +type AgentDefinitionGroupBy struct { + selector + build *AgentDefinitionQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *AgentDefinitionGroupBy) Aggregate(fns ...AggregateFunc) *AgentDefinitionGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *AgentDefinitionGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AgentDefinitionQuery, *AgentDefinitionGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *AgentDefinitionGroupBy) sqlScan(ctx context.Context, root *AgentDefinitionQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// AgentDefinitionSelect is the builder for selecting fields of AgentDefinition entities. +type AgentDefinitionSelect struct { + *AgentDefinitionQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *AgentDefinitionSelect) Aggregate(fns ...AggregateFunc) *AgentDefinitionSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *AgentDefinitionSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AgentDefinitionQuery, *AgentDefinitionSelect](ctx, _s.AgentDefinitionQuery, _s, _s.inters, v) +} + +func (_s *AgentDefinitionSelect) sqlScan(ctx context.Context, root *AgentDefinitionQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/internal/ent/agentdefinition_update.go b/internal/ent/agentdefinition_update.go new file mode 100644 index 0000000..a7b41ee --- /dev/null +++ b/internal/ent/agentdefinition_update.go @@ -0,0 +1,1237 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/predicate" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// AgentDefinitionUpdate is the builder for updating AgentDefinition entities. +type AgentDefinitionUpdate struct { + config + hooks []Hook + mutation *AgentDefinitionMutation +} + +// Where appends a list predicates to the AgentDefinitionUpdate builder. +func (_u *AgentDefinitionUpdate) Where(ps ...predicate.AgentDefinition) *AgentDefinitionUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetRepoName sets the "repo_name" field. +func (_u *AgentDefinitionUpdate) SetRepoName(v string) *AgentDefinitionUpdate { + _u.mutation.SetRepoName(v) + return _u +} + +// SetNillableRepoName sets the "repo_name" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableRepoName(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetRepoName(*v) + } + return _u +} + +// SetNamespace sets the "namespace" field. +func (_u *AgentDefinitionUpdate) SetNamespace(v string) *AgentDefinitionUpdate { + _u.mutation.SetNamespace(v) + return _u +} + +// SetNillableNamespace sets the "namespace" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableNamespace(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetNamespace(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *AgentDefinitionUpdate) SetName(v string) *AgentDefinitionUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableName(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetQualifiedName sets the "qualified_name" field. +func (_u *AgentDefinitionUpdate) SetQualifiedName(v string) *AgentDefinitionUpdate { + _u.mutation.SetQualifiedName(v) + return _u +} + +// SetNillableQualifiedName sets the "qualified_name" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableQualifiedName(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetQualifiedName(*v) + } + return _u +} + +// SetSourceRef sets the "source_ref" field. +func (_u *AgentDefinitionUpdate) SetSourceRef(v string) *AgentDefinitionUpdate { + _u.mutation.SetSourceRef(v) + return _u +} + +// SetNillableSourceRef sets the "source_ref" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableSourceRef(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetSourceRef(*v) + } + return _u +} + +// ClearSourceRef clears the value of the "source_ref" field. +func (_u *AgentDefinitionUpdate) ClearSourceRef() *AgentDefinitionUpdate { + _u.mutation.ClearSourceRef() + return _u +} + +// SetDescription sets the "description" field. +func (_u *AgentDefinitionUpdate) SetDescription(v string) *AgentDefinitionUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableDescription(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *AgentDefinitionUpdate) ClearDescription() *AgentDefinitionUpdate { + _u.mutation.ClearDescription() + return _u +} + +// SetModel sets the "model" field. +func (_u *AgentDefinitionUpdate) SetModel(v string) *AgentDefinitionUpdate { + _u.mutation.SetModel(v) + return _u +} + +// SetNillableModel sets the "model" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableModel(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetModel(*v) + } + return _u +} + +// ClearModel clears the value of the "model" field. +func (_u *AgentDefinitionUpdate) ClearModel() *AgentDefinitionUpdate { + _u.mutation.ClearModel() + return _u +} + +// SetIcon sets the "icon" field. +func (_u *AgentDefinitionUpdate) SetIcon(v string) *AgentDefinitionUpdate { + _u.mutation.SetIcon(v) + return _u +} + +// SetNillableIcon sets the "icon" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableIcon(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetIcon(*v) + } + return _u +} + +// ClearIcon clears the value of the "icon" field. +func (_u *AgentDefinitionUpdate) ClearIcon() *AgentDefinitionUpdate { + _u.mutation.ClearIcon() + return _u +} + +// SetRole sets the "role" field. +func (_u *AgentDefinitionUpdate) SetRole(v string) *AgentDefinitionUpdate { + _u.mutation.SetRole(v) + return _u +} + +// SetNillableRole sets the "role" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableRole(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetRole(*v) + } + return _u +} + +// ClearRole clears the value of the "role" field. +func (_u *AgentDefinitionUpdate) ClearRole() *AgentDefinitionUpdate { + _u.mutation.ClearRole() + return _u +} + +// SetTools sets the "tools" field. +func (_u *AgentDefinitionUpdate) SetTools(v []string) *AgentDefinitionUpdate { + _u.mutation.SetTools(v) + return _u +} + +// AppendTools appends value to the "tools" field. +func (_u *AgentDefinitionUpdate) AppendTools(v []string) *AgentDefinitionUpdate { + _u.mutation.AppendTools(v) + return _u +} + +// ClearTools clears the value of the "tools" field. +func (_u *AgentDefinitionUpdate) ClearTools() *AgentDefinitionUpdate { + _u.mutation.ClearTools() + return _u +} + +// SetAllowedTools sets the "allowed_tools" field. +func (_u *AgentDefinitionUpdate) SetAllowedTools(v []string) *AgentDefinitionUpdate { + _u.mutation.SetAllowedTools(v) + return _u +} + +// AppendAllowedTools appends value to the "allowed_tools" field. +func (_u *AgentDefinitionUpdate) AppendAllowedTools(v []string) *AgentDefinitionUpdate { + _u.mutation.AppendAllowedTools(v) + return _u +} + +// ClearAllowedTools clears the value of the "allowed_tools" field. +func (_u *AgentDefinitionUpdate) ClearAllowedTools() *AgentDefinitionUpdate { + _u.mutation.ClearAllowedTools() + return _u +} + +// SetSkills sets the "skills" field. +func (_u *AgentDefinitionUpdate) SetSkills(v []string) *AgentDefinitionUpdate { + _u.mutation.SetSkills(v) + return _u +} + +// AppendSkills appends value to the "skills" field. +func (_u *AgentDefinitionUpdate) AppendSkills(v []string) *AgentDefinitionUpdate { + _u.mutation.AppendSkills(v) + return _u +} + +// ClearSkills clears the value of the "skills" field. +func (_u *AgentDefinitionUpdate) ClearSkills() *AgentDefinitionUpdate { + _u.mutation.ClearSkills() + return _u +} + +// SetDependencies sets the "dependencies" field. +func (_u *AgentDefinitionUpdate) SetDependencies(v []string) *AgentDefinitionUpdate { + _u.mutation.SetDependencies(v) + return _u +} + +// AppendDependencies appends value to the "dependencies" field. +func (_u *AgentDefinitionUpdate) AppendDependencies(v []string) *AgentDefinitionUpdate { + _u.mutation.AppendDependencies(v) + return _u +} + +// ClearDependencies clears the value of the "dependencies" field. +func (_u *AgentDefinitionUpdate) ClearDependencies() *AgentDefinitionUpdate { + _u.mutation.ClearDependencies() + return _u +} + +// SetRequires sets the "requires" field. +func (_u *AgentDefinitionUpdate) SetRequires(v []string) *AgentDefinitionUpdate { + _u.mutation.SetRequires(v) + return _u +} + +// AppendRequires appends value to the "requires" field. +func (_u *AgentDefinitionUpdate) AppendRequires(v []string) *AgentDefinitionUpdate { + _u.mutation.AppendRequires(v) + return _u +} + +// ClearRequires clears the value of the "requires" field. +func (_u *AgentDefinitionUpdate) ClearRequires() *AgentDefinitionUpdate { + _u.mutation.ClearRequires() + return _u +} + +// SetSourcePath sets the "source_path" field. +func (_u *AgentDefinitionUpdate) SetSourcePath(v string) *AgentDefinitionUpdate { + _u.mutation.SetSourcePath(v) + return _u +} + +// SetNillableSourcePath sets the "source_path" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableSourcePath(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetSourcePath(*v) + } + return _u +} + +// SetContentHash sets the "content_hash" field. +func (_u *AgentDefinitionUpdate) SetContentHash(v string) *AgentDefinitionUpdate { + _u.mutation.SetContentHash(v) + return _u +} + +// SetNillableContentHash sets the "content_hash" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableContentHash(v *string) *AgentDefinitionUpdate { + if v != nil { + _u.SetContentHash(*v) + } + return _u +} + +// SetLastSeenAt sets the "last_seen_at" field. +func (_u *AgentDefinitionUpdate) SetLastSeenAt(v time.Time) *AgentDefinitionUpdate { + _u.mutation.SetLastSeenAt(v) + return _u +} + +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. +func (_u *AgentDefinitionUpdate) SetNillableLastSeenAt(v *time.Time) *AgentDefinitionUpdate { + if v != nil { + _u.SetLastSeenAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *AgentDefinitionUpdate) SetUpdatedAt(v time.Time) *AgentDefinitionUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// AddTeamIDs adds the "teams" edge to the TeamDefinition entity by IDs. +func (_u *AgentDefinitionUpdate) AddTeamIDs(ids ...uuid.UUID) *AgentDefinitionUpdate { + _u.mutation.AddTeamIDs(ids...) + return _u +} + +// AddTeams adds the "teams" edges to the TeamDefinition entity. +func (_u *AgentDefinitionUpdate) AddTeams(v ...*TeamDefinition) *AgentDefinitionUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamIDs(ids...) +} + +// Mutation returns the AgentDefinitionMutation object of the builder. +func (_u *AgentDefinitionUpdate) Mutation() *AgentDefinitionMutation { + return _u.mutation +} + +// ClearTeams clears all "teams" edges to the TeamDefinition entity. +func (_u *AgentDefinitionUpdate) ClearTeams() *AgentDefinitionUpdate { + _u.mutation.ClearTeams() + return _u +} + +// RemoveTeamIDs removes the "teams" edge to TeamDefinition entities by IDs. +func (_u *AgentDefinitionUpdate) RemoveTeamIDs(ids ...uuid.UUID) *AgentDefinitionUpdate { + _u.mutation.RemoveTeamIDs(ids...) + return _u +} + +// RemoveTeams removes "teams" edges to TeamDefinition entities. +func (_u *AgentDefinitionUpdate) RemoveTeams(v ...*TeamDefinition) *AgentDefinitionUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *AgentDefinitionUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *AgentDefinitionUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *AgentDefinitionUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *AgentDefinitionUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *AgentDefinitionUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := agentdefinition.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *AgentDefinitionUpdate) check() error { + if v, ok := _u.mutation.RepoName(); ok { + if err := agentdefinition.RepoNameValidator(v); err != nil { + return &ValidationError{Name: "repo_name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.repo_name": %w`, err)} + } + } + if v, ok := _u.mutation.Name(); ok { + if err := agentdefinition.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.name": %w`, err)} + } + } + if v, ok := _u.mutation.QualifiedName(); ok { + if err := agentdefinition.QualifiedNameValidator(v); err != nil { + return &ValidationError{Name: "qualified_name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.qualified_name": %w`, err)} + } + } + if v, ok := _u.mutation.SourcePath(); ok { + if err := agentdefinition.SourcePathValidator(v); err != nil { + return &ValidationError{Name: "source_path", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.source_path": %w`, err)} + } + } + if v, ok := _u.mutation.ContentHash(); ok { + if err := agentdefinition.ContentHashValidator(v); err != nil { + return &ValidationError{Name: "content_hash", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.content_hash": %w`, err)} + } + } + return nil +} + +func (_u *AgentDefinitionUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(agentdefinition.Table, agentdefinition.Columns, sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.RepoName(); ok { + _spec.SetField(agentdefinition.FieldRepoName, field.TypeString, value) + } + if value, ok := _u.mutation.Namespace(); ok { + _spec.SetField(agentdefinition.FieldNamespace, field.TypeString, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(agentdefinition.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.QualifiedName(); ok { + _spec.SetField(agentdefinition.FieldQualifiedName, field.TypeString, value) + } + if value, ok := _u.mutation.SourceRef(); ok { + _spec.SetField(agentdefinition.FieldSourceRef, field.TypeString, value) + } + if _u.mutation.SourceRefCleared() { + _spec.ClearField(agentdefinition.FieldSourceRef, field.TypeString) + } + if _u.mutation.RegistryXrnCleared() { + _spec.ClearField(agentdefinition.FieldRegistryXrn, field.TypeString) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(agentdefinition.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(agentdefinition.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Model(); ok { + _spec.SetField(agentdefinition.FieldModel, field.TypeString, value) + } + if _u.mutation.ModelCleared() { + _spec.ClearField(agentdefinition.FieldModel, field.TypeString) + } + if value, ok := _u.mutation.Icon(); ok { + _spec.SetField(agentdefinition.FieldIcon, field.TypeString, value) + } + if _u.mutation.IconCleared() { + _spec.ClearField(agentdefinition.FieldIcon, field.TypeString) + } + if value, ok := _u.mutation.Role(); ok { + _spec.SetField(agentdefinition.FieldRole, field.TypeString, value) + } + if _u.mutation.RoleCleared() { + _spec.ClearField(agentdefinition.FieldRole, field.TypeString) + } + if value, ok := _u.mutation.Tools(); ok { + _spec.SetField(agentdefinition.FieldTools, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedTools(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldTools, value) + }) + } + if _u.mutation.ToolsCleared() { + _spec.ClearField(agentdefinition.FieldTools, field.TypeJSON) + } + if value, ok := _u.mutation.AllowedTools(); ok { + _spec.SetField(agentdefinition.FieldAllowedTools, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedAllowedTools(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldAllowedTools, value) + }) + } + if _u.mutation.AllowedToolsCleared() { + _spec.ClearField(agentdefinition.FieldAllowedTools, field.TypeJSON) + } + if value, ok := _u.mutation.Skills(); ok { + _spec.SetField(agentdefinition.FieldSkills, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedSkills(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldSkills, value) + }) + } + if _u.mutation.SkillsCleared() { + _spec.ClearField(agentdefinition.FieldSkills, field.TypeJSON) + } + if value, ok := _u.mutation.Dependencies(); ok { + _spec.SetField(agentdefinition.FieldDependencies, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedDependencies(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldDependencies, value) + }) + } + if _u.mutation.DependenciesCleared() { + _spec.ClearField(agentdefinition.FieldDependencies, field.TypeJSON) + } + if value, ok := _u.mutation.Requires(); ok { + _spec.SetField(agentdefinition.FieldRequires, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedRequires(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldRequires, value) + }) + } + if _u.mutation.RequiresCleared() { + _spec.ClearField(agentdefinition.FieldRequires, field.TypeJSON) + } + if value, ok := _u.mutation.SourcePath(); ok { + _spec.SetField(agentdefinition.FieldSourcePath, field.TypeString, value) + } + if value, ok := _u.mutation.ContentHash(); ok { + _spec.SetField(agentdefinition.FieldContentHash, field.TypeString, value) + } + if value, ok := _u.mutation.LastSeenAt(); ok { + _spec.SetField(agentdefinition.FieldLastSeenAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(agentdefinition.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.TeamsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: agentdefinition.TeamsTable, + Columns: agentdefinition.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamsIDs(); len(nodes) > 0 && !_u.mutation.TeamsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: agentdefinition.TeamsTable, + Columns: agentdefinition.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: agentdefinition.TeamsTable, + Columns: agentdefinition.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{agentdefinition.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// AgentDefinitionUpdateOne is the builder for updating a single AgentDefinition entity. +type AgentDefinitionUpdateOne struct { + config + fields []string + hooks []Hook + mutation *AgentDefinitionMutation +} + +// SetRepoName sets the "repo_name" field. +func (_u *AgentDefinitionUpdateOne) SetRepoName(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetRepoName(v) + return _u +} + +// SetNillableRepoName sets the "repo_name" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableRepoName(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetRepoName(*v) + } + return _u +} + +// SetNamespace sets the "namespace" field. +func (_u *AgentDefinitionUpdateOne) SetNamespace(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetNamespace(v) + return _u +} + +// SetNillableNamespace sets the "namespace" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableNamespace(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetNamespace(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *AgentDefinitionUpdateOne) SetName(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableName(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetQualifiedName sets the "qualified_name" field. +func (_u *AgentDefinitionUpdateOne) SetQualifiedName(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetQualifiedName(v) + return _u +} + +// SetNillableQualifiedName sets the "qualified_name" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableQualifiedName(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetQualifiedName(*v) + } + return _u +} + +// SetSourceRef sets the "source_ref" field. +func (_u *AgentDefinitionUpdateOne) SetSourceRef(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetSourceRef(v) + return _u +} + +// SetNillableSourceRef sets the "source_ref" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableSourceRef(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetSourceRef(*v) + } + return _u +} + +// ClearSourceRef clears the value of the "source_ref" field. +func (_u *AgentDefinitionUpdateOne) ClearSourceRef() *AgentDefinitionUpdateOne { + _u.mutation.ClearSourceRef() + return _u +} + +// SetDescription sets the "description" field. +func (_u *AgentDefinitionUpdateOne) SetDescription(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableDescription(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *AgentDefinitionUpdateOne) ClearDescription() *AgentDefinitionUpdateOne { + _u.mutation.ClearDescription() + return _u +} + +// SetModel sets the "model" field. +func (_u *AgentDefinitionUpdateOne) SetModel(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetModel(v) + return _u +} + +// SetNillableModel sets the "model" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableModel(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetModel(*v) + } + return _u +} + +// ClearModel clears the value of the "model" field. +func (_u *AgentDefinitionUpdateOne) ClearModel() *AgentDefinitionUpdateOne { + _u.mutation.ClearModel() + return _u +} + +// SetIcon sets the "icon" field. +func (_u *AgentDefinitionUpdateOne) SetIcon(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetIcon(v) + return _u +} + +// SetNillableIcon sets the "icon" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableIcon(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetIcon(*v) + } + return _u +} + +// ClearIcon clears the value of the "icon" field. +func (_u *AgentDefinitionUpdateOne) ClearIcon() *AgentDefinitionUpdateOne { + _u.mutation.ClearIcon() + return _u +} + +// SetRole sets the "role" field. +func (_u *AgentDefinitionUpdateOne) SetRole(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetRole(v) + return _u +} + +// SetNillableRole sets the "role" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableRole(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetRole(*v) + } + return _u +} + +// ClearRole clears the value of the "role" field. +func (_u *AgentDefinitionUpdateOne) ClearRole() *AgentDefinitionUpdateOne { + _u.mutation.ClearRole() + return _u +} + +// SetTools sets the "tools" field. +func (_u *AgentDefinitionUpdateOne) SetTools(v []string) *AgentDefinitionUpdateOne { + _u.mutation.SetTools(v) + return _u +} + +// AppendTools appends value to the "tools" field. +func (_u *AgentDefinitionUpdateOne) AppendTools(v []string) *AgentDefinitionUpdateOne { + _u.mutation.AppendTools(v) + return _u +} + +// ClearTools clears the value of the "tools" field. +func (_u *AgentDefinitionUpdateOne) ClearTools() *AgentDefinitionUpdateOne { + _u.mutation.ClearTools() + return _u +} + +// SetAllowedTools sets the "allowed_tools" field. +func (_u *AgentDefinitionUpdateOne) SetAllowedTools(v []string) *AgentDefinitionUpdateOne { + _u.mutation.SetAllowedTools(v) + return _u +} + +// AppendAllowedTools appends value to the "allowed_tools" field. +func (_u *AgentDefinitionUpdateOne) AppendAllowedTools(v []string) *AgentDefinitionUpdateOne { + _u.mutation.AppendAllowedTools(v) + return _u +} + +// ClearAllowedTools clears the value of the "allowed_tools" field. +func (_u *AgentDefinitionUpdateOne) ClearAllowedTools() *AgentDefinitionUpdateOne { + _u.mutation.ClearAllowedTools() + return _u +} + +// SetSkills sets the "skills" field. +func (_u *AgentDefinitionUpdateOne) SetSkills(v []string) *AgentDefinitionUpdateOne { + _u.mutation.SetSkills(v) + return _u +} + +// AppendSkills appends value to the "skills" field. +func (_u *AgentDefinitionUpdateOne) AppendSkills(v []string) *AgentDefinitionUpdateOne { + _u.mutation.AppendSkills(v) + return _u +} + +// ClearSkills clears the value of the "skills" field. +func (_u *AgentDefinitionUpdateOne) ClearSkills() *AgentDefinitionUpdateOne { + _u.mutation.ClearSkills() + return _u +} + +// SetDependencies sets the "dependencies" field. +func (_u *AgentDefinitionUpdateOne) SetDependencies(v []string) *AgentDefinitionUpdateOne { + _u.mutation.SetDependencies(v) + return _u +} + +// AppendDependencies appends value to the "dependencies" field. +func (_u *AgentDefinitionUpdateOne) AppendDependencies(v []string) *AgentDefinitionUpdateOne { + _u.mutation.AppendDependencies(v) + return _u +} + +// ClearDependencies clears the value of the "dependencies" field. +func (_u *AgentDefinitionUpdateOne) ClearDependencies() *AgentDefinitionUpdateOne { + _u.mutation.ClearDependencies() + return _u +} + +// SetRequires sets the "requires" field. +func (_u *AgentDefinitionUpdateOne) SetRequires(v []string) *AgentDefinitionUpdateOne { + _u.mutation.SetRequires(v) + return _u +} + +// AppendRequires appends value to the "requires" field. +func (_u *AgentDefinitionUpdateOne) AppendRequires(v []string) *AgentDefinitionUpdateOne { + _u.mutation.AppendRequires(v) + return _u +} + +// ClearRequires clears the value of the "requires" field. +func (_u *AgentDefinitionUpdateOne) ClearRequires() *AgentDefinitionUpdateOne { + _u.mutation.ClearRequires() + return _u +} + +// SetSourcePath sets the "source_path" field. +func (_u *AgentDefinitionUpdateOne) SetSourcePath(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetSourcePath(v) + return _u +} + +// SetNillableSourcePath sets the "source_path" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableSourcePath(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetSourcePath(*v) + } + return _u +} + +// SetContentHash sets the "content_hash" field. +func (_u *AgentDefinitionUpdateOne) SetContentHash(v string) *AgentDefinitionUpdateOne { + _u.mutation.SetContentHash(v) + return _u +} + +// SetNillableContentHash sets the "content_hash" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableContentHash(v *string) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetContentHash(*v) + } + return _u +} + +// SetLastSeenAt sets the "last_seen_at" field. +func (_u *AgentDefinitionUpdateOne) SetLastSeenAt(v time.Time) *AgentDefinitionUpdateOne { + _u.mutation.SetLastSeenAt(v) + return _u +} + +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. +func (_u *AgentDefinitionUpdateOne) SetNillableLastSeenAt(v *time.Time) *AgentDefinitionUpdateOne { + if v != nil { + _u.SetLastSeenAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *AgentDefinitionUpdateOne) SetUpdatedAt(v time.Time) *AgentDefinitionUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// AddTeamIDs adds the "teams" edge to the TeamDefinition entity by IDs. +func (_u *AgentDefinitionUpdateOne) AddTeamIDs(ids ...uuid.UUID) *AgentDefinitionUpdateOne { + _u.mutation.AddTeamIDs(ids...) + return _u +} + +// AddTeams adds the "teams" edges to the TeamDefinition entity. +func (_u *AgentDefinitionUpdateOne) AddTeams(v ...*TeamDefinition) *AgentDefinitionUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddTeamIDs(ids...) +} + +// Mutation returns the AgentDefinitionMutation object of the builder. +func (_u *AgentDefinitionUpdateOne) Mutation() *AgentDefinitionMutation { + return _u.mutation +} + +// ClearTeams clears all "teams" edges to the TeamDefinition entity. +func (_u *AgentDefinitionUpdateOne) ClearTeams() *AgentDefinitionUpdateOne { + _u.mutation.ClearTeams() + return _u +} + +// RemoveTeamIDs removes the "teams" edge to TeamDefinition entities by IDs. +func (_u *AgentDefinitionUpdateOne) RemoveTeamIDs(ids ...uuid.UUID) *AgentDefinitionUpdateOne { + _u.mutation.RemoveTeamIDs(ids...) + return _u +} + +// RemoveTeams removes "teams" edges to TeamDefinition entities. +func (_u *AgentDefinitionUpdateOne) RemoveTeams(v ...*TeamDefinition) *AgentDefinitionUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveTeamIDs(ids...) +} + +// Where appends a list predicates to the AgentDefinitionUpdate builder. +func (_u *AgentDefinitionUpdateOne) Where(ps ...predicate.AgentDefinition) *AgentDefinitionUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *AgentDefinitionUpdateOne) Select(field string, fields ...string) *AgentDefinitionUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated AgentDefinition entity. +func (_u *AgentDefinitionUpdateOne) Save(ctx context.Context) (*AgentDefinition, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *AgentDefinitionUpdateOne) SaveX(ctx context.Context) *AgentDefinition { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *AgentDefinitionUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *AgentDefinitionUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *AgentDefinitionUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := agentdefinition.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *AgentDefinitionUpdateOne) check() error { + if v, ok := _u.mutation.RepoName(); ok { + if err := agentdefinition.RepoNameValidator(v); err != nil { + return &ValidationError{Name: "repo_name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.repo_name": %w`, err)} + } + } + if v, ok := _u.mutation.Name(); ok { + if err := agentdefinition.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.name": %w`, err)} + } + } + if v, ok := _u.mutation.QualifiedName(); ok { + if err := agentdefinition.QualifiedNameValidator(v); err != nil { + return &ValidationError{Name: "qualified_name", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.qualified_name": %w`, err)} + } + } + if v, ok := _u.mutation.SourcePath(); ok { + if err := agentdefinition.SourcePathValidator(v); err != nil { + return &ValidationError{Name: "source_path", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.source_path": %w`, err)} + } + } + if v, ok := _u.mutation.ContentHash(); ok { + if err := agentdefinition.ContentHashValidator(v); err != nil { + return &ValidationError{Name: "content_hash", err: fmt.Errorf(`ent: validator failed for field "AgentDefinition.content_hash": %w`, err)} + } + } + return nil +} + +func (_u *AgentDefinitionUpdateOne) sqlSave(ctx context.Context) (_node *AgentDefinition, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(agentdefinition.Table, agentdefinition.Columns, sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AgentDefinition.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, agentdefinition.FieldID) + for _, f := range fields { + if !agentdefinition.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != agentdefinition.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.RepoName(); ok { + _spec.SetField(agentdefinition.FieldRepoName, field.TypeString, value) + } + if value, ok := _u.mutation.Namespace(); ok { + _spec.SetField(agentdefinition.FieldNamespace, field.TypeString, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(agentdefinition.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.QualifiedName(); ok { + _spec.SetField(agentdefinition.FieldQualifiedName, field.TypeString, value) + } + if value, ok := _u.mutation.SourceRef(); ok { + _spec.SetField(agentdefinition.FieldSourceRef, field.TypeString, value) + } + if _u.mutation.SourceRefCleared() { + _spec.ClearField(agentdefinition.FieldSourceRef, field.TypeString) + } + if _u.mutation.RegistryXrnCleared() { + _spec.ClearField(agentdefinition.FieldRegistryXrn, field.TypeString) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(agentdefinition.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(agentdefinition.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Model(); ok { + _spec.SetField(agentdefinition.FieldModel, field.TypeString, value) + } + if _u.mutation.ModelCleared() { + _spec.ClearField(agentdefinition.FieldModel, field.TypeString) + } + if value, ok := _u.mutation.Icon(); ok { + _spec.SetField(agentdefinition.FieldIcon, field.TypeString, value) + } + if _u.mutation.IconCleared() { + _spec.ClearField(agentdefinition.FieldIcon, field.TypeString) + } + if value, ok := _u.mutation.Role(); ok { + _spec.SetField(agentdefinition.FieldRole, field.TypeString, value) + } + if _u.mutation.RoleCleared() { + _spec.ClearField(agentdefinition.FieldRole, field.TypeString) + } + if value, ok := _u.mutation.Tools(); ok { + _spec.SetField(agentdefinition.FieldTools, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedTools(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldTools, value) + }) + } + if _u.mutation.ToolsCleared() { + _spec.ClearField(agentdefinition.FieldTools, field.TypeJSON) + } + if value, ok := _u.mutation.AllowedTools(); ok { + _spec.SetField(agentdefinition.FieldAllowedTools, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedAllowedTools(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldAllowedTools, value) + }) + } + if _u.mutation.AllowedToolsCleared() { + _spec.ClearField(agentdefinition.FieldAllowedTools, field.TypeJSON) + } + if value, ok := _u.mutation.Skills(); ok { + _spec.SetField(agentdefinition.FieldSkills, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedSkills(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldSkills, value) + }) + } + if _u.mutation.SkillsCleared() { + _spec.ClearField(agentdefinition.FieldSkills, field.TypeJSON) + } + if value, ok := _u.mutation.Dependencies(); ok { + _spec.SetField(agentdefinition.FieldDependencies, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedDependencies(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldDependencies, value) + }) + } + if _u.mutation.DependenciesCleared() { + _spec.ClearField(agentdefinition.FieldDependencies, field.TypeJSON) + } + if value, ok := _u.mutation.Requires(); ok { + _spec.SetField(agentdefinition.FieldRequires, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedRequires(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, agentdefinition.FieldRequires, value) + }) + } + if _u.mutation.RequiresCleared() { + _spec.ClearField(agentdefinition.FieldRequires, field.TypeJSON) + } + if value, ok := _u.mutation.SourcePath(); ok { + _spec.SetField(agentdefinition.FieldSourcePath, field.TypeString, value) + } + if value, ok := _u.mutation.ContentHash(); ok { + _spec.SetField(agentdefinition.FieldContentHash, field.TypeString, value) + } + if value, ok := _u.mutation.LastSeenAt(); ok { + _spec.SetField(agentdefinition.FieldLastSeenAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(agentdefinition.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.TeamsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: agentdefinition.TeamsTable, + Columns: agentdefinition.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedTeamsIDs(); len(nodes) > 0 && !_u.mutation.TeamsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: agentdefinition.TeamsTable, + Columns: agentdefinition.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TeamsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: agentdefinition.TeamsTable, + Columns: agentdefinition.TeamsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &AgentDefinition{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{agentdefinition.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/internal/ent/client.go b/internal/ent/client.go index af919d6..248058e 100644 --- a/internal/ent/client.go +++ b/internal/ent/client.go @@ -9,12 +9,15 @@ import ( "log" "reflect" - "github.com/plexusone/agentplexus/internal/ent/migrate" "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/migrate" "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" "github.com/plexusone/agentplexus/internal/ent/view" ) @@ -23,6 +26,10 @@ type Client struct { config // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema + // AgentDefinition is the client for interacting with the AgentDefinition builders. + AgentDefinition *AgentDefinitionClient + // TeamDefinition is the client for interacting with the TeamDefinition builders. + TeamDefinition *TeamDefinitionClient // View is the client for interacting with the View builders. View *ViewClient } @@ -36,6 +43,8 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) + c.AgentDefinition = NewAgentDefinitionClient(c.config) + c.TeamDefinition = NewTeamDefinitionClient(c.config) c.View = NewViewClient(c.config) } @@ -127,9 +136,11 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { cfg := c.config cfg.driver = tx return &Tx{ - ctx: ctx, - config: cfg, - View: NewViewClient(cfg), + ctx: ctx, + config: cfg, + AgentDefinition: NewAgentDefinitionClient(cfg), + TeamDefinition: NewTeamDefinitionClient(cfg), + View: NewViewClient(cfg), }, nil } @@ -147,16 +158,18 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ - ctx: ctx, - config: cfg, - View: NewViewClient(cfg), + ctx: ctx, + config: cfg, + AgentDefinition: NewAgentDefinitionClient(cfg), + TeamDefinition: NewTeamDefinitionClient(cfg), + View: NewViewClient(cfg), }, nil } // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). -// View. +// AgentDefinition. // Query(). // Count(ctx) func (c *Client) Debug() *Client { @@ -178,18 +191,26 @@ func (c *Client) Close() error { // Use adds the mutation hooks to all the entity clients. // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { + c.AgentDefinition.Use(hooks...) + c.TeamDefinition.Use(hooks...) c.View.Use(hooks...) } // Intercept adds the query interceptors to all the entity clients. // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { + c.AgentDefinition.Intercept(interceptors...) + c.TeamDefinition.Intercept(interceptors...) c.View.Intercept(interceptors...) } // Mutate implements the ent.Mutator interface. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { + case *AgentDefinitionMutation: + return c.AgentDefinition.mutate(ctx, m) + case *TeamDefinitionMutation: + return c.TeamDefinition.mutate(ctx, m) case *ViewMutation: return c.View.mutate(ctx, m) default: @@ -197,6 +218,304 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { } } +// AgentDefinitionClient is a client for the AgentDefinition schema. +type AgentDefinitionClient struct { + config +} + +// NewAgentDefinitionClient returns a client for the AgentDefinition from the given config. +func NewAgentDefinitionClient(c config) *AgentDefinitionClient { + return &AgentDefinitionClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `agentdefinition.Hooks(f(g(h())))`. +func (c *AgentDefinitionClient) Use(hooks ...Hook) { + c.hooks.AgentDefinition = append(c.hooks.AgentDefinition, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `agentdefinition.Intercept(f(g(h())))`. +func (c *AgentDefinitionClient) Intercept(interceptors ...Interceptor) { + c.inters.AgentDefinition = append(c.inters.AgentDefinition, interceptors...) +} + +// Create returns a builder for creating a AgentDefinition entity. +func (c *AgentDefinitionClient) Create() *AgentDefinitionCreate { + mutation := newAgentDefinitionMutation(c.config, OpCreate) + return &AgentDefinitionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of AgentDefinition entities. +func (c *AgentDefinitionClient) CreateBulk(builders ...*AgentDefinitionCreate) *AgentDefinitionCreateBulk { + return &AgentDefinitionCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *AgentDefinitionClient) MapCreateBulk(slice any, setFunc func(*AgentDefinitionCreate, int)) *AgentDefinitionCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AgentDefinitionCreateBulk{err: fmt.Errorf("calling to AgentDefinitionClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AgentDefinitionCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AgentDefinitionCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for AgentDefinition. +func (c *AgentDefinitionClient) Update() *AgentDefinitionUpdate { + mutation := newAgentDefinitionMutation(c.config, OpUpdate) + return &AgentDefinitionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *AgentDefinitionClient) UpdateOne(_m *AgentDefinition) *AgentDefinitionUpdateOne { + mutation := newAgentDefinitionMutation(c.config, OpUpdateOne, withAgentDefinition(_m)) + return &AgentDefinitionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *AgentDefinitionClient) UpdateOneID(id uuid.UUID) *AgentDefinitionUpdateOne { + mutation := newAgentDefinitionMutation(c.config, OpUpdateOne, withAgentDefinitionID(id)) + return &AgentDefinitionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for AgentDefinition. +func (c *AgentDefinitionClient) Delete() *AgentDefinitionDelete { + mutation := newAgentDefinitionMutation(c.config, OpDelete) + return &AgentDefinitionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *AgentDefinitionClient) DeleteOne(_m *AgentDefinition) *AgentDefinitionDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *AgentDefinitionClient) DeleteOneID(id uuid.UUID) *AgentDefinitionDeleteOne { + builder := c.Delete().Where(agentdefinition.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &AgentDefinitionDeleteOne{builder} +} + +// Query returns a query builder for AgentDefinition. +func (c *AgentDefinitionClient) Query() *AgentDefinitionQuery { + return &AgentDefinitionQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeAgentDefinition}, + inters: c.Interceptors(), + } +} + +// Get returns a AgentDefinition entity by its id. +func (c *AgentDefinitionClient) Get(ctx context.Context, id uuid.UUID) (*AgentDefinition, error) { + return c.Query().Where(agentdefinition.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *AgentDefinitionClient) GetX(ctx context.Context, id uuid.UUID) *AgentDefinition { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryTeams queries the teams edge of a AgentDefinition. +func (c *AgentDefinitionClient) QueryTeams(_m *AgentDefinition) *TeamDefinitionQuery { + query := (&TeamDefinitionClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(agentdefinition.Table, agentdefinition.FieldID, id), + sqlgraph.To(teamdefinition.Table, teamdefinition.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, agentdefinition.TeamsTable, agentdefinition.TeamsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *AgentDefinitionClient) Hooks() []Hook { + return c.hooks.AgentDefinition +} + +// Interceptors returns the client interceptors. +func (c *AgentDefinitionClient) Interceptors() []Interceptor { + return c.inters.AgentDefinition +} + +func (c *AgentDefinitionClient) mutate(ctx context.Context, m *AgentDefinitionMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AgentDefinitionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AgentDefinitionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AgentDefinitionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AgentDefinitionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown AgentDefinition mutation op: %q", m.Op()) + } +} + +// TeamDefinitionClient is a client for the TeamDefinition schema. +type TeamDefinitionClient struct { + config +} + +// NewTeamDefinitionClient returns a client for the TeamDefinition from the given config. +func NewTeamDefinitionClient(c config) *TeamDefinitionClient { + return &TeamDefinitionClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `teamdefinition.Hooks(f(g(h())))`. +func (c *TeamDefinitionClient) Use(hooks ...Hook) { + c.hooks.TeamDefinition = append(c.hooks.TeamDefinition, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `teamdefinition.Intercept(f(g(h())))`. +func (c *TeamDefinitionClient) Intercept(interceptors ...Interceptor) { + c.inters.TeamDefinition = append(c.inters.TeamDefinition, interceptors...) +} + +// Create returns a builder for creating a TeamDefinition entity. +func (c *TeamDefinitionClient) Create() *TeamDefinitionCreate { + mutation := newTeamDefinitionMutation(c.config, OpCreate) + return &TeamDefinitionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of TeamDefinition entities. +func (c *TeamDefinitionClient) CreateBulk(builders ...*TeamDefinitionCreate) *TeamDefinitionCreateBulk { + return &TeamDefinitionCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TeamDefinitionClient) MapCreateBulk(slice any, setFunc func(*TeamDefinitionCreate, int)) *TeamDefinitionCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TeamDefinitionCreateBulk{err: fmt.Errorf("calling to TeamDefinitionClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TeamDefinitionCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TeamDefinitionCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for TeamDefinition. +func (c *TeamDefinitionClient) Update() *TeamDefinitionUpdate { + mutation := newTeamDefinitionMutation(c.config, OpUpdate) + return &TeamDefinitionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *TeamDefinitionClient) UpdateOne(_m *TeamDefinition) *TeamDefinitionUpdateOne { + mutation := newTeamDefinitionMutation(c.config, OpUpdateOne, withTeamDefinition(_m)) + return &TeamDefinitionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *TeamDefinitionClient) UpdateOneID(id uuid.UUID) *TeamDefinitionUpdateOne { + mutation := newTeamDefinitionMutation(c.config, OpUpdateOne, withTeamDefinitionID(id)) + return &TeamDefinitionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for TeamDefinition. +func (c *TeamDefinitionClient) Delete() *TeamDefinitionDelete { + mutation := newTeamDefinitionMutation(c.config, OpDelete) + return &TeamDefinitionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *TeamDefinitionClient) DeleteOne(_m *TeamDefinition) *TeamDefinitionDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *TeamDefinitionClient) DeleteOneID(id uuid.UUID) *TeamDefinitionDeleteOne { + builder := c.Delete().Where(teamdefinition.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &TeamDefinitionDeleteOne{builder} +} + +// Query returns a query builder for TeamDefinition. +func (c *TeamDefinitionClient) Query() *TeamDefinitionQuery { + return &TeamDefinitionQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeTeamDefinition}, + inters: c.Interceptors(), + } +} + +// Get returns a TeamDefinition entity by its id. +func (c *TeamDefinitionClient) Get(ctx context.Context, id uuid.UUID) (*TeamDefinition, error) { + return c.Query().Where(teamdefinition.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *TeamDefinitionClient) GetX(ctx context.Context, id uuid.UUID) *TeamDefinition { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryAgents queries the agents edge of a TeamDefinition. +func (c *TeamDefinitionClient) QueryAgents(_m *TeamDefinition) *AgentDefinitionQuery { + query := (&AgentDefinitionClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(teamdefinition.Table, teamdefinition.FieldID, id), + sqlgraph.To(agentdefinition.Table, agentdefinition.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, teamdefinition.AgentsTable, teamdefinition.AgentsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *TeamDefinitionClient) Hooks() []Hook { + return c.hooks.TeamDefinition +} + +// Interceptors returns the client interceptors. +func (c *TeamDefinitionClient) Interceptors() []Interceptor { + return c.inters.TeamDefinition +} + +func (c *TeamDefinitionClient) mutate(ctx context.Context, m *TeamDefinitionMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TeamDefinitionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TeamDefinitionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TeamDefinitionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TeamDefinitionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown TeamDefinition mutation op: %q", m.Op()) + } +} + // ViewClient is a client for the View schema. type ViewClient struct { config @@ -333,9 +652,9 @@ func (c *ViewClient) mutate(ctx context.Context, m *ViewMutation) (Value, error) // hooks and interceptors per client, for fast access. type ( hooks struct { - View []ent.Hook + AgentDefinition, TeamDefinition, View []ent.Hook } inters struct { - View []ent.Interceptor + AgentDefinition, TeamDefinition, View []ent.Interceptor } ) diff --git a/internal/ent/ent.go b/internal/ent/ent.go index a33d640..6ef1e86 100644 --- a/internal/ent/ent.go +++ b/internal/ent/ent.go @@ -12,6 +12,8 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" "github.com/plexusone/agentplexus/internal/ent/view" ) @@ -73,7 +75,9 @@ var ( func checkColumn(t, c string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - view.Table: view.ValidColumn, + agentdefinition.Table: agentdefinition.ValidColumn, + teamdefinition.Table: teamdefinition.ValidColumn, + view.Table: view.ValidColumn, }) }) return columnCheck(t, c) diff --git a/internal/ent/hook/hook.go b/internal/ent/hook/hook.go index 557f541..6ae0614 100644 --- a/internal/ent/hook/hook.go +++ b/internal/ent/hook/hook.go @@ -9,6 +9,30 @@ import ( "github.com/plexusone/agentplexus/internal/ent" ) +// The AgentDefinitionFunc type is an adapter to allow the use of ordinary +// function as AgentDefinition mutator. +type AgentDefinitionFunc func(context.Context, *ent.AgentDefinitionMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f AgentDefinitionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.AgentDefinitionMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AgentDefinitionMutation", m) +} + +// The TeamDefinitionFunc type is an adapter to allow the use of ordinary +// function as TeamDefinition mutator. +type TeamDefinitionFunc func(context.Context, *ent.TeamDefinitionMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f TeamDefinitionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.TeamDefinitionMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TeamDefinitionMutation", m) +} + // The ViewFunc type is an adapter to allow the use of ordinary // function as View mutator. type ViewFunc func(context.Context, *ent.ViewMutation) (ent.Value, error) diff --git a/internal/ent/migrate/schema.go b/internal/ent/migrate/schema.go index b153495..d2226b9 100644 --- a/internal/ent/migrate/schema.go +++ b/internal/ent/migrate/schema.go @@ -8,6 +8,75 @@ import ( ) var ( + // AgentDefinitionsColumns holds the columns for the "agent_definitions" table. + AgentDefinitionsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "repo_name", Type: field.TypeString}, + {Name: "namespace", Type: field.TypeString, Default: ""}, + {Name: "name", Type: field.TypeString}, + {Name: "qualified_name", Type: field.TypeString}, + {Name: "source_ref", Type: field.TypeString, Nullable: true}, + {Name: "registry_xrn", Type: field.TypeString, Unique: true, Nullable: true}, + {Name: "description", Type: field.TypeString, Nullable: true}, + {Name: "model", Type: field.TypeString, Nullable: true}, + {Name: "icon", Type: field.TypeString, Nullable: true}, + {Name: "role", Type: field.TypeString, Nullable: true}, + {Name: "tools", Type: field.TypeJSON, Nullable: true}, + {Name: "allowed_tools", Type: field.TypeJSON, Nullable: true}, + {Name: "skills", Type: field.TypeJSON, Nullable: true}, + {Name: "dependencies", Type: field.TypeJSON, Nullable: true}, + {Name: "requires", Type: field.TypeJSON, Nullable: true}, + {Name: "source_path", Type: field.TypeString}, + {Name: "content_hash", Type: field.TypeString}, + {Name: "first_seen_at", Type: field.TypeTime}, + {Name: "last_seen_at", Type: field.TypeTime}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + } + // AgentDefinitionsTable holds the schema information for the "agent_definitions" table. + AgentDefinitionsTable = &schema.Table{ + Name: "agent_definitions", + Columns: AgentDefinitionsColumns, + PrimaryKey: []*schema.Column{AgentDefinitionsColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "agentdefinition_repo_name_namespace_name", + Unique: true, + Columns: []*schema.Column{AgentDefinitionsColumns[1], AgentDefinitionsColumns[2], AgentDefinitionsColumns[3]}, + }, + }, + } + // TeamDefinitionsColumns holds the columns for the "team_definitions" table. + TeamDefinitionsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "repo_name", Type: field.TypeString}, + {Name: "name", Type: field.TypeString}, + {Name: "source_ref", Type: field.TypeString, Nullable: true}, + {Name: "registry_xrn", Type: field.TypeString, Unique: true, Nullable: true}, + {Name: "version", Type: field.TypeString, Nullable: true}, + {Name: "description", Type: field.TypeString, Nullable: true}, + {Name: "orchestrator", Type: field.TypeString, Nullable: true}, + {Name: "agent_names", Type: field.TypeJSON, Nullable: true}, + {Name: "source_path", Type: field.TypeString}, + {Name: "content_hash", Type: field.TypeString}, + {Name: "first_seen_at", Type: field.TypeTime}, + {Name: "last_seen_at", Type: field.TypeTime}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + } + // TeamDefinitionsTable holds the schema information for the "team_definitions" table. + TeamDefinitionsTable = &schema.Table{ + Name: "team_definitions", + Columns: TeamDefinitionsColumns, + PrimaryKey: []*schema.Column{TeamDefinitionsColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "teamdefinition_repo_name_name", + Unique: true, + Columns: []*schema.Column{TeamDefinitionsColumns[1], TeamDefinitionsColumns[2]}, + }, + }, + } // ViewsColumns holds the columns for the "views" table. ViewsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -25,11 +94,41 @@ var ( Columns: ViewsColumns, PrimaryKey: []*schema.Column{ViewsColumns[0]}, } + // TeamDefinitionAgentsColumns holds the columns for the "team_definition_agents" table. + TeamDefinitionAgentsColumns = []*schema.Column{ + {Name: "team_definition_id", Type: field.TypeUUID}, + {Name: "agent_definition_id", Type: field.TypeUUID}, + } + // TeamDefinitionAgentsTable holds the schema information for the "team_definition_agents" table. + TeamDefinitionAgentsTable = &schema.Table{ + Name: "team_definition_agents", + Columns: TeamDefinitionAgentsColumns, + PrimaryKey: []*schema.Column{TeamDefinitionAgentsColumns[0], TeamDefinitionAgentsColumns[1]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "team_definition_agents_team_definition_id", + Columns: []*schema.Column{TeamDefinitionAgentsColumns[0]}, + RefColumns: []*schema.Column{TeamDefinitionsColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "team_definition_agents_agent_definition_id", + Columns: []*schema.Column{TeamDefinitionAgentsColumns[1]}, + RefColumns: []*schema.Column{AgentDefinitionsColumns[0]}, + OnDelete: schema.Cascade, + }, + }, + } // Tables holds all the tables in the schema. Tables = []*schema.Table{ + AgentDefinitionsTable, + TeamDefinitionsTable, ViewsTable, + TeamDefinitionAgentsTable, } ) func init() { + TeamDefinitionAgentsTable.ForeignKeys[0].RefTable = TeamDefinitionsTable + TeamDefinitionAgentsTable.ForeignKeys[1].RefTable = AgentDefinitionsTable } diff --git a/internal/ent/mutation.go b/internal/ent/mutation.go index 377f20c..504bedf 100644 --- a/internal/ent/mutation.go +++ b/internal/ent/mutation.go @@ -11,10 +11,12 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" "github.com/plexusone/agentplexus/internal/ent/predicate" "github.com/plexusone/agentplexus/internal/ent/schema" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" "github.com/plexusone/agentplexus/internal/ent/view" - "github.com/google/uuid" ) const ( @@ -26,9 +28,3074 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeView = "View" + TypeAgentDefinition = "AgentDefinition" + TypeTeamDefinition = "TeamDefinition" + TypeView = "View" ) +// AgentDefinitionMutation represents an operation that mutates the AgentDefinition nodes in the graph. +type AgentDefinitionMutation struct { + config + op Op + typ string + id *uuid.UUID + repo_name *string + namespace *string + name *string + qualified_name *string + source_ref *string + registry_xrn *string + description *string + model *string + icon *string + role *string + tools *[]string + appendtools []string + allowed_tools *[]string + appendallowed_tools []string + skills *[]string + appendskills []string + dependencies *[]string + appenddependencies []string + requires *[]string + appendrequires []string + source_path *string + content_hash *string + first_seen_at *time.Time + last_seen_at *time.Time + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + teams map[uuid.UUID]struct{} + removedteams map[uuid.UUID]struct{} + clearedteams bool + done bool + oldValue func(context.Context) (*AgentDefinition, error) + predicates []predicate.AgentDefinition +} + +var _ ent.Mutation = (*AgentDefinitionMutation)(nil) + +// agentdefinitionOption allows management of the mutation configuration using functional options. +type agentdefinitionOption func(*AgentDefinitionMutation) + +// newAgentDefinitionMutation creates new mutation for the AgentDefinition entity. +func newAgentDefinitionMutation(c config, op Op, opts ...agentdefinitionOption) *AgentDefinitionMutation { + m := &AgentDefinitionMutation{ + config: c, + op: op, + typ: TypeAgentDefinition, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withAgentDefinitionID sets the ID field of the mutation. +func withAgentDefinitionID(id uuid.UUID) agentdefinitionOption { + return func(m *AgentDefinitionMutation) { + var ( + err error + once sync.Once + value *AgentDefinition + ) + m.oldValue = func(ctx context.Context) (*AgentDefinition, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().AgentDefinition.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withAgentDefinition sets the old AgentDefinition of the mutation. +func withAgentDefinition(node *AgentDefinition) agentdefinitionOption { + return func(m *AgentDefinitionMutation) { + m.oldValue = func(context.Context) (*AgentDefinition, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m AgentDefinitionMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m AgentDefinitionMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of AgentDefinition entities. +func (m *AgentDefinitionMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *AgentDefinitionMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *AgentDefinitionMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().AgentDefinition.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetRepoName sets the "repo_name" field. +func (m *AgentDefinitionMutation) SetRepoName(s string) { + m.repo_name = &s +} + +// RepoName returns the value of the "repo_name" field in the mutation. +func (m *AgentDefinitionMutation) RepoName() (r string, exists bool) { + v := m.repo_name + if v == nil { + return + } + return *v, true +} + +// OldRepoName returns the old "repo_name" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldRepoName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRepoName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRepoName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRepoName: %w", err) + } + return oldValue.RepoName, nil +} + +// ResetRepoName resets all changes to the "repo_name" field. +func (m *AgentDefinitionMutation) ResetRepoName() { + m.repo_name = nil +} + +// SetNamespace sets the "namespace" field. +func (m *AgentDefinitionMutation) SetNamespace(s string) { + m.namespace = &s +} + +// Namespace returns the value of the "namespace" field in the mutation. +func (m *AgentDefinitionMutation) Namespace() (r string, exists bool) { + v := m.namespace + if v == nil { + return + } + return *v, true +} + +// OldNamespace returns the old "namespace" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldNamespace(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNamespace is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNamespace requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) + } + return oldValue.Namespace, nil +} + +// ResetNamespace resets all changes to the "namespace" field. +func (m *AgentDefinitionMutation) ResetNamespace() { + m.namespace = nil +} + +// SetName sets the "name" field. +func (m *AgentDefinitionMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *AgentDefinitionMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *AgentDefinitionMutation) ResetName() { + m.name = nil +} + +// SetQualifiedName sets the "qualified_name" field. +func (m *AgentDefinitionMutation) SetQualifiedName(s string) { + m.qualified_name = &s +} + +// QualifiedName returns the value of the "qualified_name" field in the mutation. +func (m *AgentDefinitionMutation) QualifiedName() (r string, exists bool) { + v := m.qualified_name + if v == nil { + return + } + return *v, true +} + +// OldQualifiedName returns the old "qualified_name" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldQualifiedName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldQualifiedName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldQualifiedName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldQualifiedName: %w", err) + } + return oldValue.QualifiedName, nil +} + +// ResetQualifiedName resets all changes to the "qualified_name" field. +func (m *AgentDefinitionMutation) ResetQualifiedName() { + m.qualified_name = nil +} + +// SetSourceRef sets the "source_ref" field. +func (m *AgentDefinitionMutation) SetSourceRef(s string) { + m.source_ref = &s +} + +// SourceRef returns the value of the "source_ref" field in the mutation. +func (m *AgentDefinitionMutation) SourceRef() (r string, exists bool) { + v := m.source_ref + if v == nil { + return + } + return *v, true +} + +// OldSourceRef returns the old "source_ref" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldSourceRef(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSourceRef is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSourceRef requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSourceRef: %w", err) + } + return oldValue.SourceRef, nil +} + +// ClearSourceRef clears the value of the "source_ref" field. +func (m *AgentDefinitionMutation) ClearSourceRef() { + m.source_ref = nil + m.clearedFields[agentdefinition.FieldSourceRef] = struct{}{} +} + +// SourceRefCleared returns if the "source_ref" field was cleared in this mutation. +func (m *AgentDefinitionMutation) SourceRefCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldSourceRef] + return ok +} + +// ResetSourceRef resets all changes to the "source_ref" field. +func (m *AgentDefinitionMutation) ResetSourceRef() { + m.source_ref = nil + delete(m.clearedFields, agentdefinition.FieldSourceRef) +} + +// SetRegistryXrn sets the "registry_xrn" field. +func (m *AgentDefinitionMutation) SetRegistryXrn(s string) { + m.registry_xrn = &s +} + +// RegistryXrn returns the value of the "registry_xrn" field in the mutation. +func (m *AgentDefinitionMutation) RegistryXrn() (r string, exists bool) { + v := m.registry_xrn + if v == nil { + return + } + return *v, true +} + +// OldRegistryXrn returns the old "registry_xrn" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldRegistryXrn(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRegistryXrn is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRegistryXrn requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRegistryXrn: %w", err) + } + return oldValue.RegistryXrn, nil +} + +// ClearRegistryXrn clears the value of the "registry_xrn" field. +func (m *AgentDefinitionMutation) ClearRegistryXrn() { + m.registry_xrn = nil + m.clearedFields[agentdefinition.FieldRegistryXrn] = struct{}{} +} + +// RegistryXrnCleared returns if the "registry_xrn" field was cleared in this mutation. +func (m *AgentDefinitionMutation) RegistryXrnCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldRegistryXrn] + return ok +} + +// ResetRegistryXrn resets all changes to the "registry_xrn" field. +func (m *AgentDefinitionMutation) ResetRegistryXrn() { + m.registry_xrn = nil + delete(m.clearedFields, agentdefinition.FieldRegistryXrn) +} + +// SetDescription sets the "description" field. +func (m *AgentDefinitionMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *AgentDefinitionMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *AgentDefinitionMutation) ClearDescription() { + m.description = nil + m.clearedFields[agentdefinition.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *AgentDefinitionMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *AgentDefinitionMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, agentdefinition.FieldDescription) +} + +// SetModel sets the "model" field. +func (m *AgentDefinitionMutation) SetModel(s string) { + m.model = &s +} + +// Model returns the value of the "model" field in the mutation. +func (m *AgentDefinitionMutation) Model() (r string, exists bool) { + v := m.model + if v == nil { + return + } + return *v, true +} + +// OldModel returns the old "model" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldModel(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldModel is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldModel requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldModel: %w", err) + } + return oldValue.Model, nil +} + +// ClearModel clears the value of the "model" field. +func (m *AgentDefinitionMutation) ClearModel() { + m.model = nil + m.clearedFields[agentdefinition.FieldModel] = struct{}{} +} + +// ModelCleared returns if the "model" field was cleared in this mutation. +func (m *AgentDefinitionMutation) ModelCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldModel] + return ok +} + +// ResetModel resets all changes to the "model" field. +func (m *AgentDefinitionMutation) ResetModel() { + m.model = nil + delete(m.clearedFields, agentdefinition.FieldModel) +} + +// SetIcon sets the "icon" field. +func (m *AgentDefinitionMutation) SetIcon(s string) { + m.icon = &s +} + +// Icon returns the value of the "icon" field in the mutation. +func (m *AgentDefinitionMutation) Icon() (r string, exists bool) { + v := m.icon + if v == nil { + return + } + return *v, true +} + +// OldIcon returns the old "icon" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldIcon(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIcon is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIcon requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIcon: %w", err) + } + return oldValue.Icon, nil +} + +// ClearIcon clears the value of the "icon" field. +func (m *AgentDefinitionMutation) ClearIcon() { + m.icon = nil + m.clearedFields[agentdefinition.FieldIcon] = struct{}{} +} + +// IconCleared returns if the "icon" field was cleared in this mutation. +func (m *AgentDefinitionMutation) IconCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldIcon] + return ok +} + +// ResetIcon resets all changes to the "icon" field. +func (m *AgentDefinitionMutation) ResetIcon() { + m.icon = nil + delete(m.clearedFields, agentdefinition.FieldIcon) +} + +// SetRole sets the "role" field. +func (m *AgentDefinitionMutation) SetRole(s string) { + m.role = &s +} + +// Role returns the value of the "role" field in the mutation. +func (m *AgentDefinitionMutation) Role() (r string, exists bool) { + v := m.role + if v == nil { + return + } + return *v, true +} + +// OldRole returns the old "role" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldRole(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRole is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRole requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRole: %w", err) + } + return oldValue.Role, nil +} + +// ClearRole clears the value of the "role" field. +func (m *AgentDefinitionMutation) ClearRole() { + m.role = nil + m.clearedFields[agentdefinition.FieldRole] = struct{}{} +} + +// RoleCleared returns if the "role" field was cleared in this mutation. +func (m *AgentDefinitionMutation) RoleCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldRole] + return ok +} + +// ResetRole resets all changes to the "role" field. +func (m *AgentDefinitionMutation) ResetRole() { + m.role = nil + delete(m.clearedFields, agentdefinition.FieldRole) +} + +// SetTools sets the "tools" field. +func (m *AgentDefinitionMutation) SetTools(s []string) { + m.tools = &s + m.appendtools = nil +} + +// Tools returns the value of the "tools" field in the mutation. +func (m *AgentDefinitionMutation) Tools() (r []string, exists bool) { + v := m.tools + if v == nil { + return + } + return *v, true +} + +// OldTools returns the old "tools" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldTools(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTools is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTools requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTools: %w", err) + } + return oldValue.Tools, nil +} + +// AppendTools adds s to the "tools" field. +func (m *AgentDefinitionMutation) AppendTools(s []string) { + m.appendtools = append(m.appendtools, s...) +} + +// AppendedTools returns the list of values that were appended to the "tools" field in this mutation. +func (m *AgentDefinitionMutation) AppendedTools() ([]string, bool) { + if len(m.appendtools) == 0 { + return nil, false + } + return m.appendtools, true +} + +// ClearTools clears the value of the "tools" field. +func (m *AgentDefinitionMutation) ClearTools() { + m.tools = nil + m.appendtools = nil + m.clearedFields[agentdefinition.FieldTools] = struct{}{} +} + +// ToolsCleared returns if the "tools" field was cleared in this mutation. +func (m *AgentDefinitionMutation) ToolsCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldTools] + return ok +} + +// ResetTools resets all changes to the "tools" field. +func (m *AgentDefinitionMutation) ResetTools() { + m.tools = nil + m.appendtools = nil + delete(m.clearedFields, agentdefinition.FieldTools) +} + +// SetAllowedTools sets the "allowed_tools" field. +func (m *AgentDefinitionMutation) SetAllowedTools(s []string) { + m.allowed_tools = &s + m.appendallowed_tools = nil +} + +// AllowedTools returns the value of the "allowed_tools" field in the mutation. +func (m *AgentDefinitionMutation) AllowedTools() (r []string, exists bool) { + v := m.allowed_tools + if v == nil { + return + } + return *v, true +} + +// OldAllowedTools returns the old "allowed_tools" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldAllowedTools(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAllowedTools is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAllowedTools requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAllowedTools: %w", err) + } + return oldValue.AllowedTools, nil +} + +// AppendAllowedTools adds s to the "allowed_tools" field. +func (m *AgentDefinitionMutation) AppendAllowedTools(s []string) { + m.appendallowed_tools = append(m.appendallowed_tools, s...) +} + +// AppendedAllowedTools returns the list of values that were appended to the "allowed_tools" field in this mutation. +func (m *AgentDefinitionMutation) AppendedAllowedTools() ([]string, bool) { + if len(m.appendallowed_tools) == 0 { + return nil, false + } + return m.appendallowed_tools, true +} + +// ClearAllowedTools clears the value of the "allowed_tools" field. +func (m *AgentDefinitionMutation) ClearAllowedTools() { + m.allowed_tools = nil + m.appendallowed_tools = nil + m.clearedFields[agentdefinition.FieldAllowedTools] = struct{}{} +} + +// AllowedToolsCleared returns if the "allowed_tools" field was cleared in this mutation. +func (m *AgentDefinitionMutation) AllowedToolsCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldAllowedTools] + return ok +} + +// ResetAllowedTools resets all changes to the "allowed_tools" field. +func (m *AgentDefinitionMutation) ResetAllowedTools() { + m.allowed_tools = nil + m.appendallowed_tools = nil + delete(m.clearedFields, agentdefinition.FieldAllowedTools) +} + +// SetSkills sets the "skills" field. +func (m *AgentDefinitionMutation) SetSkills(s []string) { + m.skills = &s + m.appendskills = nil +} + +// Skills returns the value of the "skills" field in the mutation. +func (m *AgentDefinitionMutation) Skills() (r []string, exists bool) { + v := m.skills + if v == nil { + return + } + return *v, true +} + +// OldSkills returns the old "skills" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldSkills(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSkills is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSkills requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSkills: %w", err) + } + return oldValue.Skills, nil +} + +// AppendSkills adds s to the "skills" field. +func (m *AgentDefinitionMutation) AppendSkills(s []string) { + m.appendskills = append(m.appendskills, s...) +} + +// AppendedSkills returns the list of values that were appended to the "skills" field in this mutation. +func (m *AgentDefinitionMutation) AppendedSkills() ([]string, bool) { + if len(m.appendskills) == 0 { + return nil, false + } + return m.appendskills, true +} + +// ClearSkills clears the value of the "skills" field. +func (m *AgentDefinitionMutation) ClearSkills() { + m.skills = nil + m.appendskills = nil + m.clearedFields[agentdefinition.FieldSkills] = struct{}{} +} + +// SkillsCleared returns if the "skills" field was cleared in this mutation. +func (m *AgentDefinitionMutation) SkillsCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldSkills] + return ok +} + +// ResetSkills resets all changes to the "skills" field. +func (m *AgentDefinitionMutation) ResetSkills() { + m.skills = nil + m.appendskills = nil + delete(m.clearedFields, agentdefinition.FieldSkills) +} + +// SetDependencies sets the "dependencies" field. +func (m *AgentDefinitionMutation) SetDependencies(s []string) { + m.dependencies = &s + m.appenddependencies = nil +} + +// Dependencies returns the value of the "dependencies" field in the mutation. +func (m *AgentDefinitionMutation) Dependencies() (r []string, exists bool) { + v := m.dependencies + if v == nil { + return + } + return *v, true +} + +// OldDependencies returns the old "dependencies" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldDependencies(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDependencies is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDependencies requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDependencies: %w", err) + } + return oldValue.Dependencies, nil +} + +// AppendDependencies adds s to the "dependencies" field. +func (m *AgentDefinitionMutation) AppendDependencies(s []string) { + m.appenddependencies = append(m.appenddependencies, s...) +} + +// AppendedDependencies returns the list of values that were appended to the "dependencies" field in this mutation. +func (m *AgentDefinitionMutation) AppendedDependencies() ([]string, bool) { + if len(m.appenddependencies) == 0 { + return nil, false + } + return m.appenddependencies, true +} + +// ClearDependencies clears the value of the "dependencies" field. +func (m *AgentDefinitionMutation) ClearDependencies() { + m.dependencies = nil + m.appenddependencies = nil + m.clearedFields[agentdefinition.FieldDependencies] = struct{}{} +} + +// DependenciesCleared returns if the "dependencies" field was cleared in this mutation. +func (m *AgentDefinitionMutation) DependenciesCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldDependencies] + return ok +} + +// ResetDependencies resets all changes to the "dependencies" field. +func (m *AgentDefinitionMutation) ResetDependencies() { + m.dependencies = nil + m.appenddependencies = nil + delete(m.clearedFields, agentdefinition.FieldDependencies) +} + +// SetRequires sets the "requires" field. +func (m *AgentDefinitionMutation) SetRequires(s []string) { + m.requires = &s + m.appendrequires = nil +} + +// Requires returns the value of the "requires" field in the mutation. +func (m *AgentDefinitionMutation) Requires() (r []string, exists bool) { + v := m.requires + if v == nil { + return + } + return *v, true +} + +// OldRequires returns the old "requires" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldRequires(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRequires is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRequires requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRequires: %w", err) + } + return oldValue.Requires, nil +} + +// AppendRequires adds s to the "requires" field. +func (m *AgentDefinitionMutation) AppendRequires(s []string) { + m.appendrequires = append(m.appendrequires, s...) +} + +// AppendedRequires returns the list of values that were appended to the "requires" field in this mutation. +func (m *AgentDefinitionMutation) AppendedRequires() ([]string, bool) { + if len(m.appendrequires) == 0 { + return nil, false + } + return m.appendrequires, true +} + +// ClearRequires clears the value of the "requires" field. +func (m *AgentDefinitionMutation) ClearRequires() { + m.requires = nil + m.appendrequires = nil + m.clearedFields[agentdefinition.FieldRequires] = struct{}{} +} + +// RequiresCleared returns if the "requires" field was cleared in this mutation. +func (m *AgentDefinitionMutation) RequiresCleared() bool { + _, ok := m.clearedFields[agentdefinition.FieldRequires] + return ok +} + +// ResetRequires resets all changes to the "requires" field. +func (m *AgentDefinitionMutation) ResetRequires() { + m.requires = nil + m.appendrequires = nil + delete(m.clearedFields, agentdefinition.FieldRequires) +} + +// SetSourcePath sets the "source_path" field. +func (m *AgentDefinitionMutation) SetSourcePath(s string) { + m.source_path = &s +} + +// SourcePath returns the value of the "source_path" field in the mutation. +func (m *AgentDefinitionMutation) SourcePath() (r string, exists bool) { + v := m.source_path + if v == nil { + return + } + return *v, true +} + +// OldSourcePath returns the old "source_path" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldSourcePath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSourcePath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSourcePath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSourcePath: %w", err) + } + return oldValue.SourcePath, nil +} + +// ResetSourcePath resets all changes to the "source_path" field. +func (m *AgentDefinitionMutation) ResetSourcePath() { + m.source_path = nil +} + +// SetContentHash sets the "content_hash" field. +func (m *AgentDefinitionMutation) SetContentHash(s string) { + m.content_hash = &s +} + +// ContentHash returns the value of the "content_hash" field in the mutation. +func (m *AgentDefinitionMutation) ContentHash() (r string, exists bool) { + v := m.content_hash + if v == nil { + return + } + return *v, true +} + +// OldContentHash returns the old "content_hash" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldContentHash(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldContentHash is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldContentHash requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldContentHash: %w", err) + } + return oldValue.ContentHash, nil +} + +// ResetContentHash resets all changes to the "content_hash" field. +func (m *AgentDefinitionMutation) ResetContentHash() { + m.content_hash = nil +} + +// SetFirstSeenAt sets the "first_seen_at" field. +func (m *AgentDefinitionMutation) SetFirstSeenAt(t time.Time) { + m.first_seen_at = &t +} + +// FirstSeenAt returns the value of the "first_seen_at" field in the mutation. +func (m *AgentDefinitionMutation) FirstSeenAt() (r time.Time, exists bool) { + v := m.first_seen_at + if v == nil { + return + } + return *v, true +} + +// OldFirstSeenAt returns the old "first_seen_at" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldFirstSeenAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFirstSeenAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFirstSeenAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFirstSeenAt: %w", err) + } + return oldValue.FirstSeenAt, nil +} + +// ResetFirstSeenAt resets all changes to the "first_seen_at" field. +func (m *AgentDefinitionMutation) ResetFirstSeenAt() { + m.first_seen_at = nil +} + +// SetLastSeenAt sets the "last_seen_at" field. +func (m *AgentDefinitionMutation) SetLastSeenAt(t time.Time) { + m.last_seen_at = &t +} + +// LastSeenAt returns the value of the "last_seen_at" field in the mutation. +func (m *AgentDefinitionMutation) LastSeenAt() (r time.Time, exists bool) { + v := m.last_seen_at + if v == nil { + return + } + return *v, true +} + +// OldLastSeenAt returns the old "last_seen_at" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldLastSeenAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLastSeenAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLastSeenAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLastSeenAt: %w", err) + } + return oldValue.LastSeenAt, nil +} + +// ResetLastSeenAt resets all changes to the "last_seen_at" field. +func (m *AgentDefinitionMutation) ResetLastSeenAt() { + m.last_seen_at = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *AgentDefinitionMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *AgentDefinitionMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *AgentDefinitionMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *AgentDefinitionMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *AgentDefinitionMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the AgentDefinition entity. +// If the AgentDefinition 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 *AgentDefinitionMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *AgentDefinitionMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// AddTeamIDs adds the "teams" edge to the TeamDefinition entity by ids. +func (m *AgentDefinitionMutation) AddTeamIDs(ids ...uuid.UUID) { + if m.teams == nil { + m.teams = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.teams[ids[i]] = struct{}{} + } +} + +// ClearTeams clears the "teams" edge to the TeamDefinition entity. +func (m *AgentDefinitionMutation) ClearTeams() { + m.clearedteams = true +} + +// TeamsCleared reports if the "teams" edge to the TeamDefinition entity was cleared. +func (m *AgentDefinitionMutation) TeamsCleared() bool { + return m.clearedteams +} + +// RemoveTeamIDs removes the "teams" edge to the TeamDefinition entity by IDs. +func (m *AgentDefinitionMutation) RemoveTeamIDs(ids ...uuid.UUID) { + if m.removedteams == nil { + m.removedteams = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.teams, ids[i]) + m.removedteams[ids[i]] = struct{}{} + } +} + +// RemovedTeams returns the removed IDs of the "teams" edge to the TeamDefinition entity. +func (m *AgentDefinitionMutation) RemovedTeamsIDs() (ids []uuid.UUID) { + for id := range m.removedteams { + ids = append(ids, id) + } + return +} + +// TeamsIDs returns the "teams" edge IDs in the mutation. +func (m *AgentDefinitionMutation) TeamsIDs() (ids []uuid.UUID) { + for id := range m.teams { + ids = append(ids, id) + } + return +} + +// ResetTeams resets all changes to the "teams" edge. +func (m *AgentDefinitionMutation) ResetTeams() { + m.teams = nil + m.clearedteams = false + m.removedteams = nil +} + +// Where appends a list predicates to the AgentDefinitionMutation builder. +func (m *AgentDefinitionMutation) Where(ps ...predicate.AgentDefinition) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the AgentDefinitionMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AgentDefinitionMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.AgentDefinition, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *AgentDefinitionMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *AgentDefinitionMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (AgentDefinition). +func (m *AgentDefinitionMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *AgentDefinitionMutation) Fields() []string { + fields := make([]string, 0, 21) + if m.repo_name != nil { + fields = append(fields, agentdefinition.FieldRepoName) + } + if m.namespace != nil { + fields = append(fields, agentdefinition.FieldNamespace) + } + if m.name != nil { + fields = append(fields, agentdefinition.FieldName) + } + if m.qualified_name != nil { + fields = append(fields, agentdefinition.FieldQualifiedName) + } + if m.source_ref != nil { + fields = append(fields, agentdefinition.FieldSourceRef) + } + if m.registry_xrn != nil { + fields = append(fields, agentdefinition.FieldRegistryXrn) + } + if m.description != nil { + fields = append(fields, agentdefinition.FieldDescription) + } + if m.model != nil { + fields = append(fields, agentdefinition.FieldModel) + } + if m.icon != nil { + fields = append(fields, agentdefinition.FieldIcon) + } + if m.role != nil { + fields = append(fields, agentdefinition.FieldRole) + } + if m.tools != nil { + fields = append(fields, agentdefinition.FieldTools) + } + if m.allowed_tools != nil { + fields = append(fields, agentdefinition.FieldAllowedTools) + } + if m.skills != nil { + fields = append(fields, agentdefinition.FieldSkills) + } + if m.dependencies != nil { + fields = append(fields, agentdefinition.FieldDependencies) + } + if m.requires != nil { + fields = append(fields, agentdefinition.FieldRequires) + } + if m.source_path != nil { + fields = append(fields, agentdefinition.FieldSourcePath) + } + if m.content_hash != nil { + fields = append(fields, agentdefinition.FieldContentHash) + } + if m.first_seen_at != nil { + fields = append(fields, agentdefinition.FieldFirstSeenAt) + } + if m.last_seen_at != nil { + fields = append(fields, agentdefinition.FieldLastSeenAt) + } + if m.created_at != nil { + fields = append(fields, agentdefinition.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, agentdefinition.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *AgentDefinitionMutation) Field(name string) (ent.Value, bool) { + switch name { + case agentdefinition.FieldRepoName: + return m.RepoName() + case agentdefinition.FieldNamespace: + return m.Namespace() + case agentdefinition.FieldName: + return m.Name() + case agentdefinition.FieldQualifiedName: + return m.QualifiedName() + case agentdefinition.FieldSourceRef: + return m.SourceRef() + case agentdefinition.FieldRegistryXrn: + return m.RegistryXrn() + case agentdefinition.FieldDescription: + return m.Description() + case agentdefinition.FieldModel: + return m.Model() + case agentdefinition.FieldIcon: + return m.Icon() + case agentdefinition.FieldRole: + return m.Role() + case agentdefinition.FieldTools: + return m.Tools() + case agentdefinition.FieldAllowedTools: + return m.AllowedTools() + case agentdefinition.FieldSkills: + return m.Skills() + case agentdefinition.FieldDependencies: + return m.Dependencies() + case agentdefinition.FieldRequires: + return m.Requires() + case agentdefinition.FieldSourcePath: + return m.SourcePath() + case agentdefinition.FieldContentHash: + return m.ContentHash() + case agentdefinition.FieldFirstSeenAt: + return m.FirstSeenAt() + case agentdefinition.FieldLastSeenAt: + return m.LastSeenAt() + case agentdefinition.FieldCreatedAt: + return m.CreatedAt() + case agentdefinition.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *AgentDefinitionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case agentdefinition.FieldRepoName: + return m.OldRepoName(ctx) + case agentdefinition.FieldNamespace: + return m.OldNamespace(ctx) + case agentdefinition.FieldName: + return m.OldName(ctx) + case agentdefinition.FieldQualifiedName: + return m.OldQualifiedName(ctx) + case agentdefinition.FieldSourceRef: + return m.OldSourceRef(ctx) + case agentdefinition.FieldRegistryXrn: + return m.OldRegistryXrn(ctx) + case agentdefinition.FieldDescription: + return m.OldDescription(ctx) + case agentdefinition.FieldModel: + return m.OldModel(ctx) + case agentdefinition.FieldIcon: + return m.OldIcon(ctx) + case agentdefinition.FieldRole: + return m.OldRole(ctx) + case agentdefinition.FieldTools: + return m.OldTools(ctx) + case agentdefinition.FieldAllowedTools: + return m.OldAllowedTools(ctx) + case agentdefinition.FieldSkills: + return m.OldSkills(ctx) + case agentdefinition.FieldDependencies: + return m.OldDependencies(ctx) + case agentdefinition.FieldRequires: + return m.OldRequires(ctx) + case agentdefinition.FieldSourcePath: + return m.OldSourcePath(ctx) + case agentdefinition.FieldContentHash: + return m.OldContentHash(ctx) + case agentdefinition.FieldFirstSeenAt: + return m.OldFirstSeenAt(ctx) + case agentdefinition.FieldLastSeenAt: + return m.OldLastSeenAt(ctx) + case agentdefinition.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case agentdefinition.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown AgentDefinition field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *AgentDefinitionMutation) SetField(name string, value ent.Value) error { + switch name { + case agentdefinition.FieldRepoName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRepoName(v) + return nil + case agentdefinition.FieldNamespace: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNamespace(v) + return nil + case agentdefinition.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case agentdefinition.FieldQualifiedName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetQualifiedName(v) + return nil + case agentdefinition.FieldSourceRef: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSourceRef(v) + return nil + case agentdefinition.FieldRegistryXrn: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRegistryXrn(v) + return nil + case agentdefinition.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case agentdefinition.FieldModel: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetModel(v) + return nil + case agentdefinition.FieldIcon: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIcon(v) + return nil + case agentdefinition.FieldRole: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRole(v) + return nil + case agentdefinition.FieldTools: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTools(v) + return nil + case agentdefinition.FieldAllowedTools: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAllowedTools(v) + return nil + case agentdefinition.FieldSkills: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSkills(v) + return nil + case agentdefinition.FieldDependencies: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDependencies(v) + return nil + case agentdefinition.FieldRequires: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRequires(v) + return nil + case agentdefinition.FieldSourcePath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSourcePath(v) + return nil + case agentdefinition.FieldContentHash: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetContentHash(v) + return nil + case agentdefinition.FieldFirstSeenAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFirstSeenAt(v) + return nil + case agentdefinition.FieldLastSeenAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLastSeenAt(v) + return nil + case agentdefinition.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case agentdefinition.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown AgentDefinition field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *AgentDefinitionMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *AgentDefinitionMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *AgentDefinitionMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown AgentDefinition numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *AgentDefinitionMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(agentdefinition.FieldSourceRef) { + fields = append(fields, agentdefinition.FieldSourceRef) + } + if m.FieldCleared(agentdefinition.FieldRegistryXrn) { + fields = append(fields, agentdefinition.FieldRegistryXrn) + } + if m.FieldCleared(agentdefinition.FieldDescription) { + fields = append(fields, agentdefinition.FieldDescription) + } + if m.FieldCleared(agentdefinition.FieldModel) { + fields = append(fields, agentdefinition.FieldModel) + } + if m.FieldCleared(agentdefinition.FieldIcon) { + fields = append(fields, agentdefinition.FieldIcon) + } + if m.FieldCleared(agentdefinition.FieldRole) { + fields = append(fields, agentdefinition.FieldRole) + } + if m.FieldCleared(agentdefinition.FieldTools) { + fields = append(fields, agentdefinition.FieldTools) + } + if m.FieldCleared(agentdefinition.FieldAllowedTools) { + fields = append(fields, agentdefinition.FieldAllowedTools) + } + if m.FieldCleared(agentdefinition.FieldSkills) { + fields = append(fields, agentdefinition.FieldSkills) + } + if m.FieldCleared(agentdefinition.FieldDependencies) { + fields = append(fields, agentdefinition.FieldDependencies) + } + if m.FieldCleared(agentdefinition.FieldRequires) { + fields = append(fields, agentdefinition.FieldRequires) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *AgentDefinitionMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *AgentDefinitionMutation) ClearField(name string) error { + switch name { + case agentdefinition.FieldSourceRef: + m.ClearSourceRef() + return nil + case agentdefinition.FieldRegistryXrn: + m.ClearRegistryXrn() + return nil + case agentdefinition.FieldDescription: + m.ClearDescription() + return nil + case agentdefinition.FieldModel: + m.ClearModel() + return nil + case agentdefinition.FieldIcon: + m.ClearIcon() + return nil + case agentdefinition.FieldRole: + m.ClearRole() + return nil + case agentdefinition.FieldTools: + m.ClearTools() + return nil + case agentdefinition.FieldAllowedTools: + m.ClearAllowedTools() + return nil + case agentdefinition.FieldSkills: + m.ClearSkills() + return nil + case agentdefinition.FieldDependencies: + m.ClearDependencies() + return nil + case agentdefinition.FieldRequires: + m.ClearRequires() + return nil + } + return fmt.Errorf("unknown AgentDefinition nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *AgentDefinitionMutation) ResetField(name string) error { + switch name { + case agentdefinition.FieldRepoName: + m.ResetRepoName() + return nil + case agentdefinition.FieldNamespace: + m.ResetNamespace() + return nil + case agentdefinition.FieldName: + m.ResetName() + return nil + case agentdefinition.FieldQualifiedName: + m.ResetQualifiedName() + return nil + case agentdefinition.FieldSourceRef: + m.ResetSourceRef() + return nil + case agentdefinition.FieldRegistryXrn: + m.ResetRegistryXrn() + return nil + case agentdefinition.FieldDescription: + m.ResetDescription() + return nil + case agentdefinition.FieldModel: + m.ResetModel() + return nil + case agentdefinition.FieldIcon: + m.ResetIcon() + return nil + case agentdefinition.FieldRole: + m.ResetRole() + return nil + case agentdefinition.FieldTools: + m.ResetTools() + return nil + case agentdefinition.FieldAllowedTools: + m.ResetAllowedTools() + return nil + case agentdefinition.FieldSkills: + m.ResetSkills() + return nil + case agentdefinition.FieldDependencies: + m.ResetDependencies() + return nil + case agentdefinition.FieldRequires: + m.ResetRequires() + return nil + case agentdefinition.FieldSourcePath: + m.ResetSourcePath() + return nil + case agentdefinition.FieldContentHash: + m.ResetContentHash() + return nil + case agentdefinition.FieldFirstSeenAt: + m.ResetFirstSeenAt() + return nil + case agentdefinition.FieldLastSeenAt: + m.ResetLastSeenAt() + return nil + case agentdefinition.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case agentdefinition.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown AgentDefinition field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *AgentDefinitionMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.teams != nil { + edges = append(edges, agentdefinition.EdgeTeams) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *AgentDefinitionMutation) AddedIDs(name string) []ent.Value { + switch name { + case agentdefinition.EdgeTeams: + ids := make([]ent.Value, 0, len(m.teams)) + for id := range m.teams { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *AgentDefinitionMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + if m.removedteams != nil { + edges = append(edges, agentdefinition.EdgeTeams) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *AgentDefinitionMutation) RemovedIDs(name string) []ent.Value { + switch name { + case agentdefinition.EdgeTeams: + ids := make([]ent.Value, 0, len(m.removedteams)) + for id := range m.removedteams { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *AgentDefinitionMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedteams { + edges = append(edges, agentdefinition.EdgeTeams) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *AgentDefinitionMutation) EdgeCleared(name string) bool { + switch name { + case agentdefinition.EdgeTeams: + return m.clearedteams + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *AgentDefinitionMutation) ClearEdge(name string) error { + switch name { + } + return fmt.Errorf("unknown AgentDefinition unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *AgentDefinitionMutation) ResetEdge(name string) error { + switch name { + case agentdefinition.EdgeTeams: + m.ResetTeams() + return nil + } + return fmt.Errorf("unknown AgentDefinition edge %s", name) +} + +// TeamDefinitionMutation represents an operation that mutates the TeamDefinition nodes in the graph. +type TeamDefinitionMutation struct { + config + op Op + typ string + id *uuid.UUID + repo_name *string + name *string + source_ref *string + registry_xrn *string + version *string + description *string + orchestrator *string + agent_names *[]string + appendagent_names []string + source_path *string + content_hash *string + first_seen_at *time.Time + last_seen_at *time.Time + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + agents map[uuid.UUID]struct{} + removedagents map[uuid.UUID]struct{} + clearedagents bool + done bool + oldValue func(context.Context) (*TeamDefinition, error) + predicates []predicate.TeamDefinition +} + +var _ ent.Mutation = (*TeamDefinitionMutation)(nil) + +// teamdefinitionOption allows management of the mutation configuration using functional options. +type teamdefinitionOption func(*TeamDefinitionMutation) + +// newTeamDefinitionMutation creates new mutation for the TeamDefinition entity. +func newTeamDefinitionMutation(c config, op Op, opts ...teamdefinitionOption) *TeamDefinitionMutation { + m := &TeamDefinitionMutation{ + config: c, + op: op, + typ: TypeTeamDefinition, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withTeamDefinitionID sets the ID field of the mutation. +func withTeamDefinitionID(id uuid.UUID) teamdefinitionOption { + return func(m *TeamDefinitionMutation) { + var ( + err error + once sync.Once + value *TeamDefinition + ) + m.oldValue = func(ctx context.Context) (*TeamDefinition, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().TeamDefinition.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withTeamDefinition sets the old TeamDefinition of the mutation. +func withTeamDefinition(node *TeamDefinition) teamdefinitionOption { + return func(m *TeamDefinitionMutation) { + m.oldValue = func(context.Context) (*TeamDefinition, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m TeamDefinitionMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m TeamDefinitionMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of TeamDefinition entities. +func (m *TeamDefinitionMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *TeamDefinitionMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *TeamDefinitionMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().TeamDefinition.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetRepoName sets the "repo_name" field. +func (m *TeamDefinitionMutation) SetRepoName(s string) { + m.repo_name = &s +} + +// RepoName returns the value of the "repo_name" field in the mutation. +func (m *TeamDefinitionMutation) RepoName() (r string, exists bool) { + v := m.repo_name + if v == nil { + return + } + return *v, true +} + +// OldRepoName returns the old "repo_name" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldRepoName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRepoName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRepoName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRepoName: %w", err) + } + return oldValue.RepoName, nil +} + +// ResetRepoName resets all changes to the "repo_name" field. +func (m *TeamDefinitionMutation) ResetRepoName() { + m.repo_name = nil +} + +// SetName sets the "name" field. +func (m *TeamDefinitionMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *TeamDefinitionMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *TeamDefinitionMutation) ResetName() { + m.name = nil +} + +// SetSourceRef sets the "source_ref" field. +func (m *TeamDefinitionMutation) SetSourceRef(s string) { + m.source_ref = &s +} + +// SourceRef returns the value of the "source_ref" field in the mutation. +func (m *TeamDefinitionMutation) SourceRef() (r string, exists bool) { + v := m.source_ref + if v == nil { + return + } + return *v, true +} + +// OldSourceRef returns the old "source_ref" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldSourceRef(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSourceRef is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSourceRef requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSourceRef: %w", err) + } + return oldValue.SourceRef, nil +} + +// ClearSourceRef clears the value of the "source_ref" field. +func (m *TeamDefinitionMutation) ClearSourceRef() { + m.source_ref = nil + m.clearedFields[teamdefinition.FieldSourceRef] = struct{}{} +} + +// SourceRefCleared returns if the "source_ref" field was cleared in this mutation. +func (m *TeamDefinitionMutation) SourceRefCleared() bool { + _, ok := m.clearedFields[teamdefinition.FieldSourceRef] + return ok +} + +// ResetSourceRef resets all changes to the "source_ref" field. +func (m *TeamDefinitionMutation) ResetSourceRef() { + m.source_ref = nil + delete(m.clearedFields, teamdefinition.FieldSourceRef) +} + +// SetRegistryXrn sets the "registry_xrn" field. +func (m *TeamDefinitionMutation) SetRegistryXrn(s string) { + m.registry_xrn = &s +} + +// RegistryXrn returns the value of the "registry_xrn" field in the mutation. +func (m *TeamDefinitionMutation) RegistryXrn() (r string, exists bool) { + v := m.registry_xrn + if v == nil { + return + } + return *v, true +} + +// OldRegistryXrn returns the old "registry_xrn" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldRegistryXrn(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRegistryXrn is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRegistryXrn requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRegistryXrn: %w", err) + } + return oldValue.RegistryXrn, nil +} + +// ClearRegistryXrn clears the value of the "registry_xrn" field. +func (m *TeamDefinitionMutation) ClearRegistryXrn() { + m.registry_xrn = nil + m.clearedFields[teamdefinition.FieldRegistryXrn] = struct{}{} +} + +// RegistryXrnCleared returns if the "registry_xrn" field was cleared in this mutation. +func (m *TeamDefinitionMutation) RegistryXrnCleared() bool { + _, ok := m.clearedFields[teamdefinition.FieldRegistryXrn] + return ok +} + +// ResetRegistryXrn resets all changes to the "registry_xrn" field. +func (m *TeamDefinitionMutation) ResetRegistryXrn() { + m.registry_xrn = nil + delete(m.clearedFields, teamdefinition.FieldRegistryXrn) +} + +// SetVersion sets the "version" field. +func (m *TeamDefinitionMutation) SetVersion(s string) { + m.version = &s +} + +// Version returns the value of the "version" field in the mutation. +func (m *TeamDefinitionMutation) Version() (r string, exists bool) { + v := m.version + if v == nil { + return + } + return *v, true +} + +// OldVersion returns the old "version" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldVersion(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldVersion is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldVersion requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldVersion: %w", err) + } + return oldValue.Version, nil +} + +// ClearVersion clears the value of the "version" field. +func (m *TeamDefinitionMutation) ClearVersion() { + m.version = nil + m.clearedFields[teamdefinition.FieldVersion] = struct{}{} +} + +// VersionCleared returns if the "version" field was cleared in this mutation. +func (m *TeamDefinitionMutation) VersionCleared() bool { + _, ok := m.clearedFields[teamdefinition.FieldVersion] + return ok +} + +// ResetVersion resets all changes to the "version" field. +func (m *TeamDefinitionMutation) ResetVersion() { + m.version = nil + delete(m.clearedFields, teamdefinition.FieldVersion) +} + +// SetDescription sets the "description" field. +func (m *TeamDefinitionMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *TeamDefinitionMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *TeamDefinitionMutation) ClearDescription() { + m.description = nil + m.clearedFields[teamdefinition.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *TeamDefinitionMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[teamdefinition.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *TeamDefinitionMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, teamdefinition.FieldDescription) +} + +// SetOrchestrator sets the "orchestrator" field. +func (m *TeamDefinitionMutation) SetOrchestrator(s string) { + m.orchestrator = &s +} + +// Orchestrator returns the value of the "orchestrator" field in the mutation. +func (m *TeamDefinitionMutation) Orchestrator() (r string, exists bool) { + v := m.orchestrator + if v == nil { + return + } + return *v, true +} + +// OldOrchestrator returns the old "orchestrator" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldOrchestrator(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldOrchestrator is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldOrchestrator requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldOrchestrator: %w", err) + } + return oldValue.Orchestrator, nil +} + +// ClearOrchestrator clears the value of the "orchestrator" field. +func (m *TeamDefinitionMutation) ClearOrchestrator() { + m.orchestrator = nil + m.clearedFields[teamdefinition.FieldOrchestrator] = struct{}{} +} + +// OrchestratorCleared returns if the "orchestrator" field was cleared in this mutation. +func (m *TeamDefinitionMutation) OrchestratorCleared() bool { + _, ok := m.clearedFields[teamdefinition.FieldOrchestrator] + return ok +} + +// ResetOrchestrator resets all changes to the "orchestrator" field. +func (m *TeamDefinitionMutation) ResetOrchestrator() { + m.orchestrator = nil + delete(m.clearedFields, teamdefinition.FieldOrchestrator) +} + +// SetAgentNames sets the "agent_names" field. +func (m *TeamDefinitionMutation) SetAgentNames(s []string) { + m.agent_names = &s + m.appendagent_names = nil +} + +// AgentNames returns the value of the "agent_names" field in the mutation. +func (m *TeamDefinitionMutation) AgentNames() (r []string, exists bool) { + v := m.agent_names + if v == nil { + return + } + return *v, true +} + +// OldAgentNames returns the old "agent_names" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldAgentNames(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAgentNames is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAgentNames requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAgentNames: %w", err) + } + return oldValue.AgentNames, nil +} + +// AppendAgentNames adds s to the "agent_names" field. +func (m *TeamDefinitionMutation) AppendAgentNames(s []string) { + m.appendagent_names = append(m.appendagent_names, s...) +} + +// AppendedAgentNames returns the list of values that were appended to the "agent_names" field in this mutation. +func (m *TeamDefinitionMutation) AppendedAgentNames() ([]string, bool) { + if len(m.appendagent_names) == 0 { + return nil, false + } + return m.appendagent_names, true +} + +// ClearAgentNames clears the value of the "agent_names" field. +func (m *TeamDefinitionMutation) ClearAgentNames() { + m.agent_names = nil + m.appendagent_names = nil + m.clearedFields[teamdefinition.FieldAgentNames] = struct{}{} +} + +// AgentNamesCleared returns if the "agent_names" field was cleared in this mutation. +func (m *TeamDefinitionMutation) AgentNamesCleared() bool { + _, ok := m.clearedFields[teamdefinition.FieldAgentNames] + return ok +} + +// ResetAgentNames resets all changes to the "agent_names" field. +func (m *TeamDefinitionMutation) ResetAgentNames() { + m.agent_names = nil + m.appendagent_names = nil + delete(m.clearedFields, teamdefinition.FieldAgentNames) +} + +// SetSourcePath sets the "source_path" field. +func (m *TeamDefinitionMutation) SetSourcePath(s string) { + m.source_path = &s +} + +// SourcePath returns the value of the "source_path" field in the mutation. +func (m *TeamDefinitionMutation) SourcePath() (r string, exists bool) { + v := m.source_path + if v == nil { + return + } + return *v, true +} + +// OldSourcePath returns the old "source_path" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldSourcePath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSourcePath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSourcePath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSourcePath: %w", err) + } + return oldValue.SourcePath, nil +} + +// ResetSourcePath resets all changes to the "source_path" field. +func (m *TeamDefinitionMutation) ResetSourcePath() { + m.source_path = nil +} + +// SetContentHash sets the "content_hash" field. +func (m *TeamDefinitionMutation) SetContentHash(s string) { + m.content_hash = &s +} + +// ContentHash returns the value of the "content_hash" field in the mutation. +func (m *TeamDefinitionMutation) ContentHash() (r string, exists bool) { + v := m.content_hash + if v == nil { + return + } + return *v, true +} + +// OldContentHash returns the old "content_hash" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldContentHash(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldContentHash is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldContentHash requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldContentHash: %w", err) + } + return oldValue.ContentHash, nil +} + +// ResetContentHash resets all changes to the "content_hash" field. +func (m *TeamDefinitionMutation) ResetContentHash() { + m.content_hash = nil +} + +// SetFirstSeenAt sets the "first_seen_at" field. +func (m *TeamDefinitionMutation) SetFirstSeenAt(t time.Time) { + m.first_seen_at = &t +} + +// FirstSeenAt returns the value of the "first_seen_at" field in the mutation. +func (m *TeamDefinitionMutation) FirstSeenAt() (r time.Time, exists bool) { + v := m.first_seen_at + if v == nil { + return + } + return *v, true +} + +// OldFirstSeenAt returns the old "first_seen_at" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldFirstSeenAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFirstSeenAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFirstSeenAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFirstSeenAt: %w", err) + } + return oldValue.FirstSeenAt, nil +} + +// ResetFirstSeenAt resets all changes to the "first_seen_at" field. +func (m *TeamDefinitionMutation) ResetFirstSeenAt() { + m.first_seen_at = nil +} + +// SetLastSeenAt sets the "last_seen_at" field. +func (m *TeamDefinitionMutation) SetLastSeenAt(t time.Time) { + m.last_seen_at = &t +} + +// LastSeenAt returns the value of the "last_seen_at" field in the mutation. +func (m *TeamDefinitionMutation) LastSeenAt() (r time.Time, exists bool) { + v := m.last_seen_at + if v == nil { + return + } + return *v, true +} + +// OldLastSeenAt returns the old "last_seen_at" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldLastSeenAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLastSeenAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLastSeenAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLastSeenAt: %w", err) + } + return oldValue.LastSeenAt, nil +} + +// ResetLastSeenAt resets all changes to the "last_seen_at" field. +func (m *TeamDefinitionMutation) ResetLastSeenAt() { + m.last_seen_at = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *TeamDefinitionMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *TeamDefinitionMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *TeamDefinitionMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *TeamDefinitionMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *TeamDefinitionMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the TeamDefinition entity. +// If the TeamDefinition 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 *TeamDefinitionMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *TeamDefinitionMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// AddAgentIDs adds the "agents" edge to the AgentDefinition entity by ids. +func (m *TeamDefinitionMutation) AddAgentIDs(ids ...uuid.UUID) { + if m.agents == nil { + m.agents = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.agents[ids[i]] = struct{}{} + } +} + +// ClearAgents clears the "agents" edge to the AgentDefinition entity. +func (m *TeamDefinitionMutation) ClearAgents() { + m.clearedagents = true +} + +// AgentsCleared reports if the "agents" edge to the AgentDefinition entity was cleared. +func (m *TeamDefinitionMutation) AgentsCleared() bool { + return m.clearedagents +} + +// RemoveAgentIDs removes the "agents" edge to the AgentDefinition entity by IDs. +func (m *TeamDefinitionMutation) RemoveAgentIDs(ids ...uuid.UUID) { + if m.removedagents == nil { + m.removedagents = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.agents, ids[i]) + m.removedagents[ids[i]] = struct{}{} + } +} + +// RemovedAgents returns the removed IDs of the "agents" edge to the AgentDefinition entity. +func (m *TeamDefinitionMutation) RemovedAgentsIDs() (ids []uuid.UUID) { + for id := range m.removedagents { + ids = append(ids, id) + } + return +} + +// AgentsIDs returns the "agents" edge IDs in the mutation. +func (m *TeamDefinitionMutation) AgentsIDs() (ids []uuid.UUID) { + for id := range m.agents { + ids = append(ids, id) + } + return +} + +// ResetAgents resets all changes to the "agents" edge. +func (m *TeamDefinitionMutation) ResetAgents() { + m.agents = nil + m.clearedagents = false + m.removedagents = nil +} + +// Where appends a list predicates to the TeamDefinitionMutation builder. +func (m *TeamDefinitionMutation) Where(ps ...predicate.TeamDefinition) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the TeamDefinitionMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *TeamDefinitionMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.TeamDefinition, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *TeamDefinitionMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *TeamDefinitionMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (TeamDefinition). +func (m *TeamDefinitionMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *TeamDefinitionMutation) Fields() []string { + fields := make([]string, 0, 14) + if m.repo_name != nil { + fields = append(fields, teamdefinition.FieldRepoName) + } + if m.name != nil { + fields = append(fields, teamdefinition.FieldName) + } + if m.source_ref != nil { + fields = append(fields, teamdefinition.FieldSourceRef) + } + if m.registry_xrn != nil { + fields = append(fields, teamdefinition.FieldRegistryXrn) + } + if m.version != nil { + fields = append(fields, teamdefinition.FieldVersion) + } + if m.description != nil { + fields = append(fields, teamdefinition.FieldDescription) + } + if m.orchestrator != nil { + fields = append(fields, teamdefinition.FieldOrchestrator) + } + if m.agent_names != nil { + fields = append(fields, teamdefinition.FieldAgentNames) + } + if m.source_path != nil { + fields = append(fields, teamdefinition.FieldSourcePath) + } + if m.content_hash != nil { + fields = append(fields, teamdefinition.FieldContentHash) + } + if m.first_seen_at != nil { + fields = append(fields, teamdefinition.FieldFirstSeenAt) + } + if m.last_seen_at != nil { + fields = append(fields, teamdefinition.FieldLastSeenAt) + } + if m.created_at != nil { + fields = append(fields, teamdefinition.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, teamdefinition.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *TeamDefinitionMutation) Field(name string) (ent.Value, bool) { + switch name { + case teamdefinition.FieldRepoName: + return m.RepoName() + case teamdefinition.FieldName: + return m.Name() + case teamdefinition.FieldSourceRef: + return m.SourceRef() + case teamdefinition.FieldRegistryXrn: + return m.RegistryXrn() + case teamdefinition.FieldVersion: + return m.Version() + case teamdefinition.FieldDescription: + return m.Description() + case teamdefinition.FieldOrchestrator: + return m.Orchestrator() + case teamdefinition.FieldAgentNames: + return m.AgentNames() + case teamdefinition.FieldSourcePath: + return m.SourcePath() + case teamdefinition.FieldContentHash: + return m.ContentHash() + case teamdefinition.FieldFirstSeenAt: + return m.FirstSeenAt() + case teamdefinition.FieldLastSeenAt: + return m.LastSeenAt() + case teamdefinition.FieldCreatedAt: + return m.CreatedAt() + case teamdefinition.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *TeamDefinitionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case teamdefinition.FieldRepoName: + return m.OldRepoName(ctx) + case teamdefinition.FieldName: + return m.OldName(ctx) + case teamdefinition.FieldSourceRef: + return m.OldSourceRef(ctx) + case teamdefinition.FieldRegistryXrn: + return m.OldRegistryXrn(ctx) + case teamdefinition.FieldVersion: + return m.OldVersion(ctx) + case teamdefinition.FieldDescription: + return m.OldDescription(ctx) + case teamdefinition.FieldOrchestrator: + return m.OldOrchestrator(ctx) + case teamdefinition.FieldAgentNames: + return m.OldAgentNames(ctx) + case teamdefinition.FieldSourcePath: + return m.OldSourcePath(ctx) + case teamdefinition.FieldContentHash: + return m.OldContentHash(ctx) + case teamdefinition.FieldFirstSeenAt: + return m.OldFirstSeenAt(ctx) + case teamdefinition.FieldLastSeenAt: + return m.OldLastSeenAt(ctx) + case teamdefinition.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case teamdefinition.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown TeamDefinition field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TeamDefinitionMutation) SetField(name string, value ent.Value) error { + switch name { + case teamdefinition.FieldRepoName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRepoName(v) + return nil + case teamdefinition.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case teamdefinition.FieldSourceRef: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSourceRef(v) + return nil + case teamdefinition.FieldRegistryXrn: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRegistryXrn(v) + return nil + case teamdefinition.FieldVersion: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetVersion(v) + return nil + case teamdefinition.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case teamdefinition.FieldOrchestrator: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOrchestrator(v) + return nil + case teamdefinition.FieldAgentNames: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAgentNames(v) + return nil + case teamdefinition.FieldSourcePath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSourcePath(v) + return nil + case teamdefinition.FieldContentHash: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetContentHash(v) + return nil + case teamdefinition.FieldFirstSeenAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFirstSeenAt(v) + return nil + case teamdefinition.FieldLastSeenAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLastSeenAt(v) + return nil + case teamdefinition.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case teamdefinition.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown TeamDefinition field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *TeamDefinitionMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *TeamDefinitionMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TeamDefinitionMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown TeamDefinition numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *TeamDefinitionMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(teamdefinition.FieldSourceRef) { + fields = append(fields, teamdefinition.FieldSourceRef) + } + if m.FieldCleared(teamdefinition.FieldRegistryXrn) { + fields = append(fields, teamdefinition.FieldRegistryXrn) + } + if m.FieldCleared(teamdefinition.FieldVersion) { + fields = append(fields, teamdefinition.FieldVersion) + } + if m.FieldCleared(teamdefinition.FieldDescription) { + fields = append(fields, teamdefinition.FieldDescription) + } + if m.FieldCleared(teamdefinition.FieldOrchestrator) { + fields = append(fields, teamdefinition.FieldOrchestrator) + } + if m.FieldCleared(teamdefinition.FieldAgentNames) { + fields = append(fields, teamdefinition.FieldAgentNames) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *TeamDefinitionMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *TeamDefinitionMutation) ClearField(name string) error { + switch name { + case teamdefinition.FieldSourceRef: + m.ClearSourceRef() + return nil + case teamdefinition.FieldRegistryXrn: + m.ClearRegistryXrn() + return nil + case teamdefinition.FieldVersion: + m.ClearVersion() + return nil + case teamdefinition.FieldDescription: + m.ClearDescription() + return nil + case teamdefinition.FieldOrchestrator: + m.ClearOrchestrator() + return nil + case teamdefinition.FieldAgentNames: + m.ClearAgentNames() + return nil + } + return fmt.Errorf("unknown TeamDefinition nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *TeamDefinitionMutation) ResetField(name string) error { + switch name { + case teamdefinition.FieldRepoName: + m.ResetRepoName() + return nil + case teamdefinition.FieldName: + m.ResetName() + return nil + case teamdefinition.FieldSourceRef: + m.ResetSourceRef() + return nil + case teamdefinition.FieldRegistryXrn: + m.ResetRegistryXrn() + return nil + case teamdefinition.FieldVersion: + m.ResetVersion() + return nil + case teamdefinition.FieldDescription: + m.ResetDescription() + return nil + case teamdefinition.FieldOrchestrator: + m.ResetOrchestrator() + return nil + case teamdefinition.FieldAgentNames: + m.ResetAgentNames() + return nil + case teamdefinition.FieldSourcePath: + m.ResetSourcePath() + return nil + case teamdefinition.FieldContentHash: + m.ResetContentHash() + return nil + case teamdefinition.FieldFirstSeenAt: + m.ResetFirstSeenAt() + return nil + case teamdefinition.FieldLastSeenAt: + m.ResetLastSeenAt() + return nil + case teamdefinition.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case teamdefinition.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown TeamDefinition field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *TeamDefinitionMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.agents != nil { + edges = append(edges, teamdefinition.EdgeAgents) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *TeamDefinitionMutation) AddedIDs(name string) []ent.Value { + switch name { + case teamdefinition.EdgeAgents: + ids := make([]ent.Value, 0, len(m.agents)) + for id := range m.agents { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *TeamDefinitionMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + if m.removedagents != nil { + edges = append(edges, teamdefinition.EdgeAgents) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *TeamDefinitionMutation) RemovedIDs(name string) []ent.Value { + switch name { + case teamdefinition.EdgeAgents: + ids := make([]ent.Value, 0, len(m.removedagents)) + for id := range m.removedagents { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *TeamDefinitionMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedagents { + edges = append(edges, teamdefinition.EdgeAgents) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *TeamDefinitionMutation) EdgeCleared(name string) bool { + switch name { + case teamdefinition.EdgeAgents: + return m.clearedagents + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *TeamDefinitionMutation) ClearEdge(name string) error { + switch name { + } + return fmt.Errorf("unknown TeamDefinition unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *TeamDefinitionMutation) ResetEdge(name string) error { + switch name { + case teamdefinition.EdgeAgents: + m.ResetAgents() + return nil + } + return fmt.Errorf("unknown TeamDefinition edge %s", name) +} + // ViewMutation represents an operation that mutates the View nodes in the graph. type ViewMutation struct { config diff --git a/internal/ent/predicate/predicate.go b/internal/ent/predicate/predicate.go index 83ae674..32fb240 100644 --- a/internal/ent/predicate/predicate.go +++ b/internal/ent/predicate/predicate.go @@ -6,5 +6,11 @@ import ( "entgo.io/ent/dialect/sql" ) +// AgentDefinition is the predicate function for agentdefinition builders. +type AgentDefinition func(*sql.Selector) + +// TeamDefinition is the predicate function for teamdefinition builders. +type TeamDefinition func(*sql.Selector) + // View is the predicate function for view builders. type View func(*sql.Selector) diff --git a/internal/ent/runtime.go b/internal/ent/runtime.go index bbd4edb..910f8a7 100644 --- a/internal/ent/runtime.go +++ b/internal/ent/runtime.go @@ -5,15 +5,105 @@ package ent import ( "time" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" "github.com/plexusone/agentplexus/internal/ent/schema" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" "github.com/plexusone/agentplexus/internal/ent/view" - "github.com/google/uuid" ) // The init function reads all schema descriptors with runtime code // (default values, validators, hooks and policies) and stitches it // to their package variables. func init() { + agentdefinitionFields := schema.AgentDefinition{}.Fields() + _ = agentdefinitionFields + // agentdefinitionDescRepoName is the schema descriptor for repo_name field. + agentdefinitionDescRepoName := agentdefinitionFields[1].Descriptor() + // agentdefinition.RepoNameValidator is a validator for the "repo_name" field. It is called by the builders before save. + agentdefinition.RepoNameValidator = agentdefinitionDescRepoName.Validators[0].(func(string) error) + // agentdefinitionDescNamespace is the schema descriptor for namespace field. + agentdefinitionDescNamespace := agentdefinitionFields[2].Descriptor() + // agentdefinition.DefaultNamespace holds the default value on creation for the namespace field. + agentdefinition.DefaultNamespace = agentdefinitionDescNamespace.Default.(string) + // agentdefinitionDescName is the schema descriptor for name field. + agentdefinitionDescName := agentdefinitionFields[3].Descriptor() + // agentdefinition.NameValidator is a validator for the "name" field. It is called by the builders before save. + agentdefinition.NameValidator = agentdefinitionDescName.Validators[0].(func(string) error) + // agentdefinitionDescQualifiedName is the schema descriptor for qualified_name field. + agentdefinitionDescQualifiedName := agentdefinitionFields[4].Descriptor() + // agentdefinition.QualifiedNameValidator is a validator for the "qualified_name" field. It is called by the builders before save. + agentdefinition.QualifiedNameValidator = agentdefinitionDescQualifiedName.Validators[0].(func(string) error) + // agentdefinitionDescSourcePath is the schema descriptor for source_path field. + agentdefinitionDescSourcePath := agentdefinitionFields[16].Descriptor() + // agentdefinition.SourcePathValidator is a validator for the "source_path" field. It is called by the builders before save. + agentdefinition.SourcePathValidator = agentdefinitionDescSourcePath.Validators[0].(func(string) error) + // agentdefinitionDescContentHash is the schema descriptor for content_hash field. + agentdefinitionDescContentHash := agentdefinitionFields[17].Descriptor() + // agentdefinition.ContentHashValidator is a validator for the "content_hash" field. It is called by the builders before save. + agentdefinition.ContentHashValidator = agentdefinitionDescContentHash.Validators[0].(func(string) error) + // agentdefinitionDescFirstSeenAt is the schema descriptor for first_seen_at field. + agentdefinitionDescFirstSeenAt := agentdefinitionFields[18].Descriptor() + // agentdefinition.DefaultFirstSeenAt holds the default value on creation for the first_seen_at field. + agentdefinition.DefaultFirstSeenAt = agentdefinitionDescFirstSeenAt.Default.(func() time.Time) + // agentdefinitionDescLastSeenAt is the schema descriptor for last_seen_at field. + agentdefinitionDescLastSeenAt := agentdefinitionFields[19].Descriptor() + // agentdefinition.DefaultLastSeenAt holds the default value on creation for the last_seen_at field. + agentdefinition.DefaultLastSeenAt = agentdefinitionDescLastSeenAt.Default.(func() time.Time) + // agentdefinitionDescCreatedAt is the schema descriptor for created_at field. + agentdefinitionDescCreatedAt := agentdefinitionFields[20].Descriptor() + // agentdefinition.DefaultCreatedAt holds the default value on creation for the created_at field. + agentdefinition.DefaultCreatedAt = agentdefinitionDescCreatedAt.Default.(func() time.Time) + // agentdefinitionDescUpdatedAt is the schema descriptor for updated_at field. + agentdefinitionDescUpdatedAt := agentdefinitionFields[21].Descriptor() + // agentdefinition.DefaultUpdatedAt holds the default value on creation for the updated_at field. + agentdefinition.DefaultUpdatedAt = agentdefinitionDescUpdatedAt.Default.(func() time.Time) + // agentdefinition.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + agentdefinition.UpdateDefaultUpdatedAt = agentdefinitionDescUpdatedAt.UpdateDefault.(func() time.Time) + // agentdefinitionDescID is the schema descriptor for id field. + agentdefinitionDescID := agentdefinitionFields[0].Descriptor() + // agentdefinition.DefaultID holds the default value on creation for the id field. + agentdefinition.DefaultID = agentdefinitionDescID.Default.(func() uuid.UUID) + teamdefinitionFields := schema.TeamDefinition{}.Fields() + _ = teamdefinitionFields + // teamdefinitionDescRepoName is the schema descriptor for repo_name field. + teamdefinitionDescRepoName := teamdefinitionFields[1].Descriptor() + // teamdefinition.RepoNameValidator is a validator for the "repo_name" field. It is called by the builders before save. + teamdefinition.RepoNameValidator = teamdefinitionDescRepoName.Validators[0].(func(string) error) + // teamdefinitionDescName is the schema descriptor for name field. + teamdefinitionDescName := teamdefinitionFields[2].Descriptor() + // teamdefinition.NameValidator is a validator for the "name" field. It is called by the builders before save. + teamdefinition.NameValidator = teamdefinitionDescName.Validators[0].(func(string) error) + // teamdefinitionDescSourcePath is the schema descriptor for source_path field. + teamdefinitionDescSourcePath := teamdefinitionFields[9].Descriptor() + // teamdefinition.SourcePathValidator is a validator for the "source_path" field. It is called by the builders before save. + teamdefinition.SourcePathValidator = teamdefinitionDescSourcePath.Validators[0].(func(string) error) + // teamdefinitionDescContentHash is the schema descriptor for content_hash field. + teamdefinitionDescContentHash := teamdefinitionFields[10].Descriptor() + // teamdefinition.ContentHashValidator is a validator for the "content_hash" field. It is called by the builders before save. + teamdefinition.ContentHashValidator = teamdefinitionDescContentHash.Validators[0].(func(string) error) + // teamdefinitionDescFirstSeenAt is the schema descriptor for first_seen_at field. + teamdefinitionDescFirstSeenAt := teamdefinitionFields[11].Descriptor() + // teamdefinition.DefaultFirstSeenAt holds the default value on creation for the first_seen_at field. + teamdefinition.DefaultFirstSeenAt = teamdefinitionDescFirstSeenAt.Default.(func() time.Time) + // teamdefinitionDescLastSeenAt is the schema descriptor for last_seen_at field. + teamdefinitionDescLastSeenAt := teamdefinitionFields[12].Descriptor() + // teamdefinition.DefaultLastSeenAt holds the default value on creation for the last_seen_at field. + teamdefinition.DefaultLastSeenAt = teamdefinitionDescLastSeenAt.Default.(func() time.Time) + // teamdefinitionDescCreatedAt is the schema descriptor for created_at field. + teamdefinitionDescCreatedAt := teamdefinitionFields[13].Descriptor() + // teamdefinition.DefaultCreatedAt holds the default value on creation for the created_at field. + teamdefinition.DefaultCreatedAt = teamdefinitionDescCreatedAt.Default.(func() time.Time) + // teamdefinitionDescUpdatedAt is the schema descriptor for updated_at field. + teamdefinitionDescUpdatedAt := teamdefinitionFields[14].Descriptor() + // teamdefinition.DefaultUpdatedAt holds the default value on creation for the updated_at field. + teamdefinition.DefaultUpdatedAt = teamdefinitionDescUpdatedAt.Default.(func() time.Time) + // teamdefinition.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + teamdefinition.UpdateDefaultUpdatedAt = teamdefinitionDescUpdatedAt.UpdateDefault.(func() time.Time) + // teamdefinitionDescID is the schema descriptor for id field. + teamdefinitionDescID := teamdefinitionFields[0].Descriptor() + // teamdefinition.DefaultID holds the default value on creation for the id field. + teamdefinition.DefaultID = teamdefinitionDescID.Default.(func() uuid.UUID) viewFields := schema.View{}.Fields() _ = viewFields // viewDescName is the schema descriptor for name field. diff --git a/internal/ent/runtime/runtime.go b/internal/ent/runtime/runtime.go index 0eaae93..c9f6de0 100644 --- a/internal/ent/runtime/runtime.go +++ b/internal/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in github.com/plexusone/agentplexus/internal/ent/runtime.go const ( - Version = "v0.14.5" // Version of ent codegen. - Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen. + Version = "v0.14.6" // Version of ent codegen. + Sum = "h1:/f2696BpwuWAEEG6PVGWflg6+Inrpq4pRWuNlWz/Skk=" // Sum of ent codegen. ) diff --git a/internal/ent/schema/agent.go b/internal/ent/schema/agent.go new file mode 100644 index 0000000..b7fa403 --- /dev/null +++ b/internal/ent/schema/agent.go @@ -0,0 +1,103 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" + "github.com/google/uuid" +) + +// AgentDefinition holds the schema definition for the agent-definition +// registry entity (the Definition plane of the AgentPlexus control plane). +// +// AgentDefinition records are upserted from multi-agent-spec agent markdown +// files (specs/agents/*.md) discovered across registered repositories. The +// (repo_name, namespace, name) triple is the stable identity key: re-running +// registration updates the existing row instead of creating a duplicate. +type AgentDefinition struct { + ent.Schema +} + +// Fields of the AgentDefinition. +func (AgentDefinition) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}). + Default(uuid.New). + Immutable(), + field.String("repo_name"). + NotEmpty(). + Comment("Owning repository, e.g. agent-team-release"), + field.String("namespace"). + Default(""). + Comment("Subdirectory namespace, if any"), + field.String("name"). + NotEmpty(). + Comment("Agent name from spec frontmatter"), + field.String("qualified_name"). + NotEmpty(). + Comment("repo_name/namespace/name, for display and lookup"), + field.String("source_ref"). + Optional(). + Comment("User-facing Go-style source path, e.g. github.com/plexusone/agent-team-release/agents/release-reviewer"), + field.String("registry_xrn"). + Optional(). + Immutable(). + Unique(). + Comment("Internal registry identity, xrn:agentplexus:agent-definition:"), + field.String("description"). + Optional(), + field.String("model"). + Optional(), + field.String("icon"). + Optional(), + field.String("role"). + Optional(), + field.JSON("tools", []string{}). + Optional(), + field.JSON("allowed_tools", []string{}). + Optional(), + field.JSON("skills", []string{}). + Optional(), + field.JSON("dependencies", []string{}). + Optional(), + field.JSON("requires", []string{}). + Optional(), + field.String("source_path"). + NotEmpty(). + Comment("Absolute path to the agent markdown file"), + field.String("content_hash"). + NotEmpty(). + Comment("sha256 of the source file, for drift detection"), + field.Time("first_seen_at"). + Default(time.Now). + Immutable(), + field.Time("last_seen_at"). + Default(time.Now). + Comment("Updated on every successful registration sync"), + field.Time("created_at"). + Default(time.Now). + Immutable(), + field.Time("updated_at"). + Default(time.Now). + UpdateDefault(time.Now), + } +} + +// Edges of the AgentDefinition. +func (AgentDefinition) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("teams", TeamDefinition.Type). + Ref("agents"), + } +} + +// Indexes of the AgentDefinition. +func (AgentDefinition) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("repo_name", "namespace", "name"). + Unique(), + } +} diff --git a/internal/ent/schema/team.go b/internal/ent/schema/team.go new file mode 100644 index 0000000..76138bb --- /dev/null +++ b/internal/ent/schema/team.go @@ -0,0 +1,87 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" + "github.com/google/uuid" +) + +// TeamDefinition holds the schema definition for the team-definition +// registry entity (the Definition plane of the AgentPlexus control plane). +// +// TeamDefinition records are upserted from multi-agent-spec team JSON files +// (specs/teams/*.json) discovered across registered repositories. The +// (repo_name, name) pair is the stable identity key. +type TeamDefinition struct { + ent.Schema +} + +// Fields of the TeamDefinition. +func (TeamDefinition) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}). + Default(uuid.New). + Immutable(), + field.String("repo_name"). + NotEmpty(). + Comment("Owning repository, e.g. agent-team-release"), + field.String("name"). + NotEmpty(). + Comment("Team name from spec"), + field.String("source_ref"). + Optional(). + Comment("User-facing Go-style source path, e.g. github.com/plexusone/agent-team-release/teams/release"), + field.String("registry_xrn"). + Optional(). + Immutable(). + Unique(). + Comment("Internal registry identity, xrn:agentplexus:team-definition:"), + field.String("version"). + Optional(), + field.String("description"). + Optional(), + field.String("orchestrator"). + Optional(). + Comment("Agent name that orchestrates this team's workflow"), + field.JSON("agent_names", []string{}). + Optional(). + Comment("Agent names referenced by the team spec, in spec order"), + field.String("source_path"). + NotEmpty(). + Comment("Absolute path to the team JSON file"), + field.String("content_hash"). + NotEmpty(). + Comment("sha256 of the source file, for drift detection"), + field.Time("first_seen_at"). + Default(time.Now). + Immutable(), + field.Time("last_seen_at"). + Default(time.Now). + Comment("Updated on every successful registration sync"), + field.Time("created_at"). + Default(time.Now). + Immutable(), + field.Time("updated_at"). + Default(time.Now). + UpdateDefault(time.Now), + } +} + +// Edges of the TeamDefinition. +func (TeamDefinition) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("agents", AgentDefinition.Type), + } +} + +// Indexes of the TeamDefinition. +func (TeamDefinition) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("repo_name", "name"). + Unique(), + } +} diff --git a/internal/ent/teamdefinition.go b/internal/ent/teamdefinition.go new file mode 100644 index 0000000..3be7ca9 --- /dev/null +++ b/internal/ent/teamdefinition.go @@ -0,0 +1,281 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// TeamDefinition is the model entity for the TeamDefinition schema. +type TeamDefinition struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // Owning repository, e.g. agent-team-release + RepoName string `json:"repo_name,omitempty"` + // Team name from spec + Name string `json:"name,omitempty"` + // User-facing Go-style source path, e.g. github.com/plexusone/agent-team-release/teams/release + SourceRef string `json:"source_ref,omitempty"` + // Internal registry identity, xrn:agentplexus:team-definition: + RegistryXrn string `json:"registry_xrn,omitempty"` + // Version holds the value of the "version" field. + Version string `json:"version,omitempty"` + // Description holds the value of the "description" field. + Description string `json:"description,omitempty"` + // Agent name that orchestrates this team's workflow + Orchestrator string `json:"orchestrator,omitempty"` + // Agent names referenced by the team spec, in spec order + AgentNames []string `json:"agent_names,omitempty"` + // Absolute path to the team JSON file + SourcePath string `json:"source_path,omitempty"` + // sha256 of the source file, for drift detection + ContentHash string `json:"content_hash,omitempty"` + // FirstSeenAt holds the value of the "first_seen_at" field. + FirstSeenAt time.Time `json:"first_seen_at,omitempty"` + // Updated on every successful registration sync + LastSeenAt time.Time `json:"last_seen_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 TeamDefinitionQuery when eager-loading is set. + Edges TeamDefinitionEdges `json:"edges"` + selectValues sql.SelectValues +} + +// TeamDefinitionEdges holds the relations/edges for other nodes in the graph. +type TeamDefinitionEdges struct { + // Agents holds the value of the agents edge. + Agents []*AgentDefinition `json:"agents,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// AgentsOrErr returns the Agents value or an error if the edge +// was not loaded in eager-loading. +func (e TeamDefinitionEdges) AgentsOrErr() ([]*AgentDefinition, error) { + if e.loadedTypes[0] { + return e.Agents, nil + } + return nil, &NotLoadedError{edge: "agents"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*TeamDefinition) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case teamdefinition.FieldAgentNames: + values[i] = new([]byte) + case teamdefinition.FieldRepoName, teamdefinition.FieldName, teamdefinition.FieldSourceRef, teamdefinition.FieldRegistryXrn, teamdefinition.FieldVersion, teamdefinition.FieldDescription, teamdefinition.FieldOrchestrator, teamdefinition.FieldSourcePath, teamdefinition.FieldContentHash: + values[i] = new(sql.NullString) + case teamdefinition.FieldFirstSeenAt, teamdefinition.FieldLastSeenAt, teamdefinition.FieldCreatedAt, teamdefinition.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case teamdefinition.FieldID: + 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 TeamDefinition fields. +func (_m *TeamDefinition) 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 teamdefinition.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 teamdefinition.FieldRepoName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field repo_name", values[i]) + } else if value.Valid { + _m.RepoName = value.String + } + case teamdefinition.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case teamdefinition.FieldSourceRef: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field source_ref", values[i]) + } else if value.Valid { + _m.SourceRef = value.String + } + case teamdefinition.FieldRegistryXrn: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field registry_xrn", values[i]) + } else if value.Valid { + _m.RegistryXrn = value.String + } + case teamdefinition.FieldVersion: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field version", values[i]) + } else if value.Valid { + _m.Version = value.String + } + case teamdefinition.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + _m.Description = value.String + } + case teamdefinition.FieldOrchestrator: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field orchestrator", values[i]) + } else if value.Valid { + _m.Orchestrator = value.String + } + case teamdefinition.FieldAgentNames: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field agent_names", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.AgentNames); err != nil { + return fmt.Errorf("unmarshal field agent_names: %w", err) + } + } + case teamdefinition.FieldSourcePath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field source_path", values[i]) + } else if value.Valid { + _m.SourcePath = value.String + } + case teamdefinition.FieldContentHash: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field content_hash", values[i]) + } else if value.Valid { + _m.ContentHash = value.String + } + case teamdefinition.FieldFirstSeenAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field first_seen_at", values[i]) + } else if value.Valid { + _m.FirstSeenAt = value.Time + } + case teamdefinition.FieldLastSeenAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field last_seen_at", values[i]) + } else if value.Valid { + _m.LastSeenAt = value.Time + } + case teamdefinition.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 teamdefinition.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 TeamDefinition. +// This includes values selected through modifiers, order, etc. +func (_m *TeamDefinition) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryAgents queries the "agents" edge of the TeamDefinition entity. +func (_m *TeamDefinition) QueryAgents() *AgentDefinitionQuery { + return NewTeamDefinitionClient(_m.config).QueryAgents(_m) +} + +// Update returns a builder for updating this TeamDefinition. +// Note that you need to call TeamDefinition.Unwrap() before calling this method if this TeamDefinition +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *TeamDefinition) Update() *TeamDefinitionUpdateOne { + return NewTeamDefinitionClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the TeamDefinition 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 *TeamDefinition) Unwrap() *TeamDefinition { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: TeamDefinition is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *TeamDefinition) String() string { + var builder strings.Builder + builder.WriteString("TeamDefinition(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("repo_name=") + builder.WriteString(_m.RepoName) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("source_ref=") + builder.WriteString(_m.SourceRef) + builder.WriteString(", ") + builder.WriteString("registry_xrn=") + builder.WriteString(_m.RegistryXrn) + builder.WriteString(", ") + builder.WriteString("version=") + builder.WriteString(_m.Version) + builder.WriteString(", ") + builder.WriteString("description=") + builder.WriteString(_m.Description) + builder.WriteString(", ") + builder.WriteString("orchestrator=") + builder.WriteString(_m.Orchestrator) + builder.WriteString(", ") + builder.WriteString("agent_names=") + builder.WriteString(fmt.Sprintf("%v", _m.AgentNames)) + builder.WriteString(", ") + builder.WriteString("source_path=") + builder.WriteString(_m.SourcePath) + builder.WriteString(", ") + builder.WriteString("content_hash=") + builder.WriteString(_m.ContentHash) + builder.WriteString(", ") + builder.WriteString("first_seen_at=") + builder.WriteString(_m.FirstSeenAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("last_seen_at=") + builder.WriteString(_m.LastSeenAt.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() +} + +// TeamDefinitions is a parsable slice of TeamDefinition. +type TeamDefinitions []*TeamDefinition diff --git a/internal/ent/teamdefinition/teamdefinition.go b/internal/ent/teamdefinition/teamdefinition.go new file mode 100644 index 0000000..74d9534 --- /dev/null +++ b/internal/ent/teamdefinition/teamdefinition.go @@ -0,0 +1,207 @@ +// Code generated by ent, DO NOT EDIT. + +package teamdefinition + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the teamdefinition type in the database. + Label = "team_definition" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldRepoName holds the string denoting the repo_name field in the database. + FieldRepoName = "repo_name" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldSourceRef holds the string denoting the source_ref field in the database. + FieldSourceRef = "source_ref" + // FieldRegistryXrn holds the string denoting the registry_xrn field in the database. + FieldRegistryXrn = "registry_xrn" + // FieldVersion holds the string denoting the version field in the database. + FieldVersion = "version" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // FieldOrchestrator holds the string denoting the orchestrator field in the database. + FieldOrchestrator = "orchestrator" + // FieldAgentNames holds the string denoting the agent_names field in the database. + FieldAgentNames = "agent_names" + // FieldSourcePath holds the string denoting the source_path field in the database. + FieldSourcePath = "source_path" + // FieldContentHash holds the string denoting the content_hash field in the database. + FieldContentHash = "content_hash" + // FieldFirstSeenAt holds the string denoting the first_seen_at field in the database. + FieldFirstSeenAt = "first_seen_at" + // FieldLastSeenAt holds the string denoting the last_seen_at field in the database. + FieldLastSeenAt = "last_seen_at" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // EdgeAgents holds the string denoting the agents edge name in mutations. + EdgeAgents = "agents" + // Table holds the table name of the teamdefinition in the database. + Table = "team_definitions" + // AgentsTable is the table that holds the agents relation/edge. The primary key declared below. + AgentsTable = "team_definition_agents" + // AgentsInverseTable is the table name for the AgentDefinition entity. + // It exists in this package in order to avoid circular dependency with the "agentdefinition" package. + AgentsInverseTable = "agent_definitions" +) + +// Columns holds all SQL columns for teamdefinition fields. +var Columns = []string{ + FieldID, + FieldRepoName, + FieldName, + FieldSourceRef, + FieldRegistryXrn, + FieldVersion, + FieldDescription, + FieldOrchestrator, + FieldAgentNames, + FieldSourcePath, + FieldContentHash, + FieldFirstSeenAt, + FieldLastSeenAt, + FieldCreatedAt, + FieldUpdatedAt, +} + +var ( + // AgentsPrimaryKey and AgentsColumn2 are the table columns denoting the + // primary key for the agents relation (M2M). + AgentsPrimaryKey = []string{"team_definition_id", "agent_definition_id"} +) + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // RepoNameValidator is a validator for the "repo_name" field. It is called by the builders before save. + RepoNameValidator func(string) error + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // SourcePathValidator is a validator for the "source_path" field. It is called by the builders before save. + SourcePathValidator func(string) error + // ContentHashValidator is a validator for the "content_hash" field. It is called by the builders before save. + ContentHashValidator func(string) error + // DefaultFirstSeenAt holds the default value on creation for the "first_seen_at" field. + DefaultFirstSeenAt func() time.Time + // DefaultLastSeenAt holds the default value on creation for the "last_seen_at" field. + DefaultLastSeenAt func() time.Time + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the TeamDefinition queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByRepoName orders the results by the repo_name field. +func ByRepoName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRepoName, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// BySourceRef orders the results by the source_ref field. +func BySourceRef(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSourceRef, opts...).ToFunc() +} + +// ByRegistryXrn orders the results by the registry_xrn field. +func ByRegistryXrn(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRegistryXrn, opts...).ToFunc() +} + +// ByVersion orders the results by the version field. +func ByVersion(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldVersion, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByOrchestrator orders the results by the orchestrator field. +func ByOrchestrator(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldOrchestrator, opts...).ToFunc() +} + +// BySourcePath orders the results by the source_path field. +func BySourcePath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSourcePath, opts...).ToFunc() +} + +// ByContentHash orders the results by the content_hash field. +func ByContentHash(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldContentHash, opts...).ToFunc() +} + +// ByFirstSeenAt orders the results by the first_seen_at field. +func ByFirstSeenAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFirstSeenAt, opts...).ToFunc() +} + +// ByLastSeenAt orders the results by the last_seen_at field. +func ByLastSeenAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLastSeenAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByAgentsCount orders the results by agents count. +func ByAgentsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newAgentsStep(), opts...) + } +} + +// ByAgents orders the results by agents terms. +func ByAgents(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newAgentsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newAgentsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AgentsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, AgentsTable, AgentsPrimaryKey...), + ) +} diff --git a/internal/ent/teamdefinition/where.go b/internal/ent/teamdefinition/where.go new file mode 100644 index 0000000..0bcdd3f --- /dev/null +++ b/internal/ent/teamdefinition/where.go @@ -0,0 +1,965 @@ +// Code generated by ent, DO NOT EDIT. + +package teamdefinition + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldID, id)) +} + +// RepoName applies equality check predicate on the "repo_name" field. It's identical to RepoNameEQ. +func RepoName(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldRepoName, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldName, v)) +} + +// SourceRef applies equality check predicate on the "source_ref" field. It's identical to SourceRefEQ. +func SourceRef(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldSourceRef, v)) +} + +// RegistryXrn applies equality check predicate on the "registry_xrn" field. It's identical to RegistryXrnEQ. +func RegistryXrn(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldRegistryXrn, v)) +} + +// Version applies equality check predicate on the "version" field. It's identical to VersionEQ. +func Version(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldVersion, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldDescription, v)) +} + +// Orchestrator applies equality check predicate on the "orchestrator" field. It's identical to OrchestratorEQ. +func Orchestrator(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldOrchestrator, v)) +} + +// SourcePath applies equality check predicate on the "source_path" field. It's identical to SourcePathEQ. +func SourcePath(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldSourcePath, v)) +} + +// ContentHash applies equality check predicate on the "content_hash" field. It's identical to ContentHashEQ. +func ContentHash(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldContentHash, v)) +} + +// FirstSeenAt applies equality check predicate on the "first_seen_at" field. It's identical to FirstSeenAtEQ. +func FirstSeenAt(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldFirstSeenAt, v)) +} + +// LastSeenAt applies equality check predicate on the "last_seen_at" field. It's identical to LastSeenAtEQ. +func LastSeenAt(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldLastSeenAt, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// RepoNameEQ applies the EQ predicate on the "repo_name" field. +func RepoNameEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldRepoName, v)) +} + +// RepoNameNEQ applies the NEQ predicate on the "repo_name" field. +func RepoNameNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldRepoName, v)) +} + +// RepoNameIn applies the In predicate on the "repo_name" field. +func RepoNameIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldRepoName, vs...)) +} + +// RepoNameNotIn applies the NotIn predicate on the "repo_name" field. +func RepoNameNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldRepoName, vs...)) +} + +// RepoNameGT applies the GT predicate on the "repo_name" field. +func RepoNameGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldRepoName, v)) +} + +// RepoNameGTE applies the GTE predicate on the "repo_name" field. +func RepoNameGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldRepoName, v)) +} + +// RepoNameLT applies the LT predicate on the "repo_name" field. +func RepoNameLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldRepoName, v)) +} + +// RepoNameLTE applies the LTE predicate on the "repo_name" field. +func RepoNameLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldRepoName, v)) +} + +// RepoNameContains applies the Contains predicate on the "repo_name" field. +func RepoNameContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldRepoName, v)) +} + +// RepoNameHasPrefix applies the HasPrefix predicate on the "repo_name" field. +func RepoNameHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldRepoName, v)) +} + +// RepoNameHasSuffix applies the HasSuffix predicate on the "repo_name" field. +func RepoNameHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldRepoName, v)) +} + +// RepoNameEqualFold applies the EqualFold predicate on the "repo_name" field. +func RepoNameEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldRepoName, v)) +} + +// RepoNameContainsFold applies the ContainsFold predicate on the "repo_name" field. +func RepoNameContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldRepoName, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldName, v)) +} + +// SourceRefEQ applies the EQ predicate on the "source_ref" field. +func SourceRefEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldSourceRef, v)) +} + +// SourceRefNEQ applies the NEQ predicate on the "source_ref" field. +func SourceRefNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldSourceRef, v)) +} + +// SourceRefIn applies the In predicate on the "source_ref" field. +func SourceRefIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldSourceRef, vs...)) +} + +// SourceRefNotIn applies the NotIn predicate on the "source_ref" field. +func SourceRefNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldSourceRef, vs...)) +} + +// SourceRefGT applies the GT predicate on the "source_ref" field. +func SourceRefGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldSourceRef, v)) +} + +// SourceRefGTE applies the GTE predicate on the "source_ref" field. +func SourceRefGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldSourceRef, v)) +} + +// SourceRefLT applies the LT predicate on the "source_ref" field. +func SourceRefLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldSourceRef, v)) +} + +// SourceRefLTE applies the LTE predicate on the "source_ref" field. +func SourceRefLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldSourceRef, v)) +} + +// SourceRefContains applies the Contains predicate on the "source_ref" field. +func SourceRefContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldSourceRef, v)) +} + +// SourceRefHasPrefix applies the HasPrefix predicate on the "source_ref" field. +func SourceRefHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldSourceRef, v)) +} + +// SourceRefHasSuffix applies the HasSuffix predicate on the "source_ref" field. +func SourceRefHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldSourceRef, v)) +} + +// SourceRefIsNil applies the IsNil predicate on the "source_ref" field. +func SourceRefIsNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIsNull(FieldSourceRef)) +} + +// SourceRefNotNil applies the NotNil predicate on the "source_ref" field. +func SourceRefNotNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotNull(FieldSourceRef)) +} + +// SourceRefEqualFold applies the EqualFold predicate on the "source_ref" field. +func SourceRefEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldSourceRef, v)) +} + +// SourceRefContainsFold applies the ContainsFold predicate on the "source_ref" field. +func SourceRefContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldSourceRef, v)) +} + +// RegistryXrnEQ applies the EQ predicate on the "registry_xrn" field. +func RegistryXrnEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldRegistryXrn, v)) +} + +// RegistryXrnNEQ applies the NEQ predicate on the "registry_xrn" field. +func RegistryXrnNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldRegistryXrn, v)) +} + +// RegistryXrnIn applies the In predicate on the "registry_xrn" field. +func RegistryXrnIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldRegistryXrn, vs...)) +} + +// RegistryXrnNotIn applies the NotIn predicate on the "registry_xrn" field. +func RegistryXrnNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldRegistryXrn, vs...)) +} + +// RegistryXrnGT applies the GT predicate on the "registry_xrn" field. +func RegistryXrnGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldRegistryXrn, v)) +} + +// RegistryXrnGTE applies the GTE predicate on the "registry_xrn" field. +func RegistryXrnGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldRegistryXrn, v)) +} + +// RegistryXrnLT applies the LT predicate on the "registry_xrn" field. +func RegistryXrnLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldRegistryXrn, v)) +} + +// RegistryXrnLTE applies the LTE predicate on the "registry_xrn" field. +func RegistryXrnLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldRegistryXrn, v)) +} + +// RegistryXrnContains applies the Contains predicate on the "registry_xrn" field. +func RegistryXrnContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldRegistryXrn, v)) +} + +// RegistryXrnHasPrefix applies the HasPrefix predicate on the "registry_xrn" field. +func RegistryXrnHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldRegistryXrn, v)) +} + +// RegistryXrnHasSuffix applies the HasSuffix predicate on the "registry_xrn" field. +func RegistryXrnHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldRegistryXrn, v)) +} + +// RegistryXrnIsNil applies the IsNil predicate on the "registry_xrn" field. +func RegistryXrnIsNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIsNull(FieldRegistryXrn)) +} + +// RegistryXrnNotNil applies the NotNil predicate on the "registry_xrn" field. +func RegistryXrnNotNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotNull(FieldRegistryXrn)) +} + +// RegistryXrnEqualFold applies the EqualFold predicate on the "registry_xrn" field. +func RegistryXrnEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldRegistryXrn, v)) +} + +// RegistryXrnContainsFold applies the ContainsFold predicate on the "registry_xrn" field. +func RegistryXrnContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldRegistryXrn, v)) +} + +// VersionEQ applies the EQ predicate on the "version" field. +func VersionEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldVersion, v)) +} + +// VersionNEQ applies the NEQ predicate on the "version" field. +func VersionNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldVersion, v)) +} + +// VersionIn applies the In predicate on the "version" field. +func VersionIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldVersion, vs...)) +} + +// VersionNotIn applies the NotIn predicate on the "version" field. +func VersionNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldVersion, vs...)) +} + +// VersionGT applies the GT predicate on the "version" field. +func VersionGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldVersion, v)) +} + +// VersionGTE applies the GTE predicate on the "version" field. +func VersionGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldVersion, v)) +} + +// VersionLT applies the LT predicate on the "version" field. +func VersionLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldVersion, v)) +} + +// VersionLTE applies the LTE predicate on the "version" field. +func VersionLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldVersion, v)) +} + +// VersionContains applies the Contains predicate on the "version" field. +func VersionContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldVersion, v)) +} + +// VersionHasPrefix applies the HasPrefix predicate on the "version" field. +func VersionHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldVersion, v)) +} + +// VersionHasSuffix applies the HasSuffix predicate on the "version" field. +func VersionHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldVersion, v)) +} + +// VersionIsNil applies the IsNil predicate on the "version" field. +func VersionIsNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIsNull(FieldVersion)) +} + +// VersionNotNil applies the NotNil predicate on the "version" field. +func VersionNotNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotNull(FieldVersion)) +} + +// VersionEqualFold applies the EqualFold predicate on the "version" field. +func VersionEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldVersion, v)) +} + +// VersionContainsFold applies the ContainsFold predicate on the "version" field. +func VersionContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldVersion, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldDescription, v)) +} + +// OrchestratorEQ applies the EQ predicate on the "orchestrator" field. +func OrchestratorEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldOrchestrator, v)) +} + +// OrchestratorNEQ applies the NEQ predicate on the "orchestrator" field. +func OrchestratorNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldOrchestrator, v)) +} + +// OrchestratorIn applies the In predicate on the "orchestrator" field. +func OrchestratorIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldOrchestrator, vs...)) +} + +// OrchestratorNotIn applies the NotIn predicate on the "orchestrator" field. +func OrchestratorNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldOrchestrator, vs...)) +} + +// OrchestratorGT applies the GT predicate on the "orchestrator" field. +func OrchestratorGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldOrchestrator, v)) +} + +// OrchestratorGTE applies the GTE predicate on the "orchestrator" field. +func OrchestratorGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldOrchestrator, v)) +} + +// OrchestratorLT applies the LT predicate on the "orchestrator" field. +func OrchestratorLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldOrchestrator, v)) +} + +// OrchestratorLTE applies the LTE predicate on the "orchestrator" field. +func OrchestratorLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldOrchestrator, v)) +} + +// OrchestratorContains applies the Contains predicate on the "orchestrator" field. +func OrchestratorContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldOrchestrator, v)) +} + +// OrchestratorHasPrefix applies the HasPrefix predicate on the "orchestrator" field. +func OrchestratorHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldOrchestrator, v)) +} + +// OrchestratorHasSuffix applies the HasSuffix predicate on the "orchestrator" field. +func OrchestratorHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldOrchestrator, v)) +} + +// OrchestratorIsNil applies the IsNil predicate on the "orchestrator" field. +func OrchestratorIsNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIsNull(FieldOrchestrator)) +} + +// OrchestratorNotNil applies the NotNil predicate on the "orchestrator" field. +func OrchestratorNotNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotNull(FieldOrchestrator)) +} + +// OrchestratorEqualFold applies the EqualFold predicate on the "orchestrator" field. +func OrchestratorEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldOrchestrator, v)) +} + +// OrchestratorContainsFold applies the ContainsFold predicate on the "orchestrator" field. +func OrchestratorContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldOrchestrator, v)) +} + +// AgentNamesIsNil applies the IsNil predicate on the "agent_names" field. +func AgentNamesIsNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIsNull(FieldAgentNames)) +} + +// AgentNamesNotNil applies the NotNil predicate on the "agent_names" field. +func AgentNamesNotNil() predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotNull(FieldAgentNames)) +} + +// SourcePathEQ applies the EQ predicate on the "source_path" field. +func SourcePathEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldSourcePath, v)) +} + +// SourcePathNEQ applies the NEQ predicate on the "source_path" field. +func SourcePathNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldSourcePath, v)) +} + +// SourcePathIn applies the In predicate on the "source_path" field. +func SourcePathIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldSourcePath, vs...)) +} + +// SourcePathNotIn applies the NotIn predicate on the "source_path" field. +func SourcePathNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldSourcePath, vs...)) +} + +// SourcePathGT applies the GT predicate on the "source_path" field. +func SourcePathGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldSourcePath, v)) +} + +// SourcePathGTE applies the GTE predicate on the "source_path" field. +func SourcePathGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldSourcePath, v)) +} + +// SourcePathLT applies the LT predicate on the "source_path" field. +func SourcePathLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldSourcePath, v)) +} + +// SourcePathLTE applies the LTE predicate on the "source_path" field. +func SourcePathLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldSourcePath, v)) +} + +// SourcePathContains applies the Contains predicate on the "source_path" field. +func SourcePathContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldSourcePath, v)) +} + +// SourcePathHasPrefix applies the HasPrefix predicate on the "source_path" field. +func SourcePathHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldSourcePath, v)) +} + +// SourcePathHasSuffix applies the HasSuffix predicate on the "source_path" field. +func SourcePathHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldSourcePath, v)) +} + +// SourcePathEqualFold applies the EqualFold predicate on the "source_path" field. +func SourcePathEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldSourcePath, v)) +} + +// SourcePathContainsFold applies the ContainsFold predicate on the "source_path" field. +func SourcePathContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldSourcePath, v)) +} + +// ContentHashEQ applies the EQ predicate on the "content_hash" field. +func ContentHashEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldContentHash, v)) +} + +// ContentHashNEQ applies the NEQ predicate on the "content_hash" field. +func ContentHashNEQ(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldContentHash, v)) +} + +// ContentHashIn applies the In predicate on the "content_hash" field. +func ContentHashIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldContentHash, vs...)) +} + +// ContentHashNotIn applies the NotIn predicate on the "content_hash" field. +func ContentHashNotIn(vs ...string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldContentHash, vs...)) +} + +// ContentHashGT applies the GT predicate on the "content_hash" field. +func ContentHashGT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldContentHash, v)) +} + +// ContentHashGTE applies the GTE predicate on the "content_hash" field. +func ContentHashGTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldContentHash, v)) +} + +// ContentHashLT applies the LT predicate on the "content_hash" field. +func ContentHashLT(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldContentHash, v)) +} + +// ContentHashLTE applies the LTE predicate on the "content_hash" field. +func ContentHashLTE(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldContentHash, v)) +} + +// ContentHashContains applies the Contains predicate on the "content_hash" field. +func ContentHashContains(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContains(FieldContentHash, v)) +} + +// ContentHashHasPrefix applies the HasPrefix predicate on the "content_hash" field. +func ContentHashHasPrefix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasPrefix(FieldContentHash, v)) +} + +// ContentHashHasSuffix applies the HasSuffix predicate on the "content_hash" field. +func ContentHashHasSuffix(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldHasSuffix(FieldContentHash, v)) +} + +// ContentHashEqualFold applies the EqualFold predicate on the "content_hash" field. +func ContentHashEqualFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEqualFold(FieldContentHash, v)) +} + +// ContentHashContainsFold applies the ContainsFold predicate on the "content_hash" field. +func ContentHashContainsFold(v string) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldContainsFold(FieldContentHash, v)) +} + +// FirstSeenAtEQ applies the EQ predicate on the "first_seen_at" field. +func FirstSeenAtEQ(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldFirstSeenAt, v)) +} + +// FirstSeenAtNEQ applies the NEQ predicate on the "first_seen_at" field. +func FirstSeenAtNEQ(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldFirstSeenAt, v)) +} + +// FirstSeenAtIn applies the In predicate on the "first_seen_at" field. +func FirstSeenAtIn(vs ...time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldFirstSeenAt, vs...)) +} + +// FirstSeenAtNotIn applies the NotIn predicate on the "first_seen_at" field. +func FirstSeenAtNotIn(vs ...time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldFirstSeenAt, vs...)) +} + +// FirstSeenAtGT applies the GT predicate on the "first_seen_at" field. +func FirstSeenAtGT(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldFirstSeenAt, v)) +} + +// FirstSeenAtGTE applies the GTE predicate on the "first_seen_at" field. +func FirstSeenAtGTE(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldFirstSeenAt, v)) +} + +// FirstSeenAtLT applies the LT predicate on the "first_seen_at" field. +func FirstSeenAtLT(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldFirstSeenAt, v)) +} + +// FirstSeenAtLTE applies the LTE predicate on the "first_seen_at" field. +func FirstSeenAtLTE(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldFirstSeenAt, v)) +} + +// LastSeenAtEQ applies the EQ predicate on the "last_seen_at" field. +func LastSeenAtEQ(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldLastSeenAt, v)) +} + +// LastSeenAtNEQ applies the NEQ predicate on the "last_seen_at" field. +func LastSeenAtNEQ(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldLastSeenAt, v)) +} + +// LastSeenAtIn applies the In predicate on the "last_seen_at" field. +func LastSeenAtIn(vs ...time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldLastSeenAt, vs...)) +} + +// LastSeenAtNotIn applies the NotIn predicate on the "last_seen_at" field. +func LastSeenAtNotIn(vs ...time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldLastSeenAt, vs...)) +} + +// LastSeenAtGT applies the GT predicate on the "last_seen_at" field. +func LastSeenAtGT(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldLastSeenAt, v)) +} + +// LastSeenAtGTE applies the GTE predicate on the "last_seen_at" field. +func LastSeenAtGTE(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldLastSeenAt, v)) +} + +// LastSeenAtLT applies the LT predicate on the "last_seen_at" field. +func LastSeenAtLT(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldLastSeenAt, v)) +} + +// LastSeenAtLTE applies the LTE predicate on the "last_seen_at" field. +func LastSeenAtLTE(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldLastSeenAt, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// HasAgents applies the HasEdge predicate on the "agents" edge. +func HasAgents() predicate.TeamDefinition { + return predicate.TeamDefinition(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, AgentsTable, AgentsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasAgentsWith applies the HasEdge predicate on the "agents" edge with a given conditions (other predicates). +func HasAgentsWith(preds ...predicate.AgentDefinition) predicate.TeamDefinition { + return predicate.TeamDefinition(func(s *sql.Selector) { + step := newAgentsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.TeamDefinition) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.TeamDefinition) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.TeamDefinition) predicate.TeamDefinition { + return predicate.TeamDefinition(sql.NotPredicates(p)) +} diff --git a/internal/ent/teamdefinition_create.go b/internal/ent/teamdefinition_create.go new file mode 100644 index 0000000..c7044aa --- /dev/null +++ b/internal/ent/teamdefinition_create.go @@ -0,0 +1,505 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// TeamDefinitionCreate is the builder for creating a TeamDefinition entity. +type TeamDefinitionCreate struct { + config + mutation *TeamDefinitionMutation + hooks []Hook +} + +// SetRepoName sets the "repo_name" field. +func (_c *TeamDefinitionCreate) SetRepoName(v string) *TeamDefinitionCreate { + _c.mutation.SetRepoName(v) + return _c +} + +// SetName sets the "name" field. +func (_c *TeamDefinitionCreate) SetName(v string) *TeamDefinitionCreate { + _c.mutation.SetName(v) + return _c +} + +// SetSourceRef sets the "source_ref" field. +func (_c *TeamDefinitionCreate) SetSourceRef(v string) *TeamDefinitionCreate { + _c.mutation.SetSourceRef(v) + return _c +} + +// SetNillableSourceRef sets the "source_ref" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableSourceRef(v *string) *TeamDefinitionCreate { + if v != nil { + _c.SetSourceRef(*v) + } + return _c +} + +// SetRegistryXrn sets the "registry_xrn" field. +func (_c *TeamDefinitionCreate) SetRegistryXrn(v string) *TeamDefinitionCreate { + _c.mutation.SetRegistryXrn(v) + return _c +} + +// SetNillableRegistryXrn sets the "registry_xrn" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableRegistryXrn(v *string) *TeamDefinitionCreate { + if v != nil { + _c.SetRegistryXrn(*v) + } + return _c +} + +// SetVersion sets the "version" field. +func (_c *TeamDefinitionCreate) SetVersion(v string) *TeamDefinitionCreate { + _c.mutation.SetVersion(v) + return _c +} + +// SetNillableVersion sets the "version" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableVersion(v *string) *TeamDefinitionCreate { + if v != nil { + _c.SetVersion(*v) + } + return _c +} + +// SetDescription sets the "description" field. +func (_c *TeamDefinitionCreate) SetDescription(v string) *TeamDefinitionCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableDescription(v *string) *TeamDefinitionCreate { + if v != nil { + _c.SetDescription(*v) + } + return _c +} + +// SetOrchestrator sets the "orchestrator" field. +func (_c *TeamDefinitionCreate) SetOrchestrator(v string) *TeamDefinitionCreate { + _c.mutation.SetOrchestrator(v) + return _c +} + +// SetNillableOrchestrator sets the "orchestrator" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableOrchestrator(v *string) *TeamDefinitionCreate { + if v != nil { + _c.SetOrchestrator(*v) + } + return _c +} + +// SetAgentNames sets the "agent_names" field. +func (_c *TeamDefinitionCreate) SetAgentNames(v []string) *TeamDefinitionCreate { + _c.mutation.SetAgentNames(v) + return _c +} + +// SetSourcePath sets the "source_path" field. +func (_c *TeamDefinitionCreate) SetSourcePath(v string) *TeamDefinitionCreate { + _c.mutation.SetSourcePath(v) + return _c +} + +// SetContentHash sets the "content_hash" field. +func (_c *TeamDefinitionCreate) SetContentHash(v string) *TeamDefinitionCreate { + _c.mutation.SetContentHash(v) + return _c +} + +// SetFirstSeenAt sets the "first_seen_at" field. +func (_c *TeamDefinitionCreate) SetFirstSeenAt(v time.Time) *TeamDefinitionCreate { + _c.mutation.SetFirstSeenAt(v) + return _c +} + +// SetNillableFirstSeenAt sets the "first_seen_at" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableFirstSeenAt(v *time.Time) *TeamDefinitionCreate { + if v != nil { + _c.SetFirstSeenAt(*v) + } + return _c +} + +// SetLastSeenAt sets the "last_seen_at" field. +func (_c *TeamDefinitionCreate) SetLastSeenAt(v time.Time) *TeamDefinitionCreate { + _c.mutation.SetLastSeenAt(v) + return _c +} + +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableLastSeenAt(v *time.Time) *TeamDefinitionCreate { + if v != nil { + _c.SetLastSeenAt(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *TeamDefinitionCreate) SetCreatedAt(v time.Time) *TeamDefinitionCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableCreatedAt(v *time.Time) *TeamDefinitionCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *TeamDefinitionCreate) SetUpdatedAt(v time.Time) *TeamDefinitionCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableUpdatedAt(v *time.Time) *TeamDefinitionCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *TeamDefinitionCreate) SetID(v uuid.UUID) *TeamDefinitionCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *TeamDefinitionCreate) SetNillableID(v *uuid.UUID) *TeamDefinitionCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// AddAgentIDs adds the "agents" edge to the AgentDefinition entity by IDs. +func (_c *TeamDefinitionCreate) AddAgentIDs(ids ...uuid.UUID) *TeamDefinitionCreate { + _c.mutation.AddAgentIDs(ids...) + return _c +} + +// AddAgents adds the "agents" edges to the AgentDefinition entity. +func (_c *TeamDefinitionCreate) AddAgents(v ...*AgentDefinition) *TeamDefinitionCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddAgentIDs(ids...) +} + +// Mutation returns the TeamDefinitionMutation object of the builder. +func (_c *TeamDefinitionCreate) Mutation() *TeamDefinitionMutation { + return _c.mutation +} + +// Save creates the TeamDefinition in the database. +func (_c *TeamDefinitionCreate) Save(ctx context.Context) (*TeamDefinition, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *TeamDefinitionCreate) SaveX(ctx context.Context) *TeamDefinition { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *TeamDefinitionCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *TeamDefinitionCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *TeamDefinitionCreate) defaults() { + if _, ok := _c.mutation.FirstSeenAt(); !ok { + v := teamdefinition.DefaultFirstSeenAt() + _c.mutation.SetFirstSeenAt(v) + } + if _, ok := _c.mutation.LastSeenAt(); !ok { + v := teamdefinition.DefaultLastSeenAt() + _c.mutation.SetLastSeenAt(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := teamdefinition.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := teamdefinition.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := teamdefinition.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *TeamDefinitionCreate) check() error { + if _, ok := _c.mutation.RepoName(); !ok { + return &ValidationError{Name: "repo_name", err: errors.New(`ent: missing required field "TeamDefinition.repo_name"`)} + } + if v, ok := _c.mutation.RepoName(); ok { + if err := teamdefinition.RepoNameValidator(v); err != nil { + return &ValidationError{Name: "repo_name", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.repo_name": %w`, err)} + } + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "TeamDefinition.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := teamdefinition.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.name": %w`, err)} + } + } + if _, ok := _c.mutation.SourcePath(); !ok { + return &ValidationError{Name: "source_path", err: errors.New(`ent: missing required field "TeamDefinition.source_path"`)} + } + if v, ok := _c.mutation.SourcePath(); ok { + if err := teamdefinition.SourcePathValidator(v); err != nil { + return &ValidationError{Name: "source_path", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.source_path": %w`, err)} + } + } + if _, ok := _c.mutation.ContentHash(); !ok { + return &ValidationError{Name: "content_hash", err: errors.New(`ent: missing required field "TeamDefinition.content_hash"`)} + } + if v, ok := _c.mutation.ContentHash(); ok { + if err := teamdefinition.ContentHashValidator(v); err != nil { + return &ValidationError{Name: "content_hash", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.content_hash": %w`, err)} + } + } + if _, ok := _c.mutation.FirstSeenAt(); !ok { + return &ValidationError{Name: "first_seen_at", err: errors.New(`ent: missing required field "TeamDefinition.first_seen_at"`)} + } + if _, ok := _c.mutation.LastSeenAt(); !ok { + return &ValidationError{Name: "last_seen_at", err: errors.New(`ent: missing required field "TeamDefinition.last_seen_at"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "TeamDefinition.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "TeamDefinition.updated_at"`)} + } + return nil +} + +func (_c *TeamDefinitionCreate) sqlSave(ctx context.Context) (*TeamDefinition, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *TeamDefinitionCreate) createSpec() (*TeamDefinition, *sqlgraph.CreateSpec) { + var ( + _node = &TeamDefinition{config: _c.config} + _spec = sqlgraph.NewCreateSpec(teamdefinition.Table, sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.RepoName(); ok { + _spec.SetField(teamdefinition.FieldRepoName, field.TypeString, value) + _node.RepoName = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(teamdefinition.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.SourceRef(); ok { + _spec.SetField(teamdefinition.FieldSourceRef, field.TypeString, value) + _node.SourceRef = value + } + if value, ok := _c.mutation.RegistryXrn(); ok { + _spec.SetField(teamdefinition.FieldRegistryXrn, field.TypeString, value) + _node.RegistryXrn = value + } + if value, ok := _c.mutation.Version(); ok { + _spec.SetField(teamdefinition.FieldVersion, field.TypeString, value) + _node.Version = value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(teamdefinition.FieldDescription, field.TypeString, value) + _node.Description = value + } + if value, ok := _c.mutation.Orchestrator(); ok { + _spec.SetField(teamdefinition.FieldOrchestrator, field.TypeString, value) + _node.Orchestrator = value + } + if value, ok := _c.mutation.AgentNames(); ok { + _spec.SetField(teamdefinition.FieldAgentNames, field.TypeJSON, value) + _node.AgentNames = value + } + if value, ok := _c.mutation.SourcePath(); ok { + _spec.SetField(teamdefinition.FieldSourcePath, field.TypeString, value) + _node.SourcePath = value + } + if value, ok := _c.mutation.ContentHash(); ok { + _spec.SetField(teamdefinition.FieldContentHash, field.TypeString, value) + _node.ContentHash = value + } + if value, ok := _c.mutation.FirstSeenAt(); ok { + _spec.SetField(teamdefinition.FieldFirstSeenAt, field.TypeTime, value) + _node.FirstSeenAt = value + } + if value, ok := _c.mutation.LastSeenAt(); ok { + _spec.SetField(teamdefinition.FieldLastSeenAt, field.TypeTime, value) + _node.LastSeenAt = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(teamdefinition.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(teamdefinition.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if nodes := _c.mutation.AgentsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamdefinition.AgentsTable, + Columns: teamdefinition.AgentsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// TeamDefinitionCreateBulk is the builder for creating many TeamDefinition entities in bulk. +type TeamDefinitionCreateBulk struct { + config + err error + builders []*TeamDefinitionCreate +} + +// Save creates the TeamDefinition entities in the database. +func (_c *TeamDefinitionCreateBulk) Save(ctx context.Context) ([]*TeamDefinition, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*TeamDefinition, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*TeamDefinitionMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *TeamDefinitionCreateBulk) SaveX(ctx context.Context) []*TeamDefinition { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *TeamDefinitionCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *TeamDefinitionCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/ent/teamdefinition_delete.go b/internal/ent/teamdefinition_delete.go new file mode 100644 index 0000000..c506b4f --- /dev/null +++ b/internal/ent/teamdefinition_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/plexusone/agentplexus/internal/ent/predicate" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// TeamDefinitionDelete is the builder for deleting a TeamDefinition entity. +type TeamDefinitionDelete struct { + config + hooks []Hook + mutation *TeamDefinitionMutation +} + +// Where appends a list predicates to the TeamDefinitionDelete builder. +func (_d *TeamDefinitionDelete) Where(ps ...predicate.TeamDefinition) *TeamDefinitionDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *TeamDefinitionDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *TeamDefinitionDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *TeamDefinitionDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(teamdefinition.Table, sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// TeamDefinitionDeleteOne is the builder for deleting a single TeamDefinition entity. +type TeamDefinitionDeleteOne struct { + _d *TeamDefinitionDelete +} + +// Where appends a list predicates to the TeamDefinitionDelete builder. +func (_d *TeamDefinitionDeleteOne) Where(ps ...predicate.TeamDefinition) *TeamDefinitionDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *TeamDefinitionDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{teamdefinition.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *TeamDefinitionDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/ent/teamdefinition_query.go b/internal/ent/teamdefinition_query.go new file mode 100644 index 0000000..8661453 --- /dev/null +++ b/internal/ent/teamdefinition_query.go @@ -0,0 +1,638 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/predicate" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// TeamDefinitionQuery is the builder for querying TeamDefinition entities. +type TeamDefinitionQuery struct { + config + ctx *QueryContext + order []teamdefinition.OrderOption + inters []Interceptor + predicates []predicate.TeamDefinition + withAgents *AgentDefinitionQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the TeamDefinitionQuery builder. +func (_q *TeamDefinitionQuery) Where(ps ...predicate.TeamDefinition) *TeamDefinitionQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *TeamDefinitionQuery) Limit(limit int) *TeamDefinitionQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *TeamDefinitionQuery) Offset(offset int) *TeamDefinitionQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *TeamDefinitionQuery) Unique(unique bool) *TeamDefinitionQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *TeamDefinitionQuery) Order(o ...teamdefinition.OrderOption) *TeamDefinitionQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryAgents chains the current query on the "agents" edge. +func (_q *TeamDefinitionQuery) QueryAgents() *AgentDefinitionQuery { + query := (&AgentDefinitionClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(teamdefinition.Table, teamdefinition.FieldID, selector), + sqlgraph.To(agentdefinition.Table, agentdefinition.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, teamdefinition.AgentsTable, teamdefinition.AgentsPrimaryKey...), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first TeamDefinition entity from the query. +// Returns a *NotFoundError when no TeamDefinition was found. +func (_q *TeamDefinitionQuery) First(ctx context.Context) (*TeamDefinition, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{teamdefinition.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *TeamDefinitionQuery) FirstX(ctx context.Context) *TeamDefinition { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first TeamDefinition ID from the query. +// Returns a *NotFoundError when no TeamDefinition ID was found. +func (_q *TeamDefinitionQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{teamdefinition.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *TeamDefinitionQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single TeamDefinition entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one TeamDefinition entity is found. +// Returns a *NotFoundError when no TeamDefinition entities are found. +func (_q *TeamDefinitionQuery) Only(ctx context.Context) (*TeamDefinition, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{teamdefinition.Label} + default: + return nil, &NotSingularError{teamdefinition.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *TeamDefinitionQuery) OnlyX(ctx context.Context) *TeamDefinition { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only TeamDefinition ID in the query. +// Returns a *NotSingularError when more than one TeamDefinition ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *TeamDefinitionQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{teamdefinition.Label} + default: + err = &NotSingularError{teamdefinition.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *TeamDefinitionQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of TeamDefinitions. +func (_q *TeamDefinitionQuery) All(ctx context.Context) ([]*TeamDefinition, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*TeamDefinition, *TeamDefinitionQuery]() + return withInterceptors[[]*TeamDefinition](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *TeamDefinitionQuery) AllX(ctx context.Context) []*TeamDefinition { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of TeamDefinition IDs. +func (_q *TeamDefinitionQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(teamdefinition.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *TeamDefinitionQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *TeamDefinitionQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*TeamDefinitionQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *TeamDefinitionQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *TeamDefinitionQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *TeamDefinitionQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the TeamDefinitionQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *TeamDefinitionQuery) Clone() *TeamDefinitionQuery { + if _q == nil { + return nil + } + return &TeamDefinitionQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]teamdefinition.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.TeamDefinition{}, _q.predicates...), + withAgents: _q.withAgents.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithAgents tells the query-builder to eager-load the nodes that are connected to +// the "agents" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TeamDefinitionQuery) WithAgents(opts ...func(*AgentDefinitionQuery)) *TeamDefinitionQuery { + query := (&AgentDefinitionClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withAgents = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// RepoName string `json:"repo_name,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.TeamDefinition.Query(). +// GroupBy(teamdefinition.FieldRepoName). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *TeamDefinitionQuery) GroupBy(field string, fields ...string) *TeamDefinitionGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &TeamDefinitionGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = teamdefinition.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// RepoName string `json:"repo_name,omitempty"` +// } +// +// client.TeamDefinition.Query(). +// Select(teamdefinition.FieldRepoName). +// Scan(ctx, &v) +func (_q *TeamDefinitionQuery) Select(fields ...string) *TeamDefinitionSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &TeamDefinitionSelect{TeamDefinitionQuery: _q} + sbuild.label = teamdefinition.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a TeamDefinitionSelect configured with the given aggregations. +func (_q *TeamDefinitionQuery) Aggregate(fns ...AggregateFunc) *TeamDefinitionSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *TeamDefinitionQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !teamdefinition.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *TeamDefinitionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TeamDefinition, error) { + var ( + nodes = []*TeamDefinition{} + _spec = _q.querySpec() + loadedTypes = [1]bool{ + _q.withAgents != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*TeamDefinition).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &TeamDefinition{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withAgents; query != nil { + if err := _q.loadAgents(ctx, query, nodes, + func(n *TeamDefinition) { n.Edges.Agents = []*AgentDefinition{} }, + func(n *TeamDefinition, e *AgentDefinition) { n.Edges.Agents = append(n.Edges.Agents, e) }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *TeamDefinitionQuery) loadAgents(ctx context.Context, query *AgentDefinitionQuery, nodes []*TeamDefinition, init func(*TeamDefinition), assign func(*TeamDefinition, *AgentDefinition)) error { + edgeIDs := make([]driver.Value, len(nodes)) + byID := make(map[uuid.UUID]*TeamDefinition) + nids := make(map[uuid.UUID]map[*TeamDefinition]struct{}) + for i, node := range nodes { + edgeIDs[i] = node.ID + byID[node.ID] = node + if init != nil { + init(node) + } + } + query.Where(func(s *sql.Selector) { + joinT := sql.Table(teamdefinition.AgentsTable) + s.Join(joinT).On(s.C(agentdefinition.FieldID), joinT.C(teamdefinition.AgentsPrimaryKey[1])) + s.Where(sql.InValues(joinT.C(teamdefinition.AgentsPrimaryKey[0]), edgeIDs...)) + columns := s.SelectedColumns() + s.Select(joinT.C(teamdefinition.AgentsPrimaryKey[0])) + s.AppendSelect(columns...) + s.SetDistinct(false) + }) + if err := query.prepareQuery(ctx); err != nil { + return err + } + qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { + assign := spec.Assign + values := spec.ScanValues + spec.ScanValues = func(columns []string) ([]any, error) { + values, err := values(columns[1:]) + if err != nil { + return nil, err + } + return append([]any{new(uuid.UUID)}, values...), nil + } + spec.Assign = func(columns []string, values []any) error { + outValue := *values[0].(*uuid.UUID) + inValue := *values[1].(*uuid.UUID) + if nids[inValue] == nil { + nids[inValue] = map[*TeamDefinition]struct{}{byID[outValue]: {}} + return assign(columns[1:], values[1:]) + } + nids[inValue][byID[outValue]] = struct{}{} + return nil + } + }) + }) + neighbors, err := withInterceptors[[]*AgentDefinition](ctx, query, qr, query.inters) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nids[n.ID] + if !ok { + return fmt.Errorf(`unexpected "agents" node returned %v`, n.ID) + } + for kn := range nodes { + assign(kn, n) + } + } + return nil +} + +func (_q *TeamDefinitionQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *TeamDefinitionQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(teamdefinition.Table, teamdefinition.Columns, sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, teamdefinition.FieldID) + for i := range fields { + if fields[i] != teamdefinition.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *TeamDefinitionQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(teamdefinition.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = teamdefinition.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// TeamDefinitionGroupBy is the group-by builder for TeamDefinition entities. +type TeamDefinitionGroupBy struct { + selector + build *TeamDefinitionQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *TeamDefinitionGroupBy) Aggregate(fns ...AggregateFunc) *TeamDefinitionGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *TeamDefinitionGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*TeamDefinitionQuery, *TeamDefinitionGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *TeamDefinitionGroupBy) sqlScan(ctx context.Context, root *TeamDefinitionQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// TeamDefinitionSelect is the builder for selecting fields of TeamDefinition entities. +type TeamDefinitionSelect struct { + *TeamDefinitionQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *TeamDefinitionSelect) Aggregate(fns ...AggregateFunc) *TeamDefinitionSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *TeamDefinitionSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*TeamDefinitionQuery, *TeamDefinitionSelect](ctx, _s.TeamDefinitionQuery, _s, _s.inters, v) +} + +func (_s *TeamDefinitionSelect) sqlScan(ctx context.Context, root *TeamDefinitionQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/internal/ent/teamdefinition_update.go b/internal/ent/teamdefinition_update.go new file mode 100644 index 0000000..501bb0c --- /dev/null +++ b/internal/ent/teamdefinition_update.go @@ -0,0 +1,875 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + "github.com/plexusone/agentplexus/internal/ent/predicate" + "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// TeamDefinitionUpdate is the builder for updating TeamDefinition entities. +type TeamDefinitionUpdate struct { + config + hooks []Hook + mutation *TeamDefinitionMutation +} + +// Where appends a list predicates to the TeamDefinitionUpdate builder. +func (_u *TeamDefinitionUpdate) Where(ps ...predicate.TeamDefinition) *TeamDefinitionUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetRepoName sets the "repo_name" field. +func (_u *TeamDefinitionUpdate) SetRepoName(v string) *TeamDefinitionUpdate { + _u.mutation.SetRepoName(v) + return _u +} + +// SetNillableRepoName sets the "repo_name" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableRepoName(v *string) *TeamDefinitionUpdate { + if v != nil { + _u.SetRepoName(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *TeamDefinitionUpdate) SetName(v string) *TeamDefinitionUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableName(v *string) *TeamDefinitionUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetSourceRef sets the "source_ref" field. +func (_u *TeamDefinitionUpdate) SetSourceRef(v string) *TeamDefinitionUpdate { + _u.mutation.SetSourceRef(v) + return _u +} + +// SetNillableSourceRef sets the "source_ref" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableSourceRef(v *string) *TeamDefinitionUpdate { + if v != nil { + _u.SetSourceRef(*v) + } + return _u +} + +// ClearSourceRef clears the value of the "source_ref" field. +func (_u *TeamDefinitionUpdate) ClearSourceRef() *TeamDefinitionUpdate { + _u.mutation.ClearSourceRef() + return _u +} + +// SetVersion sets the "version" field. +func (_u *TeamDefinitionUpdate) SetVersion(v string) *TeamDefinitionUpdate { + _u.mutation.SetVersion(v) + return _u +} + +// SetNillableVersion sets the "version" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableVersion(v *string) *TeamDefinitionUpdate { + if v != nil { + _u.SetVersion(*v) + } + return _u +} + +// ClearVersion clears the value of the "version" field. +func (_u *TeamDefinitionUpdate) ClearVersion() *TeamDefinitionUpdate { + _u.mutation.ClearVersion() + return _u +} + +// SetDescription sets the "description" field. +func (_u *TeamDefinitionUpdate) SetDescription(v string) *TeamDefinitionUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableDescription(v *string) *TeamDefinitionUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *TeamDefinitionUpdate) ClearDescription() *TeamDefinitionUpdate { + _u.mutation.ClearDescription() + return _u +} + +// SetOrchestrator sets the "orchestrator" field. +func (_u *TeamDefinitionUpdate) SetOrchestrator(v string) *TeamDefinitionUpdate { + _u.mutation.SetOrchestrator(v) + return _u +} + +// SetNillableOrchestrator sets the "orchestrator" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableOrchestrator(v *string) *TeamDefinitionUpdate { + if v != nil { + _u.SetOrchestrator(*v) + } + return _u +} + +// ClearOrchestrator clears the value of the "orchestrator" field. +func (_u *TeamDefinitionUpdate) ClearOrchestrator() *TeamDefinitionUpdate { + _u.mutation.ClearOrchestrator() + return _u +} + +// SetAgentNames sets the "agent_names" field. +func (_u *TeamDefinitionUpdate) SetAgentNames(v []string) *TeamDefinitionUpdate { + _u.mutation.SetAgentNames(v) + return _u +} + +// AppendAgentNames appends value to the "agent_names" field. +func (_u *TeamDefinitionUpdate) AppendAgentNames(v []string) *TeamDefinitionUpdate { + _u.mutation.AppendAgentNames(v) + return _u +} + +// ClearAgentNames clears the value of the "agent_names" field. +func (_u *TeamDefinitionUpdate) ClearAgentNames() *TeamDefinitionUpdate { + _u.mutation.ClearAgentNames() + return _u +} + +// SetSourcePath sets the "source_path" field. +func (_u *TeamDefinitionUpdate) SetSourcePath(v string) *TeamDefinitionUpdate { + _u.mutation.SetSourcePath(v) + return _u +} + +// SetNillableSourcePath sets the "source_path" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableSourcePath(v *string) *TeamDefinitionUpdate { + if v != nil { + _u.SetSourcePath(*v) + } + return _u +} + +// SetContentHash sets the "content_hash" field. +func (_u *TeamDefinitionUpdate) SetContentHash(v string) *TeamDefinitionUpdate { + _u.mutation.SetContentHash(v) + return _u +} + +// SetNillableContentHash sets the "content_hash" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableContentHash(v *string) *TeamDefinitionUpdate { + if v != nil { + _u.SetContentHash(*v) + } + return _u +} + +// SetLastSeenAt sets the "last_seen_at" field. +func (_u *TeamDefinitionUpdate) SetLastSeenAt(v time.Time) *TeamDefinitionUpdate { + _u.mutation.SetLastSeenAt(v) + return _u +} + +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. +func (_u *TeamDefinitionUpdate) SetNillableLastSeenAt(v *time.Time) *TeamDefinitionUpdate { + if v != nil { + _u.SetLastSeenAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *TeamDefinitionUpdate) SetUpdatedAt(v time.Time) *TeamDefinitionUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// AddAgentIDs adds the "agents" edge to the AgentDefinition entity by IDs. +func (_u *TeamDefinitionUpdate) AddAgentIDs(ids ...uuid.UUID) *TeamDefinitionUpdate { + _u.mutation.AddAgentIDs(ids...) + return _u +} + +// AddAgents adds the "agents" edges to the AgentDefinition entity. +func (_u *TeamDefinitionUpdate) AddAgents(v ...*AgentDefinition) *TeamDefinitionUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddAgentIDs(ids...) +} + +// Mutation returns the TeamDefinitionMutation object of the builder. +func (_u *TeamDefinitionUpdate) Mutation() *TeamDefinitionMutation { + return _u.mutation +} + +// ClearAgents clears all "agents" edges to the AgentDefinition entity. +func (_u *TeamDefinitionUpdate) ClearAgents() *TeamDefinitionUpdate { + _u.mutation.ClearAgents() + return _u +} + +// RemoveAgentIDs removes the "agents" edge to AgentDefinition entities by IDs. +func (_u *TeamDefinitionUpdate) RemoveAgentIDs(ids ...uuid.UUID) *TeamDefinitionUpdate { + _u.mutation.RemoveAgentIDs(ids...) + return _u +} + +// RemoveAgents removes "agents" edges to AgentDefinition entities. +func (_u *TeamDefinitionUpdate) RemoveAgents(v ...*AgentDefinition) *TeamDefinitionUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveAgentIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *TeamDefinitionUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *TeamDefinitionUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *TeamDefinitionUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *TeamDefinitionUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *TeamDefinitionUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := teamdefinition.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *TeamDefinitionUpdate) check() error { + if v, ok := _u.mutation.RepoName(); ok { + if err := teamdefinition.RepoNameValidator(v); err != nil { + return &ValidationError{Name: "repo_name", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.repo_name": %w`, err)} + } + } + if v, ok := _u.mutation.Name(); ok { + if err := teamdefinition.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.name": %w`, err)} + } + } + if v, ok := _u.mutation.SourcePath(); ok { + if err := teamdefinition.SourcePathValidator(v); err != nil { + return &ValidationError{Name: "source_path", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.source_path": %w`, err)} + } + } + if v, ok := _u.mutation.ContentHash(); ok { + if err := teamdefinition.ContentHashValidator(v); err != nil { + return &ValidationError{Name: "content_hash", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.content_hash": %w`, err)} + } + } + return nil +} + +func (_u *TeamDefinitionUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(teamdefinition.Table, teamdefinition.Columns, sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.RepoName(); ok { + _spec.SetField(teamdefinition.FieldRepoName, field.TypeString, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(teamdefinition.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.SourceRef(); ok { + _spec.SetField(teamdefinition.FieldSourceRef, field.TypeString, value) + } + if _u.mutation.SourceRefCleared() { + _spec.ClearField(teamdefinition.FieldSourceRef, field.TypeString) + } + if _u.mutation.RegistryXrnCleared() { + _spec.ClearField(teamdefinition.FieldRegistryXrn, field.TypeString) + } + if value, ok := _u.mutation.Version(); ok { + _spec.SetField(teamdefinition.FieldVersion, field.TypeString, value) + } + if _u.mutation.VersionCleared() { + _spec.ClearField(teamdefinition.FieldVersion, field.TypeString) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(teamdefinition.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(teamdefinition.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Orchestrator(); ok { + _spec.SetField(teamdefinition.FieldOrchestrator, field.TypeString, value) + } + if _u.mutation.OrchestratorCleared() { + _spec.ClearField(teamdefinition.FieldOrchestrator, field.TypeString) + } + if value, ok := _u.mutation.AgentNames(); ok { + _spec.SetField(teamdefinition.FieldAgentNames, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedAgentNames(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, teamdefinition.FieldAgentNames, value) + }) + } + if _u.mutation.AgentNamesCleared() { + _spec.ClearField(teamdefinition.FieldAgentNames, field.TypeJSON) + } + if value, ok := _u.mutation.SourcePath(); ok { + _spec.SetField(teamdefinition.FieldSourcePath, field.TypeString, value) + } + if value, ok := _u.mutation.ContentHash(); ok { + _spec.SetField(teamdefinition.FieldContentHash, field.TypeString, value) + } + if value, ok := _u.mutation.LastSeenAt(); ok { + _spec.SetField(teamdefinition.FieldLastSeenAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(teamdefinition.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.AgentsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamdefinition.AgentsTable, + Columns: teamdefinition.AgentsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedAgentsIDs(); len(nodes) > 0 && !_u.mutation.AgentsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamdefinition.AgentsTable, + Columns: teamdefinition.AgentsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.AgentsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamdefinition.AgentsTable, + Columns: teamdefinition.AgentsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{teamdefinition.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// TeamDefinitionUpdateOne is the builder for updating a single TeamDefinition entity. +type TeamDefinitionUpdateOne struct { + config + fields []string + hooks []Hook + mutation *TeamDefinitionMutation +} + +// SetRepoName sets the "repo_name" field. +func (_u *TeamDefinitionUpdateOne) SetRepoName(v string) *TeamDefinitionUpdateOne { + _u.mutation.SetRepoName(v) + return _u +} + +// SetNillableRepoName sets the "repo_name" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableRepoName(v *string) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetRepoName(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *TeamDefinitionUpdateOne) SetName(v string) *TeamDefinitionUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableName(v *string) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetSourceRef sets the "source_ref" field. +func (_u *TeamDefinitionUpdateOne) SetSourceRef(v string) *TeamDefinitionUpdateOne { + _u.mutation.SetSourceRef(v) + return _u +} + +// SetNillableSourceRef sets the "source_ref" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableSourceRef(v *string) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetSourceRef(*v) + } + return _u +} + +// ClearSourceRef clears the value of the "source_ref" field. +func (_u *TeamDefinitionUpdateOne) ClearSourceRef() *TeamDefinitionUpdateOne { + _u.mutation.ClearSourceRef() + return _u +} + +// SetVersion sets the "version" field. +func (_u *TeamDefinitionUpdateOne) SetVersion(v string) *TeamDefinitionUpdateOne { + _u.mutation.SetVersion(v) + return _u +} + +// SetNillableVersion sets the "version" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableVersion(v *string) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetVersion(*v) + } + return _u +} + +// ClearVersion clears the value of the "version" field. +func (_u *TeamDefinitionUpdateOne) ClearVersion() *TeamDefinitionUpdateOne { + _u.mutation.ClearVersion() + return _u +} + +// SetDescription sets the "description" field. +func (_u *TeamDefinitionUpdateOne) SetDescription(v string) *TeamDefinitionUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableDescription(v *string) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *TeamDefinitionUpdateOne) ClearDescription() *TeamDefinitionUpdateOne { + _u.mutation.ClearDescription() + return _u +} + +// SetOrchestrator sets the "orchestrator" field. +func (_u *TeamDefinitionUpdateOne) SetOrchestrator(v string) *TeamDefinitionUpdateOne { + _u.mutation.SetOrchestrator(v) + return _u +} + +// SetNillableOrchestrator sets the "orchestrator" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableOrchestrator(v *string) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetOrchestrator(*v) + } + return _u +} + +// ClearOrchestrator clears the value of the "orchestrator" field. +func (_u *TeamDefinitionUpdateOne) ClearOrchestrator() *TeamDefinitionUpdateOne { + _u.mutation.ClearOrchestrator() + return _u +} + +// SetAgentNames sets the "agent_names" field. +func (_u *TeamDefinitionUpdateOne) SetAgentNames(v []string) *TeamDefinitionUpdateOne { + _u.mutation.SetAgentNames(v) + return _u +} + +// AppendAgentNames appends value to the "agent_names" field. +func (_u *TeamDefinitionUpdateOne) AppendAgentNames(v []string) *TeamDefinitionUpdateOne { + _u.mutation.AppendAgentNames(v) + return _u +} + +// ClearAgentNames clears the value of the "agent_names" field. +func (_u *TeamDefinitionUpdateOne) ClearAgentNames() *TeamDefinitionUpdateOne { + _u.mutation.ClearAgentNames() + return _u +} + +// SetSourcePath sets the "source_path" field. +func (_u *TeamDefinitionUpdateOne) SetSourcePath(v string) *TeamDefinitionUpdateOne { + _u.mutation.SetSourcePath(v) + return _u +} + +// SetNillableSourcePath sets the "source_path" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableSourcePath(v *string) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetSourcePath(*v) + } + return _u +} + +// SetContentHash sets the "content_hash" field. +func (_u *TeamDefinitionUpdateOne) SetContentHash(v string) *TeamDefinitionUpdateOne { + _u.mutation.SetContentHash(v) + return _u +} + +// SetNillableContentHash sets the "content_hash" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableContentHash(v *string) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetContentHash(*v) + } + return _u +} + +// SetLastSeenAt sets the "last_seen_at" field. +func (_u *TeamDefinitionUpdateOne) SetLastSeenAt(v time.Time) *TeamDefinitionUpdateOne { + _u.mutation.SetLastSeenAt(v) + return _u +} + +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. +func (_u *TeamDefinitionUpdateOne) SetNillableLastSeenAt(v *time.Time) *TeamDefinitionUpdateOne { + if v != nil { + _u.SetLastSeenAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *TeamDefinitionUpdateOne) SetUpdatedAt(v time.Time) *TeamDefinitionUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// AddAgentIDs adds the "agents" edge to the AgentDefinition entity by IDs. +func (_u *TeamDefinitionUpdateOne) AddAgentIDs(ids ...uuid.UUID) *TeamDefinitionUpdateOne { + _u.mutation.AddAgentIDs(ids...) + return _u +} + +// AddAgents adds the "agents" edges to the AgentDefinition entity. +func (_u *TeamDefinitionUpdateOne) AddAgents(v ...*AgentDefinition) *TeamDefinitionUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddAgentIDs(ids...) +} + +// Mutation returns the TeamDefinitionMutation object of the builder. +func (_u *TeamDefinitionUpdateOne) Mutation() *TeamDefinitionMutation { + return _u.mutation +} + +// ClearAgents clears all "agents" edges to the AgentDefinition entity. +func (_u *TeamDefinitionUpdateOne) ClearAgents() *TeamDefinitionUpdateOne { + _u.mutation.ClearAgents() + return _u +} + +// RemoveAgentIDs removes the "agents" edge to AgentDefinition entities by IDs. +func (_u *TeamDefinitionUpdateOne) RemoveAgentIDs(ids ...uuid.UUID) *TeamDefinitionUpdateOne { + _u.mutation.RemoveAgentIDs(ids...) + return _u +} + +// RemoveAgents removes "agents" edges to AgentDefinition entities. +func (_u *TeamDefinitionUpdateOne) RemoveAgents(v ...*AgentDefinition) *TeamDefinitionUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveAgentIDs(ids...) +} + +// Where appends a list predicates to the TeamDefinitionUpdate builder. +func (_u *TeamDefinitionUpdateOne) Where(ps ...predicate.TeamDefinition) *TeamDefinitionUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *TeamDefinitionUpdateOne) Select(field string, fields ...string) *TeamDefinitionUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated TeamDefinition entity. +func (_u *TeamDefinitionUpdateOne) Save(ctx context.Context) (*TeamDefinition, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *TeamDefinitionUpdateOne) SaveX(ctx context.Context) *TeamDefinition { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *TeamDefinitionUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *TeamDefinitionUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *TeamDefinitionUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := teamdefinition.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *TeamDefinitionUpdateOne) check() error { + if v, ok := _u.mutation.RepoName(); ok { + if err := teamdefinition.RepoNameValidator(v); err != nil { + return &ValidationError{Name: "repo_name", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.repo_name": %w`, err)} + } + } + if v, ok := _u.mutation.Name(); ok { + if err := teamdefinition.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.name": %w`, err)} + } + } + if v, ok := _u.mutation.SourcePath(); ok { + if err := teamdefinition.SourcePathValidator(v); err != nil { + return &ValidationError{Name: "source_path", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.source_path": %w`, err)} + } + } + if v, ok := _u.mutation.ContentHash(); ok { + if err := teamdefinition.ContentHashValidator(v); err != nil { + return &ValidationError{Name: "content_hash", err: fmt.Errorf(`ent: validator failed for field "TeamDefinition.content_hash": %w`, err)} + } + } + return nil +} + +func (_u *TeamDefinitionUpdateOne) sqlSave(ctx context.Context) (_node *TeamDefinition, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(teamdefinition.Table, teamdefinition.Columns, sqlgraph.NewFieldSpec(teamdefinition.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TeamDefinition.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, teamdefinition.FieldID) + for _, f := range fields { + if !teamdefinition.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != teamdefinition.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.RepoName(); ok { + _spec.SetField(teamdefinition.FieldRepoName, field.TypeString, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(teamdefinition.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.SourceRef(); ok { + _spec.SetField(teamdefinition.FieldSourceRef, field.TypeString, value) + } + if _u.mutation.SourceRefCleared() { + _spec.ClearField(teamdefinition.FieldSourceRef, field.TypeString) + } + if _u.mutation.RegistryXrnCleared() { + _spec.ClearField(teamdefinition.FieldRegistryXrn, field.TypeString) + } + if value, ok := _u.mutation.Version(); ok { + _spec.SetField(teamdefinition.FieldVersion, field.TypeString, value) + } + if _u.mutation.VersionCleared() { + _spec.ClearField(teamdefinition.FieldVersion, field.TypeString) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(teamdefinition.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(teamdefinition.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Orchestrator(); ok { + _spec.SetField(teamdefinition.FieldOrchestrator, field.TypeString, value) + } + if _u.mutation.OrchestratorCleared() { + _spec.ClearField(teamdefinition.FieldOrchestrator, field.TypeString) + } + if value, ok := _u.mutation.AgentNames(); ok { + _spec.SetField(teamdefinition.FieldAgentNames, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedAgentNames(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, teamdefinition.FieldAgentNames, value) + }) + } + if _u.mutation.AgentNamesCleared() { + _spec.ClearField(teamdefinition.FieldAgentNames, field.TypeJSON) + } + if value, ok := _u.mutation.SourcePath(); ok { + _spec.SetField(teamdefinition.FieldSourcePath, field.TypeString, value) + } + if value, ok := _u.mutation.ContentHash(); ok { + _spec.SetField(teamdefinition.FieldContentHash, field.TypeString, value) + } + if value, ok := _u.mutation.LastSeenAt(); ok { + _spec.SetField(teamdefinition.FieldLastSeenAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(teamdefinition.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.AgentsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamdefinition.AgentsTable, + Columns: teamdefinition.AgentsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedAgentsIDs(); len(nodes) > 0 && !_u.mutation.AgentsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamdefinition.AgentsTable, + Columns: teamdefinition.AgentsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.AgentsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: teamdefinition.AgentsTable, + Columns: teamdefinition.AgentsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(agentdefinition.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &TeamDefinition{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{teamdefinition.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/internal/ent/tx.go b/internal/ent/tx.go index 3489edb..d32678d 100644 --- a/internal/ent/tx.go +++ b/internal/ent/tx.go @@ -12,6 +12,10 @@ import ( // Tx is a transactional client that is created by calling Client.Tx(). type Tx struct { config + // AgentDefinition is the client for interacting with the AgentDefinition builders. + AgentDefinition *AgentDefinitionClient + // TeamDefinition is the client for interacting with the TeamDefinition builders. + TeamDefinition *TeamDefinitionClient // View is the client for interacting with the View builders. View *ViewClient @@ -145,6 +149,8 @@ func (tx *Tx) Client() *Client { } func (tx *Tx) init() { + tx.AgentDefinition = NewAgentDefinitionClient(tx.config) + tx.TeamDefinition = NewTeamDefinitionClient(tx.config) tx.View = NewViewClient(tx.config) } @@ -155,7 +161,7 @@ func (tx *Tx) init() { // of them in order to commit or rollback the transaction. // // If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: View.QueryXXX(), the query will be executed +// applies a query, for example: AgentDefinition.QueryXXX(), the query will be executed // through the driver which created this transaction. // // Note that txDriver is not goroutine safe. diff --git a/internal/ent/view.go b/internal/ent/view.go index 4498a4a..c41e91e 100644 --- a/internal/ent/view.go +++ b/internal/ent/view.go @@ -10,9 +10,9 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" + "github.com/google/uuid" "github.com/plexusone/agentplexus/internal/ent/schema" "github.com/plexusone/agentplexus/internal/ent/view" - "github.com/google/uuid" ) // View is the model entity for the View schema. diff --git a/internal/ent/view/where.go b/internal/ent/view/where.go index 3704958..20b4564 100644 --- a/internal/ent/view/where.go +++ b/internal/ent/view/where.go @@ -6,8 +6,8 @@ import ( "time" "entgo.io/ent/dialect/sql" - "github.com/plexusone/agentplexus/internal/ent/predicate" "github.com/google/uuid" + "github.com/plexusone/agentplexus/internal/ent/predicate" ) // ID filters vertices based on their ID field. diff --git a/internal/ent/view_create.go b/internal/ent/view_create.go index 19cfa6c..a45df34 100644 --- a/internal/ent/view_create.go +++ b/internal/ent/view_create.go @@ -10,9 +10,9 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/google/uuid" "github.com/plexusone/agentplexus/internal/ent/schema" "github.com/plexusone/agentplexus/internal/ent/view" - "github.com/google/uuid" ) // ViewCreate is the builder for creating a View entity. diff --git a/internal/ent/view_query.go b/internal/ent/view_query.go index 1e6800d..5d43a81 100644 --- a/internal/ent/view_query.go +++ b/internal/ent/view_query.go @@ -11,9 +11,9 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/google/uuid" "github.com/plexusone/agentplexus/internal/ent/predicate" "github.com/plexusone/agentplexus/internal/ent/view" - "github.com/google/uuid" ) // ViewQuery is the builder for querying View entities. diff --git a/internal/registry/registry.go b/internal/registry/registry.go new file mode 100644 index 0000000..22470c5 --- /dev/null +++ b/internal/registry/registry.go @@ -0,0 +1,350 @@ +// Package registry syncs multi-agent-spec team and agent definitions found +// on disk into AgentPlexus's persistent registry (the ent AgentDefinition +// and TeamDefinition entities — the Definition plane of the control plane). +// It provides a stable, queryable inventory of the agents already defined in +// agent-team-* repositories, keyed by (repo, namespace, name) rather than by +// file path so identity survives file moves. +package registry + +import ( + "context" + "crypto/sha256" + "encoding/hex" + "fmt" + "os" + "path/filepath" + "strings" + "sync" + "time" + + "github.com/google/uuid" + multiagentspec "github.com/plexusone/multi-agent-spec/sdk/go" + + "github.com/plexusone/agentplexus/internal/ent" + entagentdef "github.com/plexusone/agentplexus/internal/ent/agentdefinition" + entteamdef "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +// syncMu serializes Sync calls. The watcher-triggered resync and the +// POST /api/registry/sync handler can otherwise run concurrently: both +// can observe ent.IsNotFound for the same not-yet-registered agent or +// team and both attempt Create, and the loser of that race fails on the +// unique index and aborts its whole Sync call. +var syncMu sync.Mutex + +// Result summarizes one Sync call. +type Result struct { + AgentsRegistered int + AgentsUpdated int + TeamsRegistered int + TeamsUpdated int + // Warnings holds non-fatal problems, e.g. a team referencing an agent + // whose spec file could not be found or parsed. + Warnings []string +} + +func (r Result) String() string { + return fmt.Sprintf("agents: %d new, %d updated · teams: %d new, %d updated · %d warning(s)", + r.AgentsRegistered, r.AgentsUpdated, r.TeamsRegistered, r.TeamsUpdated, len(r.Warnings)) +} + +// Sync scans each specDir for multi-agent-spec agent and team files and +// upserts them into the registry. specDir is expected to contain +// "agents/*.md" and "teams/*.json", matching the layout the AgentPlexus +// viewer already reads. Sync is idempotent: re-running it against +// unchanged files only refreshes last_seen_at. +func Sync(ctx context.Context, client *ent.Client, specDirs []string) (Result, error) { + syncMu.Lock() + defer syncMu.Unlock() + + var result Result + + for _, specDir := range specDirs { + repoName := repoNameFromSpecDir(specDir) + + agentIDs, agentStats, err := syncAgents(ctx, client, repoName, specDir) + if err != nil { + return result, fmt.Errorf("sync agents for %s: %w", repoName, err) + } + result.AgentsRegistered += agentStats.registered + result.AgentsUpdated += agentStats.updated + result.Warnings = append(result.Warnings, agentStats.warnings...) + + teamStats, err := syncTeams(ctx, client, repoName, specDir, agentIDs) + if err != nil { + return result, fmt.Errorf("sync teams for %s: %w", repoName, err) + } + result.TeamsRegistered += teamStats.registered + result.TeamsUpdated += teamStats.updated + result.Warnings = append(result.Warnings, teamStats.warnings...) + } + + return result, nil +} + +type syncStats struct { + registered int + updated int + warnings []string +} + +// agentKey identifies an agent within a single repo. Team specs reference +// agents by bare name (no namespace), so lookups use namespace "". +type agentKey struct { + namespace string + name string +} + +func syncAgents(ctx context.Context, client *ent.Client, repoName, specDir string) (map[agentKey]uuid.UUID, syncStats, error) { + var stats syncStats + ids := make(map[agentKey]uuid.UUID) + moduleRef := moduleRefFromSpecDir(specDir) + + agentsDir := filepath.Join(specDir, "agents") + entries, err := os.ReadDir(agentsDir) + if err != nil { + if os.IsNotExist(err) { + return ids, stats, nil + } + return ids, stats, fmt.Errorf("read %s: %w", agentsDir, err) + } + + for _, entry := range entries { + if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".md") { + continue + } + + sourcePath := filepath.Join(agentsDir, entry.Name()) + // A malformed spec file shouldn't abort registration for the rest + // of the repo (or workspace); record it and move on. + spec, err := multiagentspec.LoadAgentFromFile(sourcePath) + if err != nil { + stats.warnings = append(stats.warnings, fmt.Sprintf("%s: parse %s: %v", repoName, entry.Name(), err)) + continue + } + + hash, err := hashFile(sourcePath) + if err != nil { + stats.warnings = append(stats.warnings, fmt.Sprintf("%s: hash %s: %v", repoName, spec.Name, err)) + continue + } + + existing, err := client.AgentDefinition.Query(). + Where( + entagentdef.RepoName(repoName), + entagentdef.Namespace(spec.Namespace), + entagentdef.Name(spec.Name), + ). + Only(ctx) + + switch { + case ent.IsNotFound(err): + id := uuid.New() + created, cerr := client.AgentDefinition.Create(). + SetID(id). + SetRegistryXrn("xrn:agentplexus:agent-definition:" + id.String()). + SetSourceRef(moduleRef + "/agents/" + spec.QualifiedName()). + SetRepoName(repoName). + SetNamespace(spec.Namespace). + SetName(spec.Name). + SetQualifiedName(spec.QualifiedName()). + SetDescription(spec.Description). + SetModel(string(spec.Model)). + SetIcon(spec.Icon). + SetRole(spec.Role). + SetTools(spec.Tools). + SetAllowedTools(spec.AllowedTools). + SetSkills(spec.Skills). + SetDependencies(spec.Dependencies). + SetRequires(spec.Requires). + SetSourcePath(sourcePath). + SetContentHash(hash). + Save(ctx) + if cerr != nil { + return ids, stats, fmt.Errorf("create agent %s/%s: %w", repoName, spec.Name, cerr) + } + ids[agentKey{spec.Namespace, spec.Name}] = created.ID + stats.registered++ + + case err != nil: + return ids, stats, fmt.Errorf("query agent %s/%s: %w", repoName, spec.Name, err) + + default: + update := existing.Update().SetLastSeenAt(time.Now()) + if existing.ContentHash != hash { + update = update. + SetSourceRef(moduleRef + "/agents/" + spec.QualifiedName()). + SetQualifiedName(spec.QualifiedName()). + SetDescription(spec.Description). + SetModel(string(spec.Model)). + SetIcon(spec.Icon). + SetRole(spec.Role). + SetTools(spec.Tools). + SetAllowedTools(spec.AllowedTools). + SetSkills(spec.Skills). + SetDependencies(spec.Dependencies). + SetRequires(spec.Requires). + SetSourcePath(sourcePath). + SetContentHash(hash) + stats.updated++ + } + saved, uerr := update.Save(ctx) + if uerr != nil { + return ids, stats, fmt.Errorf("update agent %s/%s: %w", repoName, spec.Name, uerr) + } + ids[agentKey{spec.Namespace, spec.Name}] = saved.ID + } + } + + return ids, stats, nil +} + +func syncTeams(ctx context.Context, client *ent.Client, repoName, specDir string, agentIDs map[agentKey]uuid.UUID) (syncStats, error) { + var stats syncStats + moduleRef := moduleRefFromSpecDir(specDir) + + // Unqualified names available in this repo, for Team.ValidateAgentReferences. + // Team specs in these repos reference agents by bare name, never namespaced. + availableAgents := make([]string, 0, len(agentIDs)) + for key := range agentIDs { + if key.namespace == "" { + availableAgents = append(availableAgents, key.name) + } + } + + teamsDir := filepath.Join(specDir, "teams") + entries, err := os.ReadDir(teamsDir) + if err != nil { + if os.IsNotExist(err) { + return stats, nil + } + return stats, fmt.Errorf("read %s: %w", teamsDir, err) + } + + for _, entry := range entries { + if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".json") { + continue + } + + sourcePath := filepath.Join(teamsDir, entry.Name()) + team, err := multiagentspec.LoadTeamFromFile(sourcePath) + if err != nil { + stats.warnings = append(stats.warnings, fmt.Sprintf("%s: load team %s: %v", repoName, entry.Name(), err)) + continue + } + + hash, err := hashFile(sourcePath) + if err != nil { + stats.warnings = append(stats.warnings, fmt.Sprintf("%s: hash team %s: %v", repoName, team.Name, err)) + continue + } + + // Checks the roster, orchestrator, and agent-assigned workflow + // steps in one pass — catches drift my own membership resolution + // below can't see (e.g. a stale orchestrator or workflow step + // name), not just a missing roster entry. + if verr := team.ValidateAgentReferences(availableAgents); verr != nil { + if joined, ok := verr.(interface{ Unwrap() []error }); ok { + for _, sub := range joined.Unwrap() { + stats.warnings = append(stats.warnings, fmt.Sprintf("%s: %v", repoName, sub)) + } + } else { + stats.warnings = append(stats.warnings, fmt.Sprintf("%s: %v", repoName, verr)) + } + } + + var memberIDs []uuid.UUID + for _, agentName := range team.Agents { + if id, ok := agentIDs[agentKey{"", agentName}]; ok { + memberIDs = append(memberIDs, id) + } + } + + existing, err := client.TeamDefinition.Query(). + Where(entteamdef.RepoName(repoName), entteamdef.Name(team.Name)). + Only(ctx) + + switch { + case ent.IsNotFound(err): + teamID := uuid.New() + if _, cerr := client.TeamDefinition.Create(). + SetID(teamID). + SetRegistryXrn("xrn:agentplexus:team-definition:" + teamID.String()). + SetSourceRef(moduleRef + "/teams/" + team.Name). + SetRepoName(repoName). + SetName(team.Name). + SetVersion(team.Version). + SetDescription(team.Description). + SetOrchestrator(team.Orchestrator). + SetAgentNames(team.Agents). + SetSourcePath(sourcePath). + SetContentHash(hash). + AddAgentIDs(memberIDs...). + Save(ctx); cerr != nil { + return stats, fmt.Errorf("create team %s/%s: %w", repoName, team.Name, cerr) + } + stats.registered++ + + case err != nil: + return stats, fmt.Errorf("query team %s/%s: %w", repoName, team.Name, err) + + default: + update := existing.Update().SetLastSeenAt(time.Now()) + if existing.ContentHash != hash { + update = update. + SetSourceRef(moduleRef + "/teams/" + team.Name). + SetVersion(team.Version). + SetDescription(team.Description). + SetOrchestrator(team.Orchestrator). + SetAgentNames(team.Agents). + SetSourcePath(sourcePath). + SetContentHash(hash) + stats.updated++ + } + // Membership resolution depends on the agent registry, not just + // this team file's content, so it must be refreshed on every + // sync: an agent referenced by the roster can be registered (or + // re-identified) after this team file was last seen, and that + // shouldn't require touching team.json to pick up the edge. + update = update.ClearAgents().AddAgentIDs(memberIDs...) + if _, uerr := update.Save(ctx); uerr != nil { + return stats, fmt.Errorf("update team %s/%s: %w", repoName, team.Name, uerr) + } + } + } + + return stats, nil +} + +// repoNameFromSpecDir derives the owning repository name from a spec +// directory path, e.g. ".../agent-team-release/specs" -> "agent-team-release". +func repoNameFromSpecDir(specDir string) string { + return filepath.Base(filepath.Dir(specDir)) +} + +// moduleRefFromSpecDir derives the Go-style module path of the owning +// repository from a spec directory, e.g. +// ".../github.com/plexusone/agent-team-release/specs" -> +// "github.com/plexusone/agent-team-release". It scans for a host-like +// component (one containing a ".") and returns that plus the next two path +// segments (org/repo). If no such segment is found — e.g. a spec dir outside +// the standard GOPATH layout — it falls back to the bare repository name so +// source_ref is always populated with something identifying. +func moduleRefFromSpecDir(specDir string) string { + parts := strings.Split(filepath.ToSlash(filepath.Dir(specDir)), "/") + for i := 0; i+2 < len(parts); i++ { + if strings.Contains(parts[i], ".") { + return strings.Join(parts[i:i+3], "/") + } + } + return repoNameFromSpecDir(specDir) +} + +func hashFile(path string) (string, error) { + data, err := os.ReadFile(path) + if err != nil { + return "", err + } + sum := sha256.Sum256(data) + return hex.EncodeToString(sum[:]), nil +} diff --git a/internal/registry/registry_test.go b/internal/registry/registry_test.go new file mode 100644 index 0000000..050663f --- /dev/null +++ b/internal/registry/registry_test.go @@ -0,0 +1,380 @@ +package registry + +import ( + "context" + "database/sql" + "os" + "path/filepath" + "strings" + "testing" + + "entgo.io/ent/dialect" + entsql "entgo.io/ent/dialect/sql" + _ "modernc.org/sqlite" + + "github.com/plexusone/agentplexus/internal/ent" + entteamdef "github.com/plexusone/agentplexus/internal/ent/teamdefinition" +) + +func newTestClient(t *testing.T) *ent.Client { + t.Helper() + + // Matches internal/storage.NewClient's driver: modernc.org/sqlite + // registers itself under "sqlite", not the CGO "sqlite3" name that + // entsql.Open(dialect.SQLite, ...) assumes. + db, err := sql.Open("sqlite", "file:ent?mode=memory&cache=shared&_pragma=foreign_keys(1)") + if err != nil { + t.Fatalf("open sqlite: %v", err) + } + + drv := entsql.OpenDB(dialect.SQLite, db) + client := ent.NewClient(ent.Driver(drv)) + t.Cleanup(func() { + if err := client.Close(); err != nil { + t.Errorf("close client: %v", err) + } + }) + + ctx := context.Background() + if err := client.Schema.Create(ctx); err != nil { + t.Fatalf("create schema: %v", err) + } + return client +} + +// writeAgent writes a minimal valid multi-agent-spec agent markdown file. +func writeAgent(t *testing.T, dir, name, description string) { + t.Helper() + content := "---\nname: " + name + "\ndescription: " + description + "\nmodel: sonnet\ntools: [Read]\n---\n\nInstructions for " + name + ".\n" + if err := os.WriteFile(filepath.Join(dir, name+".md"), []byte(content), 0o600); err != nil { + t.Fatalf("write agent %s: %v", name, err) + } +} + +// writeTeam writes a minimal valid multi-agent-spec team JSON file named +// "fixture-team" with the given roster. +func writeTeam(t *testing.T, dir string, agents []string) { + t.Helper() + const name, version = "fixture-team", "1.0.0" + agentsJSON := `"` + agents[0] + `"` + for _, a := range agents[1:] { + agentsJSON += `,"` + a + `"` + } + content := `{"name":"` + name + `","version":"` + version + `","agents":[` + agentsJSON + `]}` + if err := os.WriteFile(filepath.Join(dir, name+".json"), []byte(content), 0o600); err != nil { + t.Fatalf("write team %s: %v", name, err) + } +} + +func setupSpecDir(t *testing.T) string { + t.Helper() + specDir := filepath.Join(t.TempDir(), "agent-team-fixture", "specs") + if err := os.MkdirAll(filepath.Join(specDir, "agents"), 0o755); err != nil { + t.Fatalf("mkdir agents: %v", err) + } + if err := os.MkdirAll(filepath.Join(specDir, "teams"), 0o755); err != nil { + t.Fatalf("mkdir teams: %v", err) + } + return specDir +} + +func TestSync_CreatesAgentsAndTeams(t *testing.T) { + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + + writeAgent(t, filepath.Join(specDir, "agents"), "qa", "Quality checks") + writeAgent(t, filepath.Join(specDir, "agents"), "release", "Ships the release") + writeTeam(t, filepath.Join(specDir, "teams"), []string{"qa", "release"}) + + result, err := Sync(ctx, client, []string{specDir}) + if err != nil { + t.Fatalf("Sync: %v", err) + } + if result.AgentsRegistered != 2 { + t.Errorf("AgentsRegistered = %d, want 2", result.AgentsRegistered) + } + if result.TeamsRegistered != 1 { + t.Errorf("TeamsRegistered = %d, want 1", result.TeamsRegistered) + } + if len(result.Warnings) != 0 { + t.Errorf("Warnings = %v, want none", result.Warnings) + } + + team, err := client.TeamDefinition.Query().Where(entteamdef.Name("fixture-team")).WithAgents().Only(ctx) + if err != nil { + t.Fatalf("query team: %v", err) + } + if len(team.Edges.Agents) != 2 { + t.Errorf("team resolved %d agent edges, want 2", len(team.Edges.Agents)) + } +} + +func TestSync_IsIdempotent(t *testing.T) { + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + + writeAgent(t, filepath.Join(specDir, "agents"), "qa", "Quality checks") + writeTeam(t, filepath.Join(specDir, "teams"), []string{"qa"}) + + if _, err := Sync(ctx, client, []string{specDir}); err != nil { + t.Fatalf("first Sync: %v", err) + } + + result, err := Sync(ctx, client, []string{specDir}) + if err != nil { + t.Fatalf("second Sync: %v", err) + } + if result.AgentsRegistered != 0 || result.AgentsUpdated != 0 { + t.Errorf("second sync of unchanged files should be a no-op, got %+v", result) + } + if result.TeamsRegistered != 0 || result.TeamsUpdated != 0 { + t.Errorf("second sync of unchanged files should be a no-op, got %+v", result) + } +} + +func TestSync_DetectsContentChanges(t *testing.T) { + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + + agentsDir := filepath.Join(specDir, "agents") + writeAgent(t, agentsDir, "qa", "Quality checks") + if _, err := Sync(ctx, client, []string{specDir}); err != nil { + t.Fatalf("first Sync: %v", err) + } + + writeAgent(t, agentsDir, "qa", "Quality checks, revised") + result, err := Sync(ctx, client, []string{specDir}) + if err != nil { + t.Fatalf("second Sync: %v", err) + } + if result.AgentsUpdated != 1 { + t.Errorf("AgentsUpdated = %d, want 1", result.AgentsUpdated) + } + + agent, err := client.AgentDefinition.Query().Only(ctx) + if err != nil { + t.Fatalf("query agent: %v", err) + } + if agent.Description != "Quality checks, revised" { + t.Errorf("Description = %q, want updated value", agent.Description) + } +} + +func TestSync_WarnsOnDanglingOrchestratorAndWorkflowStepReferences(t *testing.T) { + // The roster alone is valid (matches the old, narrower check); the + // orchestrator and a workflow step reference agents that don't + // exist anywhere. This is the class of drift the plain roster + // check could never see, and the reason syncTeams now delegates to + // multiagentspec.Team.ValidateAgentReferences instead of just + // walking team.Agents. + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + + writeAgent(t, filepath.Join(specDir, "agents"), "qa", "Quality checks") + teamJSON := `{ + "name": "fixture-team", + "version": "1.0.0", + "agents": ["qa"], + "orchestrator": "release-coordinator", + "workflow": { + "type": "chain", + "steps": [ + {"name": "docs-validation", "agent": "documentation"} + ] + } + }` + if err := os.WriteFile(filepath.Join(specDir, "teams", "fixture-team.json"), []byte(teamJSON), 0o600); err != nil { + t.Fatalf("write team: %v", err) + } + + result, err := Sync(ctx, client, []string{specDir}) + if err != nil { + t.Fatalf("Sync: %v", err) + } + if len(result.Warnings) != 2 { + t.Fatalf("Warnings = %v, want exactly 2 (orchestrator + workflow step)", result.Warnings) + } +} + +func TestSync_WarnsOnDanglingTeamReference(t *testing.T) { + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + + writeAgent(t, filepath.Join(specDir, "agents"), "qa", "Quality checks") + writeTeam(t, filepath.Join(specDir, "teams"), []string{"qa", "ghost"}) + + result, err := Sync(ctx, client, []string{specDir}) + if err != nil { + t.Fatalf("Sync: %v", err) + } + if len(result.Warnings) != 1 { + t.Fatalf("Warnings = %v, want exactly 1", result.Warnings) + } +} + +func TestSync_WarnsOnMalformedAgentFileWithoutAborting(t *testing.T) { + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + + agentsDir := filepath.Join(specDir, "agents") + writeAgent(t, agentsDir, "qa", "Quality checks") + if err := os.WriteFile(filepath.Join(agentsDir, "broken.md"), []byte("not valid frontmatter"), 0o600); err != nil { + t.Fatalf("write broken agent: %v", err) + } + + result, err := Sync(ctx, client, []string{specDir}) + if err != nil { + t.Fatalf("Sync should not abort on a malformed file: %v", err) + } + if result.AgentsRegistered != 1 { + t.Errorf("AgentsRegistered = %d, want 1 (the valid agent, skipping the broken one)", result.AgentsRegistered) + } + if len(result.Warnings) != 1 { + t.Errorf("Warnings = %v, want exactly 1 for the broken file", result.Warnings) + } +} + +func TestSync_PopulatesIdentityFields(t *testing.T) { + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + + writeAgent(t, filepath.Join(specDir, "agents"), "qa", "Quality checks") + writeTeam(t, filepath.Join(specDir, "teams"), []string{"qa"}) + if _, err := Sync(ctx, client, []string{specDir}); err != nil { + t.Fatalf("Sync: %v", err) + } + + agent, err := client.AgentDefinition.Query().Only(ctx) + if err != nil { + t.Fatalf("query agent: %v", err) + } + if want := "xrn:agentplexus:agent-definition:" + agent.ID.String(); agent.RegistryXrn != want { + t.Errorf("agent RegistryXrn = %q, want %q", agent.RegistryXrn, want) + } + if !strings.HasSuffix(agent.SourceRef, "/agents/qa") { + t.Errorf("agent SourceRef = %q, want suffix /agents/qa", agent.SourceRef) + } + + team, err := client.TeamDefinition.Query().Only(ctx) + if err != nil { + t.Fatalf("query team: %v", err) + } + if want := "xrn:agentplexus:team-definition:" + team.ID.String(); team.RegistryXrn != want { + t.Errorf("team RegistryXrn = %q, want %q", team.RegistryXrn, want) + } + if !strings.HasSuffix(team.SourceRef, "/teams/fixture-team") { + t.Errorf("team SourceRef = %q, want suffix /teams/fixture-team", team.SourceRef) + } +} + +// TestSync_IdentityStableAcrossFileRename proves the registry keys on +// (repo, namespace, name), not file path: moving a spec to a new filename +// (same frontmatter name) reuses the existing row and its registry identity. +func TestSync_IdentityStableAcrossFileRename(t *testing.T) { + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + agentsDir := filepath.Join(specDir, "agents") + + writeAgent(t, agentsDir, "qa", "Quality checks") + if _, err := Sync(ctx, client, []string{specDir}); err != nil { + t.Fatalf("first Sync: %v", err) + } + before, err := client.AgentDefinition.Query().Only(ctx) + if err != nil { + t.Fatalf("query agent: %v", err) + } + + // Move the spec to a different filename, keeping identical content + // (same frontmatter name "qa" — writeAgent's exact bytes). + if err := os.Remove(filepath.Join(agentsDir, "qa.md")); err != nil { + t.Fatalf("remove qa.md: %v", err) + } + content := "---\nname: qa\ndescription: Quality checks\nmodel: sonnet\ntools: [Read]\n---\n\nInstructions for qa.\n" + if err := os.WriteFile(filepath.Join(agentsDir, "quality.md"), []byte(content), 0o600); err != nil { + t.Fatalf("write moved agent: %v", err) + } + + result, err := Sync(ctx, client, []string{specDir}) + if err != nil { + t.Fatalf("second Sync: %v", err) + } + if result.AgentsRegistered != 0 { + t.Errorf("a renamed-but-same-identity spec should not register a new agent, got %+v", result) + } + after, err := client.AgentDefinition.Query().Only(ctx) + if err != nil { + t.Fatalf("query agent after move: %v", err) + } + if after.ID != before.ID { + t.Errorf("agent identity changed across file rename: %s -> %s", before.ID, after.ID) + } + if after.RegistryXrn != before.RegistryXrn { + t.Errorf("registry_xrn changed across file rename: %s -> %s", before.RegistryXrn, after.RegistryXrn) + } +} + +func TestSync_MissingSpecSubdirsAreNotErrors(t *testing.T) { + client := newTestClient(t) + ctx := context.Background() + emptyDir := t.TempDir() + + result, err := Sync(ctx, client, []string{emptyDir}) + if err != nil { + t.Fatalf("Sync on a repo with no agents/teams dirs should not error: %v", err) + } + if result.AgentsRegistered != 0 || result.TeamsRegistered != 0 { + t.Errorf("expected no-op result, got %+v", result) + } +} + +func TestSync_RefreshesMembershipEvenWhenTeamFileUnchanged(t *testing.T) { + // Regression test: a team can reference an agent that isn't + // registered yet (e.g. ghost.md doesn't exist when the team is + // first synced). When that agent file later appears, the team's + // membership edge must pick it up even though team.json itself + // never changed and its content hash is identical across syncs. + client := newTestClient(t) + ctx := context.Background() + specDir := setupSpecDir(t) + agentsDir := filepath.Join(specDir, "agents") + + writeAgent(t, agentsDir, "qa", "Quality checks") + writeTeam(t, filepath.Join(specDir, "teams"), []string{"qa", "ghost"}) + + if _, err := Sync(ctx, client, []string{specDir}); err != nil { + t.Fatalf("first Sync: %v", err) + } + + team, err := client.TeamDefinition.Query().Where(entteamdef.Name("fixture-team")).WithAgents().Only(ctx) + if err != nil { + t.Fatalf("query team after first sync: %v", err) + } + if len(team.Edges.Agents) != 1 { + t.Fatalf("after first sync, resolved agent edges = %d, want 1 (ghost isn't registered yet)", len(team.Edges.Agents)) + } + + // "ghost" now gets a spec file. team.json is untouched, so its + // content hash is unchanged — the bug was that membership + // resolution was gated on that hash changing. + writeAgent(t, agentsDir, "ghost", "Was missing, now exists") + + if _, err := Sync(ctx, client, []string{specDir}); err != nil { + t.Fatalf("second Sync: %v", err) + } + + team, err = client.TeamDefinition.Query().Where(entteamdef.Name("fixture-team")).WithAgents().Only(ctx) + if err != nil { + t.Fatalf("query team after second sync: %v", err) + } + if len(team.Edges.Agents) != 2 { + t.Errorf("after ghost is registered, resolved agent edges = %d, want 2", len(team.Edges.Agents)) + } +} diff --git a/internal/server/registry_handlers.go b/internal/server/registry_handlers.go new file mode 100644 index 0000000..61e3abb --- /dev/null +++ b/internal/server/registry_handlers.go @@ -0,0 +1,121 @@ +package server + +import ( + "net/http" + + "github.com/plexusone/agentplexus/internal/registry" +) + +// RegistryAgent is the API response for a registered agent. +type RegistryAgent struct { + ID string `json:"id"` + RegistryXRN string `json:"registry_xrn,omitempty"` + SourceRef string `json:"source_ref,omitempty"` + RepoName string `json:"repo_name"` + Namespace string `json:"namespace,omitempty"` + Name string `json:"name"` + QualifiedName string `json:"qualified_name"` + Description string `json:"description,omitempty"` + Model string `json:"model,omitempty"` + Role string `json:"role,omitempty"` + Tools []string `json:"tools,omitempty"` + Skills []string `json:"skills,omitempty"` + SourcePath string `json:"source_path"` + FirstSeenAt string `json:"first_seen_at"` + LastSeenAt string `json:"last_seen_at"` +} + +// RegistryTeam is the API response for a registered team. +type RegistryTeam struct { + ID string `json:"id"` + RegistryXRN string `json:"registry_xrn,omitempty"` + SourceRef string `json:"source_ref,omitempty"` + RepoName string `json:"repo_name"` + Name string `json:"name"` + Version string `json:"version,omitempty"` + Description string `json:"description,omitempty"` + Orchestrator string `json:"orchestrator,omitempty"` + AgentNames []string `json:"agent_names,omitempty"` + SourcePath string `json:"source_path"` + FirstSeenAt string `json:"first_seen_at"` + LastSeenAt string `json:"last_seen_at"` +} + +// handleListRegistryAgents returns every agent in the registry. +// GET /api/registry/agents +func (s *Server) handleListRegistryAgents(w http.ResponseWriter, r *http.Request) { + agents, err := s.db.AgentDefinition.Query().All(r.Context()) + if err != nil { + http.Error(w, "error querying agents", http.StatusInternalServerError) + return + } + + out := make([]RegistryAgent, 0, len(agents)) + for _, a := range agents { + out = append(out, RegistryAgent{ + ID: a.ID.String(), + RegistryXRN: a.RegistryXrn, + SourceRef: a.SourceRef, + RepoName: a.RepoName, + Namespace: a.Namespace, + Name: a.Name, + QualifiedName: a.QualifiedName, + Description: a.Description, + Model: a.Model, + Role: a.Role, + Tools: a.Tools, + Skills: a.Skills, + SourcePath: a.SourcePath, + FirstSeenAt: a.FirstSeenAt.Format(timeFormat), + LastSeenAt: a.LastSeenAt.Format(timeFormat), + }) + } + + writeJSON(w, http.StatusOK, out) +} + +// handleListRegistryTeams returns every team in the registry, including +// which registered agents each team resolved to. +// GET /api/registry/teams +func (s *Server) handleListRegistryTeams(w http.ResponseWriter, r *http.Request) { + teams, err := s.db.TeamDefinition.Query().WithAgents().All(r.Context()) + if err != nil { + http.Error(w, "error querying teams", http.StatusInternalServerError) + return + } + + out := make([]RegistryTeam, 0, len(teams)) + for _, t := range teams { + out = append(out, RegistryTeam{ + ID: t.ID.String(), + RegistryXRN: t.RegistryXrn, + SourceRef: t.SourceRef, + RepoName: t.RepoName, + Name: t.Name, + Version: t.Version, + Description: t.Description, + Orchestrator: t.Orchestrator, + AgentNames: t.AgentNames, + SourcePath: t.SourcePath, + FirstSeenAt: t.FirstSeenAt.Format(timeFormat), + LastSeenAt: t.LastSeenAt.Format(timeFormat), + }) + } + + writeJSON(w, http.StatusOK, out) +} + +// handleRegistrySync re-scans all spec directories and upserts the +// registry immediately, returning a summary of what changed. +// POST /api/registry/sync +func (s *Server) handleRegistrySync(w http.ResponseWriter, r *http.Request) { + result, err := registry.Sync(r.Context(), s.db, s.specDirs) + if err != nil { + s.logger.Error("registry sync failed", "error", err) + http.Error(w, "error syncing registry", http.StatusInternalServerError) + return + } + writeJSON(w, http.StatusOK, result) +} + +const timeFormat = "2006-01-02T15:04:05Z07:00" diff --git a/internal/server/server.go b/internal/server/server.go index b83888f..1eae346 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -1,6 +1,7 @@ package server import ( + "context" "embed" "fmt" "io/fs" @@ -10,6 +11,7 @@ import ( "time" "github.com/plexusone/agentplexus/internal/ent" + "github.com/plexusone/agentplexus/internal/registry" "github.com/plexusone/agentplexus/internal/watcher" ) @@ -58,6 +60,11 @@ func (s *Server) routes() { s.mux.HandleFunc("PUT /api/views/{id}", s.handleUpdateView) s.mux.HandleFunc("DELETE /api/views/{id}", s.handleDeleteView) + // Registry routes (Agent Workforce inventory) + s.mux.HandleFunc("GET /api/registry/agents", s.handleListRegistryAgents) + s.mux.HandleFunc("GET /api/registry/teams", s.handleListRegistryTeams) + s.mux.HandleFunc("POST /api/registry/sync", s.handleRegistrySync) + // Serve embedded frontend (catch-all for non-API routes) frontendSub, err := fs.Sub(frontendFS, "frontend") if err != nil { @@ -74,6 +81,7 @@ func (s *Server) ListenAndServe() error { } s.watcher = w go s.watcher.Run() + go s.watchRegistrySync() srv := &http.Server{ Addr: fmt.Sprintf(":%d", s.port), @@ -85,6 +93,33 @@ func (s *Server) ListenAndServe() error { return srv.ListenAndServe() } +// watchRegistrySync re-syncs the agent/team registry whenever the spec +// watcher reports a change, so the registry stays current without +// requiring a server restart. A single worker goroutine runs syncs +// serially; bursts of watcher events coalesce into at most one pending +// sync via the buffered signal channel. +func (s *Server) watchRegistrySync() { + dirty := make(chan struct{}, 1) + + go func() { + for range dirty { + result, err := registry.Sync(context.Background(), s.db, s.specDirs) + if err != nil { + s.logger.Error("registry sync failed", "error", err) + continue + } + s.logger.Info("registry synced", "result", result.String()) + } + }() + + for range s.watcher.Events { + select { + case dirty <- struct{}{}: + default: + } + } +} + // Close cleans up server resources. func (s *Server) Close() error { if s.db != nil {