accept ai_fallback for new workflows (#3358)

This commit is contained in:
Jonathan Dobson
2025-09-04 12:20:22 -04:00
committed by GitHub
parent f3392899e2
commit 3299a9fcdd
5 changed files with 143 additions and 128 deletions

View File

@@ -48,6 +48,7 @@ import {
MAX_SCREENSHOT_SCROLLS_DEFAULT,
MAX_STEPS_DEFAULT,
} from "@/routes/workflows/editor/nodes/Taskv2Node/types";
import { OrgWalled } from "@/components/Orgwalled";
function createTemplateTaskFromTaskGenerationParameters(
values: TaskGenerationApiResponse,
@@ -470,22 +471,23 @@ function PromptBox() {
/>
</div>
</div>
<div className="flex gap-16">
<div className="w-48 shrink-0">
<div className="text-sm">Generate Script</div>
<div className="text-xs text-slate-400">
Whether to generate scripts for this task run (on
success).
<OrgWalled className="p-0">
<div className="flex gap-16">
<div className="w-48 shrink-0">
<div className="text-sm">Generate Script</div>
<div className="text-xs text-slate-400">
Whether to generate scripts for this task run (on
success).
</div>
</div>
<Switch
checked={generateScript}
onCheckedChange={(checked) => {
setGenerateScript(Boolean(checked));
}}
/>
</div>
<Switch
checked={generateScript}
onCheckedChange={(checked) => {
setGenerateScript(Boolean(checked));
}}
/>
</div>
</OrgWalled>
<div className="flex gap-16">
<div className="w-48 shrink-0">
<div className="text-sm">Publish Workflow</div>

View File

@@ -30,6 +30,7 @@ import { useWorkflowHasChangesStore } from "@/store/WorkflowHasChangesStore";
import { cn } from "@/util/utils";
import { WorkflowApiResponse } from "../types/workflowTypes";
import { CacheKeyValuesResponse } from "@/routes/workflows/types/scriptTypes";
import { OrgWalled } from "@/components/Orgwalled";
interface Dom {
input: React.MutableRefObject<HTMLInputElement | null>;
@@ -125,62 +126,64 @@ function WorkflowHeader({
<div className="flex h-full items-center justify-end gap-4">
{user && workflow.generate_script && (
// (cacheKeyValues?.total_count ?? 0) > 0 && (
<div
tabIndex={1}
className="flex max-w-[15rem] items-center justify-center gap-1 rounded-md border border-input pr-1 focus-within:ring-1 focus-within:ring-ring"
>
<Input
ref={dom.input}
className="focus-visible:transparent focus-visible:none h-[2.75rem] text-ellipsis whitespace-nowrap border-none focus-visible:outline-none focus-visible:ring-0"
onChange={(e) => {
setChosenCacheKeyValue(e.target.value);
onCacheKeyValuesFilter(e.target.value);
}}
onMouseDown={() => {
if (!cacheKeyValuesPanelOpen) {
onCacheKeyValuesClick();
}
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
const numFiltered = cacheKeyValues?.values?.length ?? 0;
if (numFiltered === 1) {
const first = cacheKeyValues?.values?.[0];
if (first) {
setChosenCacheKeyValue(first);
onCacheKeyValueAccept(first);
}
return;
<OrgWalled className="p-0">
<div
tabIndex={1}
className="flex max-w-[15rem] items-center justify-center gap-1 rounded-md border border-input pr-1 focus-within:ring-1 focus-within:ring-ring"
>
<Input
ref={dom.input}
className="focus-visible:transparent focus-visible:none h-[2.75rem] text-ellipsis whitespace-nowrap border-none focus-visible:outline-none focus-visible:ring-0"
onChange={(e) => {
setChosenCacheKeyValue(e.target.value);
onCacheKeyValuesFilter(e.target.value);
}}
onMouseDown={() => {
if (!cacheKeyValuesPanelOpen) {
onCacheKeyValuesClick();
}
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
const numFiltered = cacheKeyValues?.values?.length ?? 0;
setChosenCacheKeyValue(chosenCacheKeyValue);
onCacheKeyValueAccept(chosenCacheKeyValue);
}
onCacheKeyValuesKeydown(e);
}}
placeholder="Code Key Value"
value={chosenCacheKeyValue ?? undefined}
onBlur={(e) => {
onCacheKeyValuesBlurred(e.target.value);
setChosenCacheKeyValue(e.target.value);
}}
/>
{cacheKeyValuesPanelOpen ? (
<ChevronUpIcon
className="h-6 w-6 cursor-pointer"
onClick={onCacheKeyValuesClick}
/>
) : (
<ChevronDownIcon
className="h-6 w-6 cursor-pointer"
onClick={() => {
dom.input.current?.focus();
onCacheKeyValuesClick();
if (numFiltered === 1) {
const first = cacheKeyValues?.values?.[0];
if (first) {
setChosenCacheKeyValue(first);
onCacheKeyValueAccept(first);
}
return;
}
setChosenCacheKeyValue(chosenCacheKeyValue);
onCacheKeyValueAccept(chosenCacheKeyValue);
}
onCacheKeyValuesKeydown(e);
}}
placeholder="Code Key Value"
value={chosenCacheKeyValue ?? undefined}
onBlur={(e) => {
onCacheKeyValuesBlurred(e.target.value);
setChosenCacheKeyValue(e.target.value);
}}
/>
)}
</div>
{cacheKeyValuesPanelOpen ? (
<ChevronUpIcon
className="h-6 w-6 cursor-pointer"
onClick={onCacheKeyValuesClick}
/>
) : (
<ChevronDownIcon
className="h-6 w-6 cursor-pointer"
onClick={() => {
dom.input.current?.focus();
onCacheKeyValuesClick();
}}
/>
)}
</div>
</OrgWalled>
)}
{isGlobalWorkflow ? (
<Button

View File

@@ -7,6 +7,7 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { DotsHorizontalIcon } from "@radix-ui/react-icons";
import { OrgWalled } from "@/components/Orgwalled";
type Props = {
isDeletable?: boolean;
@@ -44,14 +45,18 @@ function NodeActionMenu({
Delete Block
</DropdownMenuItem>
)}
{isScriptable && onShowScript && (
<DropdownMenuItem
onSelect={() => {
onShowScript();
}}
>
{showScriptText ?? "Show Code"}
</DropdownMenuItem>
{isScriptable && (
<OrgWalled className="p-0">
{onShowScript && (
<DropdownMenuItem
onSelect={() => {
onShowScript();
}}
>
{showScriptText ?? "Show Code"}
</DropdownMenuItem>
)}
</OrgWalled>
)}
</DropdownMenuContent>
</DropdownMenu>

View File

@@ -30,6 +30,7 @@ import { ModelSelector } from "@/components/ModelSelector";
import { WorkflowModel } from "@/routes/workflows/types/workflowTypes";
import { MAX_SCREENSHOT_SCROLLS_DEFAULT } from "../Taskv2Node/types";
import { KeyValueInput } from "@/components/KeyValueInput";
import { OrgWalled } from "@/components/Orgwalled";
import { placeholders } from "@/routes/workflows/editor/helpContent";
import { useToggleScriptForNodeCallback } from "@/routes/workflows/hooks/useToggleScriptForNodeCallback";
import { useWorkflowSettingsStore } from "@/store/WorkflowSettingsStore";
@@ -162,16 +163,18 @@ function StartNode({ id, data }: NodeProps<StartNode>) {
<div className="relative">
<div className="absolute right-[-0.5rem] top-[-0.25rem]">
<div>
<Button variant="link" size="icon" onClick={showAllScripts}>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<LightningBoltIcon className="h-4 w-4 text-[gold]" />
</TooltipTrigger>
<TooltipContent>Show all code</TooltipContent>
</Tooltip>
</TooltipProvider>
</Button>
<OrgWalled className="p-0">
<Button variant="link" size="icon" onClick={showAllScripts}>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<LightningBoltIcon className="h-4 w-4 text-[gold]" />
</TooltipTrigger>
<TooltipContent>Show all code</TooltipContent>
</Tooltip>
</TooltipProvider>
</Button>
</OrgWalled>
</div>
</div>
<header className="mb-6 mt-2">Start</header>
@@ -224,57 +227,58 @@ function StartNode({ id, data }: NodeProps<StartNode>) {
}}
/>
</div>
<div className="flex flex-col gap-4">
<div className="space-y-2">
<div className="flex items-center gap-2">
<Label>Generate Code</Label>
<HelpTooltip content="Generate & use cached code for faster execution." />
<Switch
className="ml-auto"
checked={inputs.useScriptCache}
onCheckedChange={(value) => {
handleChange("useScriptCache", value);
}}
/>
</div>
</div>
{inputs.useScriptCache && (
<div className="flex flex-col gap-4 rounded-md bg-slate-elevation4 p-4 pl-4">
<div className="space-y-2">
<div className="flex gap-2">
<Label>Code Key (optional)</Label>
<HelpTooltip content="A static or dynamic key for directing code generation." />
</div>
<WorkflowBlockInputTextarea
nodeId={id}
onChange={(value) => {
const v = value.length ? value : null;
handleChange("scriptCacheKey", v);
<OrgWalled className="p-0 hover:p-0">
<div className="flex flex-col gap-4">
<div className="space-y-2">
<div className="flex items-center gap-2">
<Label>Generate Code</Label>
<HelpTooltip content="Generate & use cached code for faster execution." />
<Switch
className="ml-auto"
checked={inputs.useScriptCache}
onCheckedChange={(value) => {
handleChange("useScriptCache", value);
}}
value={inputs.scriptCacheKey ?? ""}
placeholder={
placeholders["scripts"]["scriptKey"]
}
className="nopan text-xs"
/>
</div>
<div className="space-y-2">
<div className="flex items-center gap-2">
<Label>Fallback To AI On Failure</Label>
<HelpTooltip content="If cached code fails, fallback to AI." />
<Switch
className="ml-auto"
checked={inputs.aiFallback}
onCheckedChange={(value) => {
handleChange("aiFallback", value);
</div>
{inputs.useScriptCache && (
<div className="flex flex-col gap-4 rounded-md bg-slate-elevation4 p-4 pl-4">
<div className="space-y-2">
<div className="flex gap-2">
<Label>Code Key (optional)</Label>
<HelpTooltip content="A static or dynamic key for directing code generation." />
</div>
<WorkflowBlockInputTextarea
nodeId={id}
onChange={(value) => {
const v = value.length ? value : null;
handleChange("scriptCacheKey", v);
}}
value={inputs.scriptCacheKey ?? ""}
placeholder={
placeholders["scripts"]["scriptKey"]
}
className="nopan text-xs"
/>
</div>
<div className="space-y-2">
<div className="flex items-center gap-2">
<Label>Fallback To AI On Failure</Label>
<HelpTooltip content="If cached code fails, fallback to AI." />
<Switch
className="ml-auto"
checked={inputs.aiFallback}
onCheckedChange={(value) => {
handleChange("aiFallback", value);
}}
/>
</div>
</div>
</div>
</div>
)}
</div>
)}
</div>
</OrgWalled>
<div className="space-y-2">
<div className="flex items-center gap-2">
<Label>Save &amp; Reuse Session</Label>

View File

@@ -1701,6 +1701,7 @@ class WorkflowService:
status=request.status,
generate_script=request.generate_script,
cache_key=request.cache_key,
ai_fallback=request.ai_fallback,
)
# Keeping track of the new workflow id to delete it if an error occurs during the creation process
new_workflow_id = workflow.workflow_id