mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: create tasks in coderd instead of frontend (#19280)
Instead of creating tasks with a specialized call to `CreateWorkspace` on the frontend, we instead lift this to the backend and allow the frontend to simply call `CreateAITask`.
This commit is contained in:
@@ -3,6 +3,7 @@ package codersdk
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -44,3 +45,29 @@ func (c *ExperimentalClient) AITaskPrompts(ctx context.Context, buildIDs []uuid.
|
||||
var prompts AITasksPromptsResponse
|
||||
return prompts, json.NewDecoder(res.Body).Decode(&prompts)
|
||||
}
|
||||
|
||||
type CreateTaskRequest struct {
|
||||
Name string `json:"name"`
|
||||
TemplateVersionID uuid.UUID `json:"template_version_id" format:"uuid"`
|
||||
TemplateVersionPresetID uuid.UUID `json:"template_version_preset_id,omitempty" format:"uuid"`
|
||||
Prompt string `json:"prompt"`
|
||||
}
|
||||
|
||||
func (c *ExperimentalClient) CreateTask(ctx context.Context, user string, request CreateTaskRequest) (Workspace, error) {
|
||||
res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/experimental/tasks/%s", user), request)
|
||||
if err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusCreated {
|
||||
return Workspace{}, ReadBodyAsError(res)
|
||||
}
|
||||
|
||||
var workspace Workspace
|
||||
if err := json.NewDecoder(res.Body).Decode(&workspace); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
|
||||
return workspace, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user