@@ -24,7 +24,7 @@ const (
24
24
Requirements:
25
25
- Only lowercase letters, numbers, and hyphens
26
26
- Start with "task-"
27
- - Maximum 28 characters total
27
+ - Maximum 27 characters total
28
28
- Descriptive of the main task
29
29
30
30
Examples:
@@ -145,17 +145,24 @@ func Generate(ctx context.Context, prompt string, opts ...Option) (string, error
145
145
return "" , ErrNoNameGenerated
146
146
}
147
147
148
- generatedName := acc .Messages ()[0 ].Content
149
-
150
- if err := codersdk .NameValid (generatedName ); err != nil {
151
- return "" , xerrors .Errorf ("generated name %v not valid: %w" , generatedName , err )
148
+ // We append a suffix to the end of the task name to reduce
149
+ // the chance of collisions. We truncate the task name to
150
+ // to a maximum of 27 bytes, so that when we append the
151
+ // 5 byte suffix (`-` and 4 byte hex sulg), it should
152
+ // remain within the 32 byte workspace name limit.
153
+ taskName := acc .Messages ()[0 ].Content
154
+ taskName = taskName [:min (len (taskName ), 27 )]
155
+ taskName = fmt .Sprintf ("%s-%s" , taskName , generateSuffix ())
156
+
157
+ if err := codersdk .NameValid (taskName ); err != nil {
158
+ return "" , xerrors .Errorf ("generated name %v not valid: %w" , taskName , err )
152
159
}
153
160
154
- if generatedName == "task-unnamed" {
161
+ if taskName == "task-unnamed" {
155
162
return "" , ErrNoNameGenerated
156
163
}
157
164
158
- return fmt .Sprintf ("%s-%s" , generatedName , generateSuffix ()), nil
165
+ return fmt .Sprintf ("%s-%s" , taskName , generateSuffix ()), nil
159
166
}
160
167
161
168
func anthropicDataStream (ctx context.Context , client anthropic.Client , model anthropic.Model , input []aisdk.Message ) (aisdk.DataStream , error ) {
0 commit comments