Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve prolems with saved task #1340

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading