Skip to content

Commit 2ab771c

Browse files
committed
fix: use default preset when creating a workspace for task
1 parent 7387905 commit 2ab771c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

site/src/pages/TasksPage/TasksPage.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const TaskFormSection: FC<{
192192
);
193193
};
194194

195-
type CreateTaskMutationFnProps = { prompt: string; templateId: string };
195+
type CreateTaskMutationFnProps = { prompt: string; template: Template };
196196

197197
type TaskFormProps = {
198198
templates: Template[];
@@ -201,25 +201,25 @@ type TaskFormProps = {
201201
const TaskForm: FC<TaskFormProps> = ({ templates }) => {
202202
const { user } = useAuthenticated();
203203
const queryClient = useQueryClient();
204-
205204
const [templateId, setTemplateId] = useState<string>(templates[0].id);
205+
const selectedTemplate = templates.find(
206+
(t) => t.id === templateId,
207+
) as Template;
206208
const {
207209
externalAuth,
208210
externalAuthPollingState,
209211
startPollingExternalAuth,
210212
isLoadingExternalAuth,
211213
externalAuthError,
212-
} = useExternalAuth(
213-
templates.find((t) => t.id === templateId)?.active_version_id,
214-
);
214+
} = useExternalAuth(selectedTemplate.active_version_id);
215215

216216
const hasAllRequiredExternalAuth = externalAuth?.every(
217217
(auth) => auth.optional || auth.authenticated,
218218
);
219219

220220
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),
223223
onSuccess: async () => {
224224
await queryClient.invalidateQueries({
225225
queryKey: ["tasks"],
@@ -242,7 +242,7 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => {
242242
try {
243243
await createTaskMutation.mutateAsync({
244244
prompt,
245-
templateId: templateID,
245+
template: selectedTemplate,
246246
});
247247
form.reset();
248248
} catch (error) {
@@ -533,10 +533,15 @@ export const data = {
533533
prompt: string,
534534
userId: string,
535535
templateId: string,
536+
templateVersionId: string,
536537
): Promise<Task> {
538+
const presets = await API.getTemplateVersionPresets(templateVersionId);
539+
const defaultPreset = presets.find((p) => p.Default);
537540
const workspace = await API.createWorkspace(userId, {
538541
name: `task-${generateWorkspaceName()}`,
539542
template_id: templateId,
543+
template_version_id: templateVersionId,
544+
template_version_preset_id: defaultPreset?.ID,
540545
rich_parameter_values: [
541546
{ name: AI_PROMPT_PARAMETER_NAME, value: prompt },
542547
],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy