- Notifications
You must be signed in to change notification settings - Fork23
feat: addprompt
andapp_id
fields tocoder_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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,8 +2,8 @@ package provider | ||
import ( | ||
"context" | ||
"os" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
@@ -21,13 +21,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" | ||
funcaiTaskResource() *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 { | ||
if idStr := os.Getenv("CODER_TASK_ID"); idStr != "" { | ||
resourceData.SetId(idStr) | ||
} else { | ||
return diag.Errorf("CODER_TASK_ID must be set") | ||
} | ||
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 resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
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 +69,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.", | ||
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 +88,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.", | ||
ForceNew: true, | ||
Optional: true, | ||
Computed: true, | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
ValidateFunc: validation.IsUUID, | ||
ConflictsWith: []string{"sidebar_app"}, | ||
}, | ||
}, | ||
} | ||
} |