-
Notifications
You must be signed in to change notification settings - Fork 23
feat: add prompt and app_id fields to coder_ai_task
#445
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package provider | |
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
|
|
@@ -21,13 +22,43 @@ type AITaskSidebarApp struct { | |
| // TaskPromptParameterName is the name of the parameter which is *required* to be defined when a coder_ai_task is used. | ||
| const TaskPromptParameterName = "AI Prompt" | ||
|
|
||
| func aiTask() *schema.Resource { | ||
| func aiTaskResource() *schema.Resource { | ||
| return &schema.Resource{ | ||
| SchemaVersion: 1, | ||
|
|
||
| Description: "Use this resource to define Coder tasks.", | ||
| CreateContext: func(c context.Context, resourceData *schema.ResourceData, i any) diag.Diagnostics { | ||
| resourceData.SetId(uuid.NewString()) | ||
| if idStr := os.Getenv("CODER_TASK_ID"); idStr != "" { | ||
| resourceData.SetId(idStr) | ||
| } else { | ||
| resourceData.SetId(uuid.NewString()) | ||
| } | ||
|
|
||
| if prompt := os.Getenv("CODER_TASK_PROMPT"); prompt != "" { | ||
| resourceData.Set("prompt", prompt) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question, prompt vs input? I don't personally mind either way as both work. "You give your task an initial prompt and then send new input". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The RFC laid out prompt so I'm tempted to keep it here, I also don't mind either way. |
||
| } else { | ||
| resourceData.Set("prompt", "default") | ||
| } | ||
DanielleMaywood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| var ( | ||
| appID = resourceData.Get("app_id").(string) | ||
| sidebarAppSet = resourceData.Get("sidebar_app").(*schema.Set) | ||
| ) | ||
|
|
||
| if appID == "" && sidebarAppSet.Len() > 0 { | ||
| sidebarApps := sidebarAppSet.List() | ||
| sidebarApp := sidebarApps[0].(map[string]any) | ||
|
|
||
| if id, ok := sidebarApp["id"].(string); ok && id != "" { | ||
| appID = id | ||
| resourceData.Set("app_id", id) | ||
| } | ||
| } | ||
|
|
||
| if appID == "" { | ||
| return diag.Errorf("'app_id' must be set") | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| ReadContext: schema.NoopContext, | ||
|
|
@@ -39,11 +70,13 @@ func aiTask() *schema.Resource { | |
| Computed: true, | ||
| }, | ||
| "sidebar_app": { | ||
| Type: schema.TypeSet, | ||
| Description: "The coder_app to display in the sidebar. Usually a chat interface with the AI agent running in the workspace, like https://github.com/coder/agentapi.", | ||
| ForceNew: true, | ||
| Required: true, | ||
| MaxItems: 1, | ||
| Type: schema.TypeSet, | ||
| Description: "The coder_app to display in the sidebar. Usually a chat interface with the AI agent running in the workspace, like https://github.com/coder/agentapi.", | ||
| Deprecated: "This field has been deprecated in favor of the `app_id` field.", | ||
| ForceNew: true, | ||
| Optional: true, | ||
| MaxItems: 1, | ||
| ConflictsWith: []string{"app_id"}, | ||
| Elem: &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "id": { | ||
|
|
@@ -56,6 +89,20 @@ func aiTask() *schema.Resource { | |
| }, | ||
| }, | ||
| }, | ||
| "prompt": { | ||
| Type: schema.TypeString, | ||
| Description: "The prompt text provided to the task by Coder.", | ||
| Computed: true, | ||
| }, | ||
| "app_id": { | ||
| Type: schema.TypeString, | ||
| Description: "The ID of the coder_app resource that provides the AI interface for this task.", | ||
DanielleMaywood marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ForceNew: true, | ||
| Optional: true, | ||
| Computed: true, | ||
DanielleMaywood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ValidateFunc: validation.IsUUID, | ||
| ConflictsWith: []string{"sidebar_app"}, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to exit with an error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind either.
What would happen if the provider version this lands in is used with an older version of coder? (I guess also do we care?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integration tests will tell us :)
I'd expect that it won't have any effect unless the template defines a
coder_ai_task. In that case, folks can lock their provider version.