Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: make generateSuffix internal
  • Loading branch information
DanielleMaywood committed Aug 20, 2025
commit 620a01b14e0f4d5791a18c76e9133407fc12e7d9
1 change: 0 additions & 1 deletion coderd/aitasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func (api *API) tasksCreate(rw http.ResponseWriter, r *http.Request) {
taskName = generatedName
}
}
taskName += "-" + taskname.GenerateSuffix()

createReq := codersdk.CreateWorkspaceRequest{
Name: taskName,
Expand Down
10 changes: 6 additions & 4 deletions coderd/taskname/taskname.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func GetAnthropicModelFromEnv() anthropic.Model {
return anthropic.Model(os.Getenv("ANTHROPIC_MODEL"))
}

// GenerateSuffix generates a random hex string between `100` and `fff`.
func GenerateSuffix() string {
// generateSuffix generates a random hex string between `100` and `fff`.
func generateSuffix() string {
numMin := 0x100
numMax := 0x1000
//nolint:gosec // We don't need a cryptographically secure random number generator for generating a task name suffix.
Expand All @@ -80,7 +80,9 @@ func GenerateSuffix() string {
}

func GenerateFallback() string {
return "task-" + strings.ReplaceAll(namesgenerator.GetRandomName(0), "_", "-")
name := strings.ReplaceAll(namesgenerator.GetRandomName(0), "_", "-")

return fmt.Sprintf("task-%s-%s", name, generateSuffix())
}

func Generate(ctx context.Context, prompt string, opts ...Option) (string, error) {
Expand Down Expand Up @@ -143,7 +145,7 @@ func Generate(ctx context.Context, prompt string, opts ...Option) (string, error
return "", ErrNoNameGenerated
}

return generatedName, nil
return fmt.Sprintf("%s-%s", generatedName, generateSuffix()), nil
}

func anthropicDataStream(ctx context.Context, client anthropic.Client, model anthropic.Model, input []aisdk.Message) (aisdk.DataStream, error) {
Expand Down
Loading