Skip to content

Commit dac822b

Browse files
authored
refactor: remove deprecated AITaskPromptParameterName constant (#21023)
This removes the deprecated AITaskPromptParameterName constant and all backward compatibility code that was added for v2.28. - Remove AITaskPromptParameterName constant from codersdk/aitasks.go - Remove backward compatibility code in coderd/aitasks.go that populated the "AI Prompt" parameter for templates that defined it - Remove the backward compatibility test (OK AIPromptBackCompat) - Update dbfake to no longer set the AI Prompt parameter - Remove AITaskPromptParameterName from frontend TypeScript types - Remove preset prompt read-only feature from TaskPrompt component - Update docs to reflect that pre-2.28 definition is no longer supported Task prompts are now exclusively stored in the tasks.prompt database column, as introduced in the migration that added the tasks table.
1 parent 7a5c558 commit dac822b

File tree

13 files changed

+37
-174
lines changed

13 files changed

+37
-174
lines changed

coderd/aitasks.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/coder/coder/v2/coderd/rbac/policy"
2929
"github.com/coder/coder/v2/coderd/searchquery"
3030
"github.com/coder/coder/v2/coderd/util/ptr"
31-
"github.com/coder/coder/v2/coderd/util/slice"
3231
"github.com/coder/coder/v2/codersdk"
3332
)
3433

@@ -131,31 +130,10 @@ func (api *API) tasksCreate(rw http.ResponseWriter, r *http.Request) {
131130
}
132131
}
133132

134-
// Check if the template defines the AI Prompt parameter.
135-
templateParams, err := api.Database.GetTemplateVersionParameters(ctx, req.TemplateVersionID)
136-
if err != nil {
137-
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
138-
Message: "Internal error fetching template parameters.",
139-
Detail: err.Error(),
140-
})
141-
return
142-
}
143-
144-
var richParams []codersdk.WorkspaceBuildParameter
145-
if _, hasAIPromptParam := slice.Find(templateParams, func(param database.TemplateVersionParameter) bool {
146-
return param.Name == codersdk.AITaskPromptParameterName
147-
}); hasAIPromptParam {
148-
// Only add the AI Prompt parameter if the template defines it.
149-
richParams = []codersdk.WorkspaceBuildParameter{
150-
{Name: codersdk.AITaskPromptParameterName, Value: req.Input},
151-
}
152-
}
153-
154133
createReq := codersdk.CreateWorkspaceRequest{
155134
Name: taskName,
156135
TemplateVersionID: req.TemplateVersionID,
157136
TemplateVersionPresetID: req.TemplateVersionPresetID,
158-
RichParameterValues: richParams,
159137
}
160138

161139
var owner workspaceOwner

coderd/aitasks_test.go

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestTasks(t *testing.T) {
5757
o(&opt)
5858
}
5959

