Skip to content

refactor: create tasks in coderd instead of frontend #19280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: names used
  • Loading branch information
DanielleMaywood committed Aug 11, 2025
commit 08cab33360af1e6caadc8567ba4111dc51591bac
6 changes: 3 additions & 3 deletions coderd/aitasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ func (api *API) aiTasksCreate(rw http.ResponseWriter, r *http.Request) {
return
}

hasAIPrompt, err := api.Database.GetTemplateVersionHasAIPrompt(ctx, req.TemplateVersionID)
hasAITask, err := api.Database.GetTemplateVersionHasAITask(ctx, req.TemplateVersionID)
if err != nil {
if errors.Is(err, sql.ErrNoRows) || rbac.IsUnauthorizedError(err) {
httpapi.ResourceNotFound(rw)
return
}

httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching if template version has ai prompt.",
Message: "Internal error fetching whether the template version has an AI task.",
Detail: err.Error(),
})
return
}
if !hasAIPrompt {
if !hasAITask {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: `Template does not have required parameter "` + codersdk.AITaskPromptParameterName + `"`,
})
Expand Down
6 changes: 3 additions & 3 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -2874,15 +2874,15 @@ func (q *querier) GetTemplateVersionByTemplateIDAndName(ctx context.Context, arg
return tv, nil
}

func (q *querier) GetTemplateVersionHasAIPrompt(ctx context.Context, id uuid.UUID) (bool, error) {
func (q *querier) GetTemplateVersionHasAITask(ctx context.Context, id uuid.UUID) (bool, error) {
// If we can successfully call `GetTemplateVersionByID`, then
// we know the actor has sufficient permissions to know if the
// template has an AI Prompt.
// template has an AI task.
if _, err := q.GetTemplateVersionByID(ctx, id); err != nil {
return false, err
}

return q.db.GetTemplateVersionHasAIPrompt(ctx, id)
return q.db.GetTemplateVersionHasAITask(ctx, id)
}

func (q *querier) GetTemplateVersionParameters(ctx context.Context, templateVersionID uuid.UUID) ([]database.TemplateVersionParameter, error) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ func (s *MethodTestSuite) TestTemplate() {
})
check.Args(now.Add(-time.Hour)).Asserts(rbac.ResourceTemplate.All(), policy.ActionRead)
}))
s.Run("GetTemplateVersionHasAIPrompt", s.Subtest(func(db database.Store, check *expects) {
s.Run("GetTemplateVersionHasAITask", s.Subtest(func(db database.Store, check *expects) {
o := dbgen.Organization(s.T(), db, database.Organization{})
u := dbgen.User(s.T(), db, database.User{})
t := dbgen.Template(s.T(), db, database.Template{
Expand Down
6 changes: 3 additions & 3 deletions coderd/database/dbmetrics/querymetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/queries/templateversions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ WHERE
template_versions.id IN (archived_versions.id)
RETURNING template_versions.id;

-- name: GetTemplateVersionHasAIPrompt :one
-- name: GetTemplateVersionHasAITask :one
SELECT EXISTS (
SELECT 1
FROM template_versions
Expand Down
2 changes: 1 addition & 1 deletion codersdk/aitasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type CreateAITasksRequest struct {
}

func (c *ExperimentalClient) AITasksCreate(ctx context.Context, request CreateAITasksRequest) (Workspace, error) {
res, err := c.Request(ctx, http.MethodPost, "/api/experimental/aitasks/", request)
res, err := c.Request(ctx, http.MethodPost, "/api/experimental/aitasks", request)
if err != nil {
return Workspace{}, err
}
Expand Down