@Summary Update AI task input @ID update-ai-task-input @Security CoderSessionToken @Accept json @Tags Tasks @Param user path string true "Username, user ID, or 'me' for the authenticated user" @Param task path string true "Task ID, or task name" @Param request body codersdk.UpdateTaskInputRequest tr
(rw http.ResponseWriter, r *http.Request)
| 660 | // @Success 204 |
| 661 | // @Router /api/v2/tasks/{user}/{task}/input [patch] |
| 662 | func (api *API) taskUpdateInput(rw http.ResponseWriter, r *http.Request) { |
| 663 | var ( |
| 664 | ctx = r.Context() |
| 665 | task = httpmw.TaskParam(r) |
| 666 | auditor = api.Auditor.Load() |
| 667 | taskResourceInfo = audit.AdditionalFields{} |
| 668 | ) |
| 669 | |
| 670 | aReq, commitAudit := audit.InitRequest[database.TaskTable](rw, &audit.RequestParams{ |
| 671 | Audit: *auditor, |
| 672 | Log: api.Logger, |
| 673 | Request: r, |
| 674 | Action: database.AuditActionWrite, |
| 675 | AdditionalFields: taskResourceInfo, |
| 676 | }) |
| 677 | defer commitAudit() |
| 678 | aReq.Old = task.TaskTable() |
| 679 | aReq.UpdateOrganizationID(task.OrganizationID) |
| 680 | |
| 681 | var req codersdk.UpdateTaskInputRequest |
| 682 | if !httpapi.Read(ctx, rw, r, &req) { |
| 683 | return |
| 684 | } |
| 685 | |
| 686 | if strings.TrimSpace(req.Input) == "" { |
| 687 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 688 | Message: "Task input is required.", |
| 689 | }) |
| 690 | return |
| 691 | } |
| 692 | |
| 693 | var updatedTask database.TaskTable |
| 694 | if err := api.Database.InTx(func(tx database.Store) error { |
| 695 | task, err := tx.GetTaskByID(ctx, task.ID) |
| 696 | if err != nil { |
| 697 | return httperror.NewResponseError(http.StatusInternalServerError, codersdk.Response{ |
| 698 | Message: "Failed to fetch task.", |
| 699 | Detail: err.Error(), |
| 700 | }) |
| 701 | } |
| 702 | |
| 703 | if task.Status != database.TaskStatusPaused { |
| 704 | return httperror.NewResponseError(http.StatusConflict, codersdk.Response{ |
| 705 | Message: "Unable to update task input, task must be paused.", |
| 706 | Detail: "Please stop the task's workspace before updating the input.", |
| 707 | }) |
| 708 | } |
| 709 | |
| 710 | updatedTask, err = tx.UpdateTaskPrompt(ctx, database.UpdateTaskPromptParams{ |
| 711 | ID: task.ID, |
| 712 | Prompt: req.Input, |
| 713 | }) |
| 714 | if err != nil { |
| 715 | return httperror.NewResponseError(http.StatusInternalServerError, codersdk.Response{ |
| 716 | Message: "Failed to update task input.", |
| 717 | Detail: err.Error(), |
| 718 | }) |
| 719 | } |
nothing calls this directly
no test coverage detected