fix: flow copilot arg types (#2648)

This commit is contained in:
HugoCasa
2023-11-18 13:16:25 +01:00
committed by GitHub
parent c07e9056f1
commit 08c14e51c7
3 changed files with 29 additions and 6 deletions
+10 -2
View File
@@ -444,7 +444,10 @@
drawerStore: writable<Drawer | undefined>(undefined),
modulesStore: writable<FlowCopilotModule[]>([]),
currentStepStore: writable<string | undefined>(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'
}
}
@@ -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 | undefined>('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'
+7 -2
View File
@@ -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<FlowCopilotModule[]>
currentStepStore: Writable<string | undefined>
genFlow: ((i: number, modules: FlowModule[], stepOnly?: boolean) => Promise<void>) | 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