ai fallback toggle (#3324)

This commit is contained in:
Jonathan Dobson
2025-08-29 17:21:29 -04:00
committed by GitHub
parent 81d640a3a6
commit bc8e35954f
8 changed files with 59 additions and 29 deletions

View File

@@ -63,6 +63,7 @@ function Debugger() {
: null, : null,
useScriptCache: workflow.generate_script, useScriptCache: workflow.generate_script,
scriptCacheKey: workflow.cache_key, scriptCacheKey: workflow.cache_key,
aiFallback: workflow.ai_fallback,
}; };
const elements = getElements( const elements = getElements(

View File

@@ -64,6 +64,7 @@ function WorkflowEditor() {
: null, : null,
useScriptCache: workflow.generate_script, useScriptCache: workflow.generate_script,
scriptCacheKey: workflow.cache_key, scriptCacheKey: workflow.cache_key,
aiFallback: workflow.ai_fallback,
}; };
const elements = getElements( const elements = getElements(

View File

@@ -83,6 +83,7 @@ function StartNode({ id, data }: NodeProps<StartNode>) {
extraHttpHeaders: data.withWorkflowSettings ? data.extraHttpHeaders : null, extraHttpHeaders: data.withWorkflowSettings ? data.extraHttpHeaders : null,
useScriptCache: data.withWorkflowSettings ? data.useScriptCache : false, useScriptCache: data.withWorkflowSettings ? data.useScriptCache : false,
scriptCacheKey: data.withWorkflowSettings ? data.scriptCacheKey : null, scriptCacheKey: data.withWorkflowSettings ? data.scriptCacheKey : null,
aiFallback: data.withWorkflowSettings ? data.aiFallback : false,
}); });
const [facing, setFacing] = useState<"front" | "back">("front"); const [facing, setFacing] = useState<"front" | "back">("front");
@@ -226,38 +227,57 @@ function StartNode({ id, data }: NodeProps<StartNode>) {
}} }}
/> />
</div> </div>
<OrgWalled className="flex flex-col gap-4"> <OrgWalled className="p-0 hover:p-0">
<div className="space-y-2"> <div className="flex flex-col gap-4">
<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="space-y-2"> <div className="space-y-2">
<div className="flex gap-2"> <div className="flex items-center gap-2">
<Label>Code Key (optional)</Label> <Label>Generate Code</Label>
<HelpTooltip content="A static or dynamic key for directing code generation." /> <HelpTooltip content="Generate & use cached code for faster execution." />
<Switch
className="ml-auto"
checked={inputs.useScriptCache}
onCheckedChange={(value) => {
handleChange("useScriptCache", value);
}}
/>
</div> </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>
)} {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>
</OrgWalled> </OrgWalled>
<div className="space-y-2"> <div className="space-y-2">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">

View File

@@ -14,6 +14,7 @@ export type WorkflowStartNodeData = {
editable: boolean; editable: boolean;
useScriptCache: boolean; useScriptCache: boolean;
scriptCacheKey: string | null; scriptCacheKey: string | null;
aiFallback: boolean;
label: "__start_block__"; label: "__start_block__";
showCode: boolean; showCode: boolean;
}; };

View File

@@ -705,6 +705,7 @@ function getElements(
editable, editable,
useScriptCache: settings.useScriptCache, useScriptCache: settings.useScriptCache,
scriptCacheKey: settings.scriptCacheKey, scriptCacheKey: settings.scriptCacheKey,
aiFallback: settings.aiFallback ?? false,
label: "__start_block__", label: "__start_block__",
showCode: false, showCode: false,
}), }),
@@ -1416,6 +1417,7 @@ function getWorkflowSettings(nodes: Array<AppNode>): WorkflowSettings {
extraHttpHeaders: null, extraHttpHeaders: null,
useScriptCache: false, useScriptCache: false,
scriptCacheKey: null, scriptCacheKey: null,
aiFallback: false,
}; };
const startNodes = nodes.filter(isStartNode); const startNodes = nodes.filter(isStartNode);
const startNodeWithWorkflowSettings = startNodes.find( const startNodeWithWorkflowSettings = startNodes.find(
@@ -1435,6 +1437,7 @@ function getWorkflowSettings(nodes: Array<AppNode>): WorkflowSettings {
extraHttpHeaders: data.extraHttpHeaders, extraHttpHeaders: data.extraHttpHeaders,
useScriptCache: data.useScriptCache, useScriptCache: data.useScriptCache,
scriptCacheKey: data.scriptCacheKey, scriptCacheKey: data.scriptCacheKey,
aiFallback: data.aiFallback,
}; };
} }
return defaultSettings; return defaultSettings;

View File

@@ -510,6 +510,7 @@ export type WorkflowApiResponse = {
deleted_at: string | null; deleted_at: string | null;
generate_script: boolean; generate_script: boolean;
cache_key: string | null; cache_key: string | null;
ai_fallback: boolean | null;
}; };
export type WorkflowSettings = { export type WorkflowSettings = {
@@ -521,6 +522,7 @@ export type WorkflowSettings = {
extraHttpHeaders: string | null; extraHttpHeaders: string | null;
useScriptCache: boolean; useScriptCache: boolean;
scriptCacheKey: string | null; scriptCacheKey: string | null;
aiFallback: boolean | null;
}; };
export type WorkflowModel = JsonObjectExtendable<{ model_name: string }>; export type WorkflowModel = JsonObjectExtendable<{ model_name: string }>;

View File

@@ -16,6 +16,7 @@ export type WorkflowCreateYAMLRequest = {
extra_http_headers?: Record<string, string> | null; extra_http_headers?: Record<string, string> | null;
generate_script?: boolean; generate_script?: boolean;
cache_key?: string | null; cache_key?: string | null;
ai_fallback?: boolean;
}; };
export type WorkflowDefinitionYAML = { export type WorkflowDefinitionYAML = {

View File

@@ -116,6 +116,7 @@ const useWorkflowSave = () => {
extra_http_headers: extraHttpHeaders, extra_http_headers: extraHttpHeaders,
generate_script: saveData.settings.useScriptCache, generate_script: saveData.settings.useScriptCache,
cache_key: normalizedKey, cache_key: normalizedKey,
ai_fallback: saveData.settings.aiFallback ?? undefined,
workflow_definition: { workflow_definition: {
parameters: saveData.parameters, parameters: saveData.parameters,
blocks: saveData.blocks, blocks: saveData.blocks,