diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index 1f59e45857..d0695a7a1d 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -444,7 +444,10 @@ drawerStore: writable(undefined), modulesStore: writable([]), currentStepStore: writable(undefined), - genFlow: undefined + genFlow: undefined, + shouldUpdatePropertyType: writable<{ + [key: string]: 'static' | 'javascript' | undefined + }>({}) } setContext('FlowCopilotContext', flowCopilotContext) @@ -452,7 +455,8 @@ const { drawerStore: copilotDrawerStore, modulesStore: copilotModulesStore, - currentStepStore: copilotCurrentStepStore + currentStepStore: copilotCurrentStepStore, + shouldUpdatePropertyType } = flowCopilotContext let doneTs = 0 @@ -553,6 +557,7 @@ type: 'static', value: undefined } + $shouldUpdatePropertyType[key] = 'static' } } } @@ -716,6 +721,7 @@ Object.keys(flowModule.value.input_transforms), pastModule.value.type === 'rawscript' ? pastModule.value.content : '', pastModule.value.type === 'rawscript' ? pastModule.value.language : undefined, + prevNodeId, isFirstInLoop, abortController ) @@ -747,6 +753,7 @@ type: 'javascript', expr: expr.replaceAll(/flow_input\.([A-Za-z0-9_]+)/g, (_, p1) => 'flow_input.' + p1) } + $shouldUpdatePropertyType[key] = 'javascript' }) } else { if ( @@ -799,6 +806,7 @@ : 'flow_input.' + snakeKey : 'flow_input.' + snakeKey } + $shouldUpdatePropertyType[key] = 'javascript' } } diff --git a/frontend/src/lib/components/InputTransformForm.svelte b/frontend/src/lib/components/InputTransformForm.svelte index ba22807dca..123f7cae51 100644 --- a/frontend/src/lib/components/InputTransformForm.svelte +++ b/frontend/src/lib/components/InputTransformForm.svelte @@ -20,6 +20,7 @@ import { setInputCat as computeInputCat, isCodeInjection } from '$lib/utils' import { FunctionSquare, Plug } from 'lucide-svelte' import { getResourceTypes } from './resourceTypesStore' + import type { FlowCopilotContext } from './copilot/flow' export let schema: Schema export let arg: InputTransform | any @@ -47,11 +48,20 @@ let propertyType = getPropertyType(arg) + const { shouldUpdatePropertyType } = + getContext('FlowCopilotContext') || {} + function updatePropertyType() { - propertyType = arg.type + propertyType = $shouldUpdatePropertyType?.[argName] || 'static' + shouldUpdatePropertyType?.set({ + ...$shouldUpdatePropertyType, + [argName]: undefined + }) } - $: arg?.type && arg.type !== propertyType && updatePropertyType() + $: $shouldUpdatePropertyType?.[argName] && + arg?.type === $shouldUpdatePropertyType?.[argName] && + updatePropertyType() function getPropertyType(arg: InputTransform | any): 'static' | 'javascript' { let type: 'static' | 'javascript' = arg?.type ?? 'static' diff --git a/frontend/src/lib/components/copilot/flow.ts b/frontend/src/lib/components/copilot/flow.ts index 6b5067a53d..c4ca521d98 100644 --- a/frontend/src/lib/components/copilot/flow.ts +++ b/frontend/src/lib/components/copilot/flow.ts @@ -15,7 +15,7 @@ export type FlowCopilotModule = { hubCompletions: { path: string summary: string - kind: HubScriptKind, + kind: HubScriptKind app: string ask_id: number }[] @@ -36,6 +36,9 @@ export type FlowCopilotContext = { modulesStore: Writable currentStepStore: Writable genFlow: ((i: number, modules: FlowModule[], stepOnly?: boolean) => Promise) | undefined + shouldUpdatePropertyType: Writable<{ + [key: string]: 'static' | 'javascript' | undefined + }> } const systemPrompt = `You write code as instructed by the user. Only output code. Wrap the code in a code block. @@ -125,7 +128,7 @@ const gluePrompt = `I'm building a workflow which is a sequence of script steps. My current step code has the following inputs: {inputs}. Determine what to pass as inputs. You can only use the following: - \`flow_input\` (javascript object): general inputs that are passed to the workflow, you can assume any object properties. -- \`prev_output\` (javascript object): previous output is the output of the previous step. {inferTypeGluePrompt} +- \`results.{prevId}\` (javascript object): previous output is the output of the previous step. {inferTypeGluePrompt} Reply in the following format: input_name: expr` @@ -194,6 +197,7 @@ export async function glueCopilot( inputs: string[], prevCode: string, prevLang: Script.language | undefined, + prevId: string, isFirstInLoop: boolean, abortController: AbortController ) { @@ -203,6 +207,7 @@ export async function glueCopilot( role: 'user', content: (isFirstInLoop ? loopGluePrompt : gluePrompt) .replace('{inputs}', inputs.join(', ')) + .replace('{prevId}', prevId) .replace( '{inferTypeGluePrompt}', prevCode.length > 0 && prevLang