Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cli/testdata/coder_provisioner_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"last_seen_at": "====[timestamp]=====",
"name": "test-daemon",
"version": "v0.0.0-devel",
"api_version": "1.18",
"api_version": "1.19",
"provisioners": [
"echo"
],
Expand Down
8 changes: 3 additions & 5 deletions docs/ai-coder/agents/tasks-to-chats-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,9 @@ unused when the chat is driven by the Chats API:
}
```

> [!TIP]
> You do not have to remove these resources immediately. Templates can
> serve both Tasks and Chats simultaneously during a transition period.
> The Tasks-specific resources are simply unused when work comes through
> the Chats API.
> [!IMPORTANT]
> Remove the Tasks-specific Terraform when you upgrade.
> Tasks and Chats can no longer run side by side: Coder no longer injects `CODER_TASK_ID` or `CODER_TASK_PROMPT`, so builds of a template that keeps the `coder_task` data source can no longer populate it.

See
[Template Optimization](./platform-controls/template-optimization.md)
Expand Down
10 changes: 2 additions & 8 deletions provisioner/echo/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ func (*echo) Graph(sess *provisionersdk.Session, req *proto.GraphRequest, cancel
sess.ProvisionLog(log.Level, log.Output)
}
if complete := response.GetGraph(); complete != nil {
if len(complete.AiTasks) > 0 {
// These two fields are linked; if there are AI tasks, indicate that.
complete.HasAiTasks = true
}
return complete
}
}
Expand Down Expand Up @@ -426,10 +422,8 @@ func TarWithOptions(ctx context.Context, logger slog.Logger, responses *Response
responses.ProvisionPlan = []*proto.Response{{
Type: &proto.Response_Plan{
Plan: &proto.PlanComplete{
Plan: []byte("{}"),
//nolint:gosec // the number of resources will not exceed int32
AiTaskCount: int32(len(g.GetAiTasks())),
DailyCost: dailycost,
Plan: []byte("{}"),
DailyCost: dailycost,
},
},
}}
Expand Down
1 change: 0 additions & 1 deletion provisioner/terraform/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ func (e *executor) plan(ctx, killCtx context.Context, env, vars []string, logr l
Plan: planJSON,
DailyCost: state.DailyCost,
ResourceReplacements: resReps,
AiTaskCount: state.AITaskCount,
}

return msg, nil
Expand Down
12 changes: 3 additions & 9 deletions provisioner/terraform/planresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

type PlanState struct {
DailyCost int32
AITaskCount int32
DailyCost int32
}

func planModules(plan *tfjson.Plan) []*tfjson.StateModule {
Expand All @@ -35,19 +34,15 @@ func ConvertPlanState(plan *tfjson.Plan) (*PlanState, error) {
modules := planModules(plan)

var dailyCost int32
var aiTaskCount int32
for _, mod := range modules {
err := forEachResource(mod, func(res *tfjson.StateResource) error {
switch res.Type {
case "coder_metadata":
if res.Type == "coder_metadata" {
var attrs resourceMetadataAttributes
err := mapstructure.Decode(res.AttributeValues, &attrs)
if err != nil {
return xerrors.Errorf("decode metadata attributes: %w", err)
}
dailyCost += attrs.DailyCost
case "coder_ai_task":
aiTaskCount++
}
return nil
})
Expand All @@ -57,8 +52,7 @@ func ConvertPlanState(plan *tfjson.Plan) (*PlanState, error) {
}

return &PlanState{
DailyCost: dailyCost,
AITaskCount: aiTaskCount,
DailyCost: dailyCost,
}, nil
}

Expand Down
4 changes: 0 additions & 4 deletions provisioner/terraform/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ func (s *server) Graph(
Parameters: state.Parameters,
ExternalAuthProviders: state.ExternalAuthProviders,
Presets: state.Presets,
HasAiTasks: state.HasAITasks,
AiTasks: state.AITasks,
HasExternalAgents: state.HasExternalAgents,
}
}
Expand Down Expand Up @@ -379,8 +377,6 @@ func provisionEnv(
"CODER_WORKSPACE_TEMPLATE_NAME="+metadata.GetTemplateName(),
"CODER_WORKSPACE_TEMPLATE_VERSION="+metadata.GetTemplateVersion(),
"CODER_WORKSPACE_BUILD_ID="+metadata.GetWorkspaceBuildId(),
"CODER_TASK_ID="+metadata.GetTaskId(),
"CODER_TASK_PROMPT="+metadata.GetTaskPrompt(),
awsSDKUserAgentEnv(safeEnvironValue(env, awsSDKUserAgentEnvKey)),
)
if metadata.GetPrebuiltWorkspaceBuildStage().IsPrebuild() {
Expand Down
86 changes: 0 additions & 86 deletions provisioner/terraform/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,59 +937,6 @@ func TestProvision(t *testing.T) {
}},
},
},
{
Name: "ai-task-multiple-allowed-in-plan",
Files: map[string]string{
"main.tf": `terraform {
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.13.0"
}
}
}
data "coder_task" "me" {}
resource "coder_ai_task" "a" {
sidebar_app {
id = "7128be08-8722-44cb-bbe1-b5a391c4d94b" # fake ID, irrelevant here anyway but needed for validation
}
}
resource "coder_ai_task" "b" {
sidebar_app {
id = "7128be08-8722-44cb-bbe1-b5a391c4d94b" # fake ID, irrelevant here anyway but needed for validation
}
}
`,
},
Request: &proto.PlanRequest{},
Response: &proto.GraphComplete{
Resources: []*proto.Resource{
{
Name: "a",
Type: "coder_ai_task",
},
{
Name: "b",
Type: "coder_ai_task",
},
},
AiTasks: []*proto.AITask{
{
Id: "a",
SidebarApp: &proto.AITaskSidebarApp{
Id: "7128be08-8722-44cb-bbe1-b5a391c4d94b",
},
},
{
Id: "b",
SidebarApp: &proto.AITaskSidebarApp{
Id: "7128be08-8722-44cb-bbe1-b5a391c4d94b",
},
},
},
HasAiTasks: true,
},
},
{
Name: "external-agent",
Files: map[string]string{
Expand All @@ -1014,38 +961,6 @@ func TestProvision(t *testing.T) {
HasExternalAgents: true,
},
},
{
Name: "ai-task-app-id",
Files: map[string]string{
"main.tf": `terraform {
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.12.0"
}
}
}
resource "coder_ai_task" "my-task" {
app_id = "7128be08-8722-44cb-bbe1-b5a391c4d94b" # fake ID, irrelevant here anyway but needed for validation
}
`,
},
Response: &proto.GraphComplete{
Resources: []*proto.Resource{
{
Name: "my-task",
Type: "coder_ai_task",
},
},
AiTasks: []*proto.AITask{
{
Id: "my-task",
AppId: "7128be08-8722-44cb-bbe1-b5a391c4d94b",
},
},
HasAiTasks: true,
},
},
{
Name: "malicious-tar",
Files: map[string]string{
Expand Down Expand Up @@ -1173,7 +1088,6 @@ func TestProvision(t *testing.T) {
require.Equal(t, string(modulesWant), string(modulesGot))
}

require.Equal(t, graphComplete.HasAiTasks, testCase.Response.HasAiTasks)
require.Equal(t, graphComplete.HasExternalAgents, testCase.Response.HasExternalAgents)
}

Expand Down
31 changes: 0 additions & 31 deletions provisioner/terraform/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ type State struct {
Parameters []*proto.RichParameter
Presets []*proto.Preset
ExternalAuthProviders []*proto.ExternalAuthProviderResource
AITasks []*proto.AITask
HasAITasks bool
HasExternalAgents bool
}

Expand Down Expand Up @@ -209,7 +207,6 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
// Extra array to preserve the order of rich parameters.
tfResourcesRichParameters := make([]*tfjson.StateResource, 0)
tfResourcesPresets := make([]*tfjson.StateResource, 0)
tfResourcesAITasks := make([]*tfjson.StateResource, 0)
var findTerraformResources func(mod *tfjson.StateModule)
findTerraformResources = func(mod *tfjson.StateModule) {
for _, module := range mod.ChildModules {
Expand All @@ -222,9 +219,6 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
if resource.Type == "coder_workspace_preset" {
tfResourcesPresets = append(tfResourcesPresets, resource)
}
if resource.Type == "coder_ai_task" {
tfResourcesAITasks = append(tfResourcesAITasks, resource)
}

label := convertAddressToLabel(resource.Address)
if tfResourcesByLabel[label] == nil {
Expand Down Expand Up @@ -996,29 +990,6 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
return nil, xerrors.Errorf("a maximum of 1 coder_workspace_preset can be marked as default, but %d are set", defaultPresets)
}

// This will only pick up resources which will actually be created.
aiTasks := make([]*proto.AITask, 0, len(tfResourcesAITasks))
for _, resource := range tfResourcesAITasks {
var task provider.AITask
err = mapstructure.Decode(resource.AttributeValues, &task)
if err != nil {
return nil, xerrors.Errorf("decode coder_ai_task attributes: %w", err)
}

appID := task.AppID
if appID == "" && len(task.SidebarApp) > 0 {
appID = task.SidebarApp[0].ID
}

aiTasks = append(aiTasks, &proto.AITask{
Id: task.ID,
AppId: appID,
SidebarApp: &proto.AITaskSidebarApp{
Id: appID,
},
})
}

// A map is used to ensure we don't have duplicates!
externalAuthProvidersMap := map[string]*proto.ExternalAuthProviderResource{}
// Process the legacy coder_git_auth type first so that
Expand Down Expand Up @@ -1068,8 +1039,6 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
Parameters: parameters,
Presets: presets,
ExternalAuthProviders: externalAuthProviders,
HasAITasks: len(aiTasks) > 0,
AITasks: aiTasks,
HasExternalAgents: hasExternalAgentResources(graph),
}, nil
}
Expand Down
Loading
Loading