Skip to content

Commit

Permalink
Resolve prolems with saved task (#1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
wintonzheng authored Dec 6, 2024
1 parent bb03891 commit 18762f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ function CreateNewTaskFormPage() {
dataExtractionGoal:
data.workflow_definition.blocks[0].data_extraction_goal,
extractedInformationSchema: JSON.stringify(dataSchema, null, 2),
navigationPayload,
navigationPayload:
typeof navigationPayload === "string"
? navigationPayload
: JSON.stringify(navigationPayload, null, 2),
maxStepsOverride,
totpIdentifier: data.workflow_definition.blocks[0].totp_identifier,
totpVerificationUrl:
Expand Down
60 changes: 18 additions & 42 deletions skyvern-frontend/src/routes/tasks/create/SavedTaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,61 +43,35 @@ function transform(value: unknown) {
}

function createTaskRequestObject(formValues: SavedTaskFormValues) {
let extractedInformationSchema = null;
if (formValues.extractedInformationSchema) {
try {
extractedInformationSchema = JSON.parse(
formValues.extractedInformationSchema,
);
} catch (e) {
extractedInformationSchema = formValues.extractedInformationSchema;
}
}

let errorCodeMapping = null;
if (formValues.errorCodeMapping) {
try {
errorCodeMapping = JSON.parse(formValues.errorCodeMapping);
} catch (e) {
errorCodeMapping = formValues.errorCodeMapping;
}
}

return {
title: formValues.title,
url: formValues.url,
webhook_callback_url: transform(formValues.webhookCallbackUrl),
navigation_goal: transform(formValues.navigationGoal),
data_extraction_goal: transform(formValues.dataExtractionGoal),
proxy_location: transform(formValues.proxyLocation),
navigation_payload: transform(formValues.navigationPayload),
extracted_information_schema: extractedInformationSchema,
extracted_information_schema: safeParseMaybeJSONString(
formValues.extractedInformationSchema,
),
totp_verification_url: transform(formValues.totpVerificationUrl),
totp_identifier: transform(formValues.totpIdentifier),
error_code_mapping: errorCodeMapping,
error_code_mapping: safeParseMaybeJSONString(formValues.errorCodeMapping),
};
}

function createTaskTemplateRequestObject(values: SavedTaskFormValues) {
let extractedInformationSchema = null;
if (values.extractedInformationSchema) {
try {
extractedInformationSchema = JSON.parse(
values.extractedInformationSchema,
);
} catch (e) {
extractedInformationSchema = values.extractedInformationSchema;
}
}

let errorCodeMapping = null;
if (values.errorCodeMapping) {
function safeParseMaybeJSONString(payload: unknown) {
if (typeof payload === "string") {
try {
errorCodeMapping = JSON.parse(values.errorCodeMapping);
} catch (e) {
errorCodeMapping = values.errorCodeMapping;
return JSON.parse(payload);
} catch {
return payload;
}
}
return payload;
}

function createTaskTemplateRequestObject(values: SavedTaskFormValues) {
return {
title: values.title,
description: values.description,
Expand All @@ -110,7 +84,7 @@ function createTaskTemplateRequestObject(values: SavedTaskFormValues) {
parameter_type: "workflow",
workflow_parameter_type: "json",
key: "navigation_payload",
default_value: JSON.stringify(values.navigationPayload),
default_value: safeParseMaybeJSONString(values.navigationPayload),
},
],
blocks: [
Expand All @@ -120,11 +94,13 @@ function createTaskTemplateRequestObject(values: SavedTaskFormValues) {
url: values.url,
navigation_goal: values.navigationGoal,
data_extraction_goal: values.dataExtractionGoal,
data_schema: extractedInformationSchema,
data_schema: safeParseMaybeJSONString(
values.extractedInformationSchema,
),
max_steps_per_run: values.maxStepsOverride,
totp_verification_url: values.totpVerificationUrl,
totp_identifier: values.totpIdentifier,
error_code_mapping: errorCodeMapping,
error_code_mapping: safeParseMaybeJSONString(values.errorCodeMapping),
},
],
},
Expand Down

0 comments on commit 18762f5

Please sign in to comment.