@@ -192,7 +192,7 @@ const TaskFormSection: FC<{
192
192
) ;
193
193
} ;
194
194
195
- type CreateTaskMutationFnProps = { prompt : string ; templateId : string } ;
195
+ type CreateTaskMutationFnProps = { prompt : string ; template : Template } ;
196
196
197
197
type TaskFormProps = {
198
198
templates : Template [ ] ;
@@ -201,25 +201,25 @@ type TaskFormProps = {
201
201
const TaskForm : FC < TaskFormProps > = ( { templates } ) => {
202
202
const { user } = useAuthenticated ( ) ;
203
203
const queryClient = useQueryClient ( ) ;
204
-
205
204
const [ templateId , setTemplateId ] = useState < string > ( templates [ 0 ] . id ) ;
205
+ const selectedTemplate = templates . find (
206
+ ( t ) => t . id === templateId ,
207
+ ) as Template ;
206
208
const {
207
209
externalAuth,
208
210
externalAuthPollingState,
209
211
startPollingExternalAuth,
210
212
isLoadingExternalAuth,
211
213
externalAuthError,
212
- } = useExternalAuth (
213
- templates . find ( ( t ) => t . id === templateId ) ?. active_version_id ,
214
- ) ;
214
+ } = useExternalAuth ( selectedTemplate . active_version_id ) ;
215
215
216
216
const hasAllRequiredExternalAuth = externalAuth ?. every (
217
217
( auth ) => auth . optional || auth . authenticated ,
218
218
) ;
219
219
220
220
const createTaskMutation = useMutation ( {
221
- mutationFn : async ( { prompt, templateId } : CreateTaskMutationFnProps ) =>
222
- data . createTask ( prompt , user . id , templateId ) ,
221
+ mutationFn : async ( { prompt, template } : CreateTaskMutationFnProps ) =>
222
+ data . createTask ( prompt , user . id , template . id , template . active_version_id ) ,
223
223
onSuccess : async ( ) => {
224
224
await queryClient . invalidateQueries ( {
225
225
queryKey : [ "tasks" ] ,
@@ -242,7 +242,7 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => {
242
242
try {
243
243
await createTaskMutation . mutateAsync ( {
244
244
prompt,
245
- templateId : templateID ,
245
+ template : selectedTemplate ,
246
246
} ) ;
247
247
form . reset ( ) ;
248
248
} catch ( error ) {
@@ -533,10 +533,15 @@ export const data = {
533
533
prompt : string ,
534
534
userId : string ,
535
535
templateId : string ,
536
+ templateVersionId : string ,
536
537
) : Promise < Task > {
538
+ const presets = await API . getTemplateVersionPresets ( templateVersionId ) ;
539
+ const defaultPreset = presets . find ( ( p ) => p . Default ) ;
537
540
const workspace = await API . createWorkspace ( userId , {
538
541
name : `task-${ generateWorkspaceName ( ) } ` ,
539
542
template_id : templateId ,
543
+ template_version_id : templateVersionId ,
544
+ template_version_preset_id : defaultPreset ?. ID ,
540
545
rich_parameter_values : [
541
546
{ name : AI_PROMPT_PARAMETER_NAME , value : prompt } ,
542
547
] ,
0 commit comments