60-
// Create a template version that supports AI tasks with the AI Prompt parameter.
60+
// Create a template version that supports AI tasks.
6161
taskAppID := uuid.New()
6262
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
6363
Parse: echo.ParseComplete,
@@ -137,7 +137,7 @@ func TestTasks(t *testing.T) {
137137

138138
got, ok := slice.Find(tasks, func(t codersdk.Task) bool { return t.ID == task.ID })
139139
require.True(t, ok, "task should be found in the list")
140-
assert.Equal(t, wantPrompt, got.InitialPrompt, "task prompt should match the AI Prompt parameter")
140+
assert.Equal(t, wantPrompt, got.InitialPrompt, "task prompt should match the input")
141141
assert.Equal(t, task.WorkspaceID.UUID, got.WorkspaceID.UUID, "workspace id should match")
142142
assert.Equal(t, task.WorkspaceName, got.WorkspaceName, "workspace name should match")
143143
// Status should be populated via the tasks_with_status view.
@@ -196,7 +196,7 @@ func TestTasks(t *testing.T) {
196196

197197
assert.Equal(t, task.ID, updated.ID, "task ID should match")
198198
assert.Equal(t, task.Name, updated.Name, "task name should match")
199-
assert.Equal(t, wantPrompt, updated.InitialPrompt, "task prompt should match the AI Prompt parameter")
199+
assert.Equal(t, wantPrompt, updated.InitialPrompt, "task prompt should match the input")
200200
assert.Equal(t, task.WorkspaceID.UUID, updated.WorkspaceID.UUID, "workspace id should match")
201201
assert.Equal(t, task.WorkspaceName, updated.WorkspaceName, "workspace name should match")
202202
assert.Equal(t, ws.LatestBuild.BuildNumber, updated.WorkspaceBuildNumber, "workspace build number should match")
@@ -971,56 +971,6 @@ func TestTasksCreate(t *testing.T) {
971971
require.Len(t, parameters, 0)
972972
})
973973

974-
t.Run("OK AIPromptBackCompat", func(t *testing.T) {
975-
t.Parallel()
976-
977-
var (
978-
ctx = testutil.Context(t, testutil.WaitShort)
979-
980-
taskPrompt = "Some task prompt"
981-
)
982-
983-
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
984-
user := coderdtest.CreateFirstUser(t, client)
985-
986-
// Given: A template with an "AI Prompt" parameter
987-
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
988-
Parse: echo.ParseComplete,
989-
ProvisionApply: echo.ApplyComplete,
990-
ProvisionGraph: []*proto.Response{
991-
{Type: &proto.Response_Graph{Graph: &proto.GraphComplete{
992-
Parameters: []*proto.RichParameter{{Name: codersdk.AITaskPromptParameterName, Type: "string"}},
993-
HasAiTasks: true,
994-
}}},
995-
},
996-
})
997-
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
998-
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
999-
1000-
// When: We attempt to create a Task.
1001-
task, err := client.CreateTask(ctx, "me", codersdk.CreateTaskRequest{
1002-
TemplateVersionID: template.ActiveVersionID,
1003-
Input: taskPrompt,
1004-
})
1005-
require.NoError(t, err)
1006-
require.True(t, task.WorkspaceID.Valid)
1007-
1008-
ws, err := client.Workspace(ctx, task.WorkspaceID.UUID)
1009-
require.NoError(t, err)
1010-
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, ws.LatestBuild.ID)
1011-
1012-
// Then: We expect a workspace to have been created.
1013-
assert.NotEmpty(t, task.Name)
1014-
assert.Equal(t, template.ID, task.TemplateID)
1015-
1016-
// And: We expect it to have the "AI Prompt" parameter correctly set.
1017-
parameters, err := client.WorkspaceBuildParameters(ctx, ws.LatestBuild.ID)
1018-
require.NoError(t, err)
1019-
require.Len(t, parameters, 1)
1020-
assert.Equal(t, codersdk.AITaskPromptParameterName, parameters[0].Name)
1021-
assert.Equal(t, taskPrompt, parameters[0].Value)
1022-
})
1023-
1024974
t.Run("CustomNames", func(t *testing.T) {
1025975
t.Parallel()
1026976

@@ -1147,7 +1097,7 @@ func TestTasksCreate(t *testing.T) {
11471097
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
11481098
user := coderdtest.CreateFirstUser(t, client)
11491099

1150-
// Given: A template without an "AI Prompt" parameter
1100+
// Given: A template without AI task support (no coder_ai_task resource)
11511101
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
11521102
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
11531103
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

coderd/database/dbfake/dbfake.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/coder/coder/v2/coderd/rbac"
2525
"github.com/coder/coder/v2/coderd/telemetry"
2626
"github.com/coder/coder/v2/coderd/wspubsub"
27-
"github.com/coder/coder/v2/codersdk"
2827
"github.com/coder/coder/v2/provisionersdk"
2928
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
3029
)
@@ -130,10 +129,7 @@ func (b WorkspaceBuildBuilder) WithTask(taskSeed database.TaskTable, appSeed *sd
130129
b.taskAppID, err = uuid.Parse(takeFirst(appSeed.Id, uuid.NewString()))
131130
require.NoError(b.t, err)
132131

133-
return b.Params(database.WorkspaceBuildParameter{
134-
Name: codersdk.AITaskPromptParameterName,
135-
Value: b.taskSeed.Prompt,
136-
}).WithAgent(func(a []*sdkproto.Agent) []*sdkproto.Agent {
132+
return b.WithAgent(func(a []*sdkproto.Agent) []*sdkproto.Agent {
137133
a[0].Apps = []*sdkproto.App{
138134
{
139135
Id: b.taskAppID.String(),

codersdk/aitasks.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,8 @@ import (
1010

1111
"github.com/google/uuid"
1212
"golang.org/x/xerrors"
13-
14-
"github.com/coder/terraform-provider-coder/v2/provider"
1513
)
1614

17-
// AITaskPromptParameterName is the name of the parameter used to pass prompts
18-
// to AI tasks.
19-
//
20-
// Deprecated: This constant is deprecated and maintained only for backwards
21-
// compatibility with older templates. Task prompts are now stored directly
22-
// in the tasks.prompt database column. New code should access prompts via
23-
// the Task.InitialPrompt field returned from task endpoints.
24-
//
25-
// This constant will be removed in a future major version. Templates should
26-
// not rely on this parameter name, as the backend will continue to create it
27-
// automatically for compatibility but reads from tasks.prompt.
28-
const AITaskPromptParameterName = provider.TaskPromptParameterName
29-
3015
// CreateTaskRequest represents the request to create a new task.
3116
type CreateTaskRequest struct {
3217
TemplateVersionID uuid.UUID `json:"template_version_id" format:"uuid"`

codersdk/toolsdk/toolsdk_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,6 @@ func TestTools(t *testing.T) {
10171017
ProvisionApply: echo.ApplyComplete,
10181018
ProvisionGraph: []*proto.Response{
10191019
{Type: &proto.Response_Graph{Graph: &proto.GraphComplete{
1020-
Parameters: []*proto.RichParameter{{Name: "AI Prompt", Type: "string"}},
10211020
HasAiTasks: true,
10221021
}}},
10231022
},

docs/ai-coder/ai-bridge/client-config.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ data "coder_workspace_owner" "me" {}
5858
5959
data "coder_workspace" "me" {}
6060
61+
data "coder_task" "me" {}
62+
6163
resource "coder_agent" "dev" {
6264
arch = "amd64"
6365
os = "linux"
@@ -71,15 +73,21 @@ resource "coder_agent" "dev" {
7173
7274
# See https://registry.coder.com/modules/coder/claude-code for more information
7375
module "claude-code" {
74-
count = local.has_ai_prompt ? data.coder_workspace.me.start_count : 0
76+
count = data.coder_task.me.enabled ? data.coder_workspace.me.start_count : 0
7577
source = "dev.registry.coder.com/coder/claude-code/coder"
76-
version = ">= 3.4.0"
78+
version = ">= 4.0.0"
7779
agent_id = coder_agent.dev.id
7880
workdir = "/home/coder/project"
7981
claude_api_key = data.coder_workspace_owner.me.session_token # Use the Coder session token to authenticate with AI Bridge
80-
ai_prompt = data.coder_parameter.ai_prompt.value
82+
ai_prompt = data.coder_task.me.prompt
8183
... # other claude-code configuration
8284
}
85+
86+
# The coder_ai_task resource associates the task to the app.
87+
resource "coder_ai_task" "task" {
88+
count = data.coder_task.me.enabled ? data.coder_workspace.me.start_count : 0
89+
app_id = module.claude-code[0].task_app_id
90+
}
8391
```
8492

8593
## External and Desktop Clients

docs/ai-coder/tasks-migration.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Prior to Coder version 2.28.0, the definition of a Coder task was different to t
88

99
Note that 2 and 3 were generally handled by the `coder/agentapi` Terraform module.
1010

11-
The pre-2.28.0 definition will be supported until the release of 2.29.0. You will need to update your Tasks-enabled templates to continue using Tasks after this release.
11+
> [!IMPORTANT]
12+
> The pre-2.28.0 definition is no longer supported as of Coder 2.30.0. You must update your Tasks-enabled templates to use the new format described below.
1213
1314
You can view an [example migration here](https://github.com/coder/coder/pull/20420). Alternatively, follow the steps below:
1415

@@ -114,7 +115,7 @@ resource "coder_ai_task" "task" {
114115

115116
In v2.28 and above, the following changes were made:
116117

117-
- The explicitly named "AI Prompt" parameter is deprecated. The task prompt is now available in the `coder_ai_task` resource (provider version 2.12 and above) and `coder_task` data source (provider version 2.13 and above).
118+
- The explicitly named "AI Prompt" parameter is no longer supported. The task prompt is now available in the `coder_ai_task` resource (provider version 2.12 and above) and `coder_task` data source (provider version 2.13 and above).
118119
- Modules no longer define the `coder_ai_task` resource. These must be defined explicitly in the template.
119120
- The `sidebar_app` field of the `coder_ai_task` resource is now deprecated. In its place, use `app_id`.
120121

docs/tutorials/quickstart.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,16 @@ Coder maintains the [Tasks on Docker](https://registry.coder.com/templates/coder
268268
coder template push tasks-docker -d . --variable anthropic_api_key="your-api-key"
269269
```
270270

271-
1. **Create the new Workspace**
272-
1. In your Coder Deployment, click **Workspaces** in the upper left hand corner
273-
1. Click **New workspace** and choose **tasks-docker**
274-
1. Fill in the Workspace name. Add in an AI Prompt for Claude Code like "Make the background yellow". Click **Create workspace**
271+
1. **Create a Task**
272+
1. In your Coder deployment, click **Tasks** in the navigation
273+
1. In the "Prompt your AI agent to start a task" box, enter a prompt like "Make the background yellow"
274+
1. Select the **tasks-docker** template from the dropdown and click the submit button
275275
1. **See Tasks in action**
276-
1. Once your workspace is running, click **View tasks** with your workspace. This will bring you to the Tasks view where you can see Claude Code (left panel), preview the sample application, and interact with the code in code-server. You might need to wait for Claude Code to finish changing the background color of the application.
277-
1. Navigate to the **Tasks** tab in the upper left hand corner
276+
1. Your task will appear in the table below. Click on it to open the task view where you can follow the initialization
277+
1. Once active, you'll see Claude Code on the left panel and can preview the sample application or interact with the code in code-server on the right. You might need to wait for Claude Code to finish changing the background color of the application.
278278
1. Try typing in a new request to Claude Code: "make the background red"
279-
1. Let's exit out of this specific Task view, so we can see all the running tasks
280-
1. You can start a new task by prompting in the "Prompt your AI agent to start a task" box. You can select which template to run this from, so tasks-docker here, and that will spin up a new Workspace
279+
1. Click the back arrow to return to the task overview (you can also see all your tasks in the sidebar)
280+
1. You can start a new task from the prompt box at the top of the page
281281

282282
![Tasks changing background color of demo application](../images/screenshots/quickstart-tasks-background-change.png)
283283

provisioner/terraform/provision_test.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"github.com/stretchr/testify/assert"
2121
"github.com/stretchr/testify/require"
2222

23-
"github.com/coder/terraform-provider-coder/v2/provider"
24-
2523
"cdr.dev/slog"
2624
"cdr.dev/slog/sloggers/slogtest"
2725

@@ -941,18 +939,15 @@ func TestProvision(t *testing.T) {
941939
{
942940
Name: "ai-task-multiple-allowed-in-plan",
943941
Files: map[string]string{
944-
"main.tf": fmt.Sprintf(`terraform {
942+
"main.tf": `terraform {
945943
required_providers {
946944
coder = {
947945
source = "coder/coder"
948-
version = ">= 2.7.0"
946+
version = ">= 2.13.0"
949947
}
950948
}
951949
}
952-
data "coder_parameter" "prompt" {
953-
name = "%s"
954-
type = "string"
955-
}
950+
data "coder_task" "me" {}
956951
resource "coder_ai_task" "a" {
957952
sidebar_app {
958953
id = "7128be08-8722-44cb-bbe1-b5a391c4d94b" # fake ID, irrelevant here anyway but needed for validation
@@ -963,7 +958,7 @@ func TestProvision(t *testing.T) {
963958
id = "7128be08-8722-44cb-bbe1-b5a391c4d94b" # fake ID, irrelevant here anyway but needed for validation
964959
}
965960
}
966-
`, provider.TaskPromptParameterName),
961+
`,
967962
},
968963
Request: &proto.PlanRequest{},
969964
Response: &proto.GraphComplete{
@@ -977,14 +972,6 @@ func TestProvision(t *testing.T) {
977972
Type: "coder_ai_task",
978973
},
979974
},
980-
Parameters: []*proto.RichParameter{
981-
{
982-
Name: provider.TaskPromptParameterName,
983-
Type: "string",
984-
Required: true,
985-
FormType: proto.ParameterFormType_INPUT,
986-
},
987-
},
988975
AiTasks: []*proto.AITask{
989976
{
990977
Id: "a",

site/src/api/typesGenerated.ts

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)