diff --git a/frontend/src/lib/components/Dev.svelte b/frontend/src/lib/components/Dev.svelte index 97cb1dabe8..101f576846 100644 --- a/frontend/src/lib/components/Dev.svelte +++ b/frontend/src/lib/components/Dev.svelte @@ -61,7 +61,6 @@ } let flowCopilotContext: FlowCopilotContext = { - currentStepStore: writable(undefined), shouldUpdatePropertyType: writable<{ [key: string]: 'static' | 'javascript' | undefined }>({}), diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index 177c8eefba..9a66ec9370 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -662,7 +662,6 @@ } let flowCopilotContext: FlowCopilotContext = { - currentStepStore: writable(undefined), shouldUpdatePropertyType: writable<{ [key: string]: 'static' | 'javascript' | undefined }>({}), diff --git a/frontend/src/lib/components/ScriptEditor.svelte b/frontend/src/lib/components/ScriptEditor.svelte index 6866f66208..cb00cd807b 100644 --- a/frontend/src/lib/components/ScriptEditor.svelte +++ b/frontend/src/lib/components/ScriptEditor.svelte @@ -600,13 +600,13 @@ path, lastSavedCode, lastDeployedCode, - diffMode, - applyCode: (code) => { - hideDiffMode() - editor?.reviewAndApplyCode(code) - }, - showDiffMode + diffMode }} + applyCode={() => { + hideDiffMode() + editor?.reviewAndApplyCode(code) + }} + {showDiffMode} headerLeft={aiChatHeaderLeft} headerRight={aiChatHeaderRight} /> diff --git a/frontend/src/lib/components/copilot/StepGen.svelte b/frontend/src/lib/components/copilot/StepGen.svelte deleted file mode 100644 index 0ee617ed78..0000000000 --- a/frontend/src/lib/components/copilot/StepGen.svelte +++ /dev/null @@ -1,233 +0,0 @@ - - - (emptyString(x.summary) ? x.path : x.summary + ' (' + x.path + ')')} -/> - -
-
-
- { - if (funcDesc?.length > 2) { - getHubCompletions(funcDesc) - } else { - hubCompletions = [] - } - }} - placeholder="Search {trigger ? 'triggers' : 'scripts'} or AI gen" - /> - {#if funcDesc?.length === 0} - - {/if} -
- {#if !disableAi && funcDesc?.length > 0} -
    -
  • - -
  • -
  • - -
  • -
- {/if} - {#if funcDesc?.length > 0 && filteredItems?.length > 0} -
-

Workspace {trigger ? 'Triggers' : 'Scripts'}

-
    - {#each filteredItems?.slice(0, 3) ?? [] as item (item.path)} -
  • - -
  • - {/each} -
-
- {/if} - {#if hubCompletions.length > 0} -
-

Hub {trigger ? 'Triggers' : 'Scripts'}

-
    - {#each hubCompletions as item (item.path)} -
  • - -
  • - {/each} -
-
- {/if} -
-
diff --git a/frontend/src/lib/components/copilot/chat/AIChat.svelte b/frontend/src/lib/components/copilot/chat/AIChat.svelte index c2bb40469f..b2968ba845 100644 --- a/frontend/src/lib/components/copilot/chat/AIChat.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChat.svelte @@ -40,17 +40,18 @@ lastSavedCode?: string | undefined lastDeployedCode?: string | undefined diffMode: boolean - applyCode: (code: string) => void - showDiffMode: () => void } flowHelpers?: FlowAIChatHelpers & { getFlow: () => OpenFlow } + showDiffMode: () => void + applyCode: (code: string) => void headerLeft?: Snippet headerRight?: Snippet } - let { scriptOptions, flowHelpers, headerLeft, headerRight }: Props = $props() + let { scriptOptions, flowHelpers, applyCode, showDiffMode, headerLeft, headerRight }: Props = + $props() let instructions = $state('') let loading = writable(false) @@ -59,7 +60,6 @@ script: scriptOptions !== undefined, flow: flowHelpers !== undefined }) - $inspect(allowedModes) let mode: 'script' | 'flow' = $state(flowHelpers ? 'flow' : 'script') async function updateMode(currentMode: 'script' | 'flow') { @@ -78,10 +78,25 @@ loading, currentReply, canApplyCode: () => allowedModes.script, - applyCode: scriptOptions?.applyCode ?? (() => {}) + applyCode }) - async function sendRequest(options: { removeDiff?: boolean; addBackCode?: boolean } = {}) { + export async function sendRequest( + options: { + removeDiff?: boolean + addBackCode?: boolean + instructions?: string + mode?: 'script' | 'flow' + lang?: ScriptLang | 'bunnative' + isPreprocessor?: boolean + } = {} + ) { + if (options.mode) { + mode = options.mode + } + if (options.instructions) { + instructions = options.instructions + } if (!instructions.trim()) { return } @@ -112,14 +127,19 @@ throw new Error('No flow helpers passed') } - if (mode === 'script' && !scriptOptions) { + if (mode === 'script' && !scriptOptions && !options.lang) { throw new Error('No script options passed') } + const lang = scriptOptions?.lang ?? options.lang ?? 'bun' + const isPreprocessor = scriptOptions?.path === 'preprocessor' || options.isPreprocessor + const userMessage = mode === 'flow' ? prepareFlowUserMessage(oldInstructions, flowHelpers!.getFlow()) - : await prepareScriptUserMessage(oldInstructions, scriptOptions!.lang, oldSelectedContext) + : await prepareScriptUserMessage(oldInstructions, lang, oldSelectedContext, { + isPreprocessor + }) messages.push({ role: 'user', content: userMessage }) await historyManager.saveChat(displayMessages, messages) @@ -184,9 +204,7 @@ }) } else { const tools: Tool[] = [] - if ( - ['python3', 'php', 'bun', 'deno', 'nativets', 'bunnative'].includes(scriptOptions!.lang) - ) { + if (['python3', 'php', 'bun', 'deno', 'nativets', 'bunnative'].includes(lang)) { tools.push(resourceTypeTool) } if (oldSelectedContext.filter((c) => c.type === 'db').length > 0) { @@ -196,7 +214,7 @@ ...params, tools, helpers: { - getLang: () => scriptOptions!.lang + getLang: () => lang } }) } @@ -260,7 +278,7 @@ addBackCode: options.withCode === false }) if (options.withDiff) { - scriptOptions.showDiffMode() + showDiffMode() } } diff --git a/frontend/src/lib/components/copilot/chat/ProviderModelSelector.svelte b/frontend/src/lib/components/copilot/chat/ProviderModelSelector.svelte index a74dc353e0..6c7068a80c 100644 --- a/frontend/src/lib/components/copilot/chat/ProviderModelSelector.svelte +++ b/frontend/src/lib/components/copilot/chat/ProviderModelSelector.svelte @@ -8,6 +8,7 @@ copilotSessionModel } from '$lib/stores' import { storeLocalSetting } from '$lib/utils' + import { twMerge } from 'tailwind-merge' $: providerModel = $copilotSessionModel ?? $copilotInfo.defaultModel ?? @@ -33,9 +34,12 @@
- {#each $copilotInfo.aiModels.filter((m) => m.model !== providerModel.model) as providerModel} + {#each $copilotInfo.aiModels as providerModel}
@@ -140,7 +148,7 @@ /> {/snippet} - + {/if} diff --git a/frontend/src/lib/components/flows/content/FlowInputsQuick.svelte b/frontend/src/lib/components/flows/content/FlowInputsQuick.svelte index 046c369d47..147f66ac4b 100644 --- a/frontend/src/lib/components/flows/content/FlowInputsQuick.svelte +++ b/frontend/src/lib/components/flows/content/FlowInputsQuick.svelte @@ -9,7 +9,7 @@ import { createEventDispatcher, getContext, onDestroy, onMount } from 'svelte' import type { FlowBuilderWhitelabelCustomUi } from '$lib/components/custom_ui' import PickHubScriptQuick from '../pickers/PickHubScriptQuick.svelte' - import { type Script, type FlowModule, type ScriptLang, type HubScriptKind } from '$lib/gen' + import { type Script, type ScriptLang, type HubScriptKind } from '$lib/gen' import ListFiltersQuick from '$lib/components/home/ListFiltersQuick.svelte' import { Folder, User } from 'lucide-svelte' import type { FlowEditorContext } from '../../flows/types' @@ -31,8 +31,6 @@ export let disableAi = false export let preFilter: 'all' | 'workspace' | 'hub' = 'hub' export let funcDesc: string - export let index: number - export let modules: FlowModule[] export let owners: string[] = [] export let loading = false export let small = false @@ -52,8 +50,6 @@ } let lang: ScriptLang | undefined = undefined - console.log(lang) - let selectedCompletion: HubCompletion | undefined = undefined let filteredWorkspaceItems: (Script & { marked?: string })[] = [] @@ -93,15 +89,24 @@ } async function onGenerate() { - if (!selectedCompletion && !$copilotInfo.enabled) { + if (!$copilotInfo.enabled) { sendUserToast( 'Windmill AI is not enabled, you can activate it in the workspace settings', true ) return } - //TODO gen - dispatch('close') + console.log('ongenerate', selectedKind, lang, funcDesc) + dispatch('new', { + kind: selectedKind, + inlineScript: { + language: lang, + kind: selectedKind, + subkind: 'flow', + summary, + instructions: funcDesc + } + }) } let openScriptSettings = false diff --git a/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte b/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte index 8950f3cfec..5f90e280bd 100644 --- a/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte +++ b/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte @@ -272,6 +272,7 @@ editor, stepId: flowModule.id, showDiffMode, + hideDiffMode, diffMode, lastDeployedCode }) diff --git a/frontend/src/lib/components/flows/flowStateUtils.ts b/frontend/src/lib/components/flows/flowStateUtils.ts index 9c319553d4..6959ff1dd1 100644 --- a/frontend/src/lib/components/flows/flowStateUtils.ts +++ b/frontend/src/lib/components/flows/flowStateUtils.ts @@ -19,6 +19,7 @@ import { loadSchemaFromModule } from './flowInfers' import { nextId } from './flowModuleNextId' import { findNextAvailablePath } from '$lib/path' import type { ExtendedOpenFlow } from './types' +import { emptySchema } from '$lib/utils' export async function loadFlowModuleState(flowModule: FlowModule): Promise { try { @@ -303,11 +304,11 @@ export async function insertNewPreprocessorModule( }, wsScript?: { path: string; summary: string; hash: string | undefined } ) { - var module: FlowModule = { + let module: FlowModule = { id: 'preprocessor', value: { type: 'identity' } } - var state = emptyFlowModuleState() + let state = emptyFlowModuleState() if (inlineScript) { ;[module, state] = await createInlineScriptModule( @@ -330,3 +331,44 @@ export async function insertNewPreprocessorModule( return fss }) } + +export async function insertNewFailureModule( + flowStore: Writable, + flowStateStore: Writable, + inlineScript?: { + language: RawScript['language'] + subkind: 'pgsql' | 'flow' + instructions?: string + }, + wsScript?: { path: string; summary: string; hash: string | undefined } +) { + let module: FlowModule = { + id: 'failure', + value: { type: 'identity' } + } + let state: FlowModuleState = { + schema: emptySchema(), + previewResult: NEVER_TESTED_THIS_FAR + } + + if (inlineScript) { + ;[module, state] = await createInlineScriptModule( + inlineScript.language, + 'failure', + inlineScript.subkind, + 'failure' + ) + } else if (wsScript) { + ;[module, state] = await pickScript(wsScript.path, wsScript.summary, module.id, wsScript.hash) + } + + flowStore.update((fs) => { + fs.value.failure_module = module + return fs + }) + + flowStateStore.update((fss) => { + fss[module.id] = state + return fss + }) +} diff --git a/frontend/src/lib/components/flows/map/FlowErrorHandlerItem.svelte b/frontend/src/lib/components/flows/map/FlowErrorHandlerItem.svelte index f2f755ddb3..8b76fed4e3 100644 --- a/frontend/src/lib/components/flows/map/FlowErrorHandlerItem.svelte +++ b/frontend/src/lib/components/flows/map/FlowErrorHandlerItem.svelte @@ -1,58 +1,43 @@ @@ -62,23 +47,18 @@ id="flow-editor-error-handler" class={classNames( 'z-10', - $copilotCurrentStepStore !== undefined ? 'border-gray-500/75' : 'cursor-pointer', - 'border transition-colors duration-[400ms] ease-linear rounded-sm px-2 py-1 gap-2 bg-surface text-sm flex items-center flex-row', + 'cursor-pointer border transition-colors duration-[400ms] ease-linear rounded-sm px-2 py-1 gap-2 bg-surface text-sm flex items-center flex-row', $selectedId?.includes('failure') ? 'outline outline-offset-1 outline-2 outline-slate-900 dark:outline-slate-900/0 dark:bg-surface-secondary dark:border-gray-400' : '' )} style="min-width: {small ? '200px' : '230px'}; max-width: 275px;" on:click={() => { - if ($copilotCurrentStepStore !== undefined) return if ($flowStore?.value?.failure_module) { $selectedId = 'failure' } }} > - {#if $copilotCurrentStepStore !== undefined} -
- {/if}
@@ -100,10 +80,10 @@ index={0} placement={'top-center'} on:new={(e) => { - insertNewFailureModule(e.detail.inlineScript) + insertFailureModule(e.detail.inlineScript) }} on:pickScript={(e) => { - insertNewFailureModule(undefined, e.detail) + insertFailureModule(undefined, e.detail) }} kind="failure" /> diff --git a/frontend/src/lib/components/flows/map/FlowModuleSchemaItem.svelte b/frontend/src/lib/components/flows/map/FlowModuleSchemaItem.svelte index 64358cc7a6..1e036c00b9 100644 --- a/frontend/src/lib/components/flows/map/FlowModuleSchemaItem.svelte +++ b/frontend/src/lib/components/flows/map/FlowModuleSchemaItem.svelte @@ -1,5 +1,4 @@ @@ -41,7 +36,6 @@ {selected} {selectable} {id} - onTop={label === 'Input' && $copilotCurrentStepStore === 'Input'} on:select let:hover > diff --git a/frontend/src/lib/components/flows/types.ts b/frontend/src/lib/components/flows/types.ts index 592c3f67a8..b5cb1205fb 100644 --- a/frontend/src/lib/components/flows/types.ts +++ b/frontend/src/lib/components/flows/types.ts @@ -49,6 +49,7 @@ export type FlowEditorContext = { type: 'script' editor: Editor showDiffMode: () => void + hideDiffMode: () => void diffMode: boolean lastDeployedCode: string | undefined } diff --git a/frontend/src/lib/components/graph/FlowGraphV2.svelte b/frontend/src/lib/components/graph/FlowGraphV2.svelte index 6fa84591f2..2965f3cee7 100644 --- a/frontend/src/lib/components/graph/FlowGraphV2.svelte +++ b/frontend/src/lib/components/graph/FlowGraphV2.svelte @@ -117,7 +117,7 @@ function onModulesChange(modules: FlowModule[]) { computeSimplifiableFlow( modules, - triggerContext?.simplifiedPoll ? get(triggerContext.simplifiedPoll) ?? false : false + triggerContext?.simplifiedPoll ? (get(triggerContext.simplifiedPoll) ?? false) : false ) } @@ -160,13 +160,13 @@ position: { x: des.x ? // @ts-ignore - (des.data.data.offset ?? 0) + - // @ts-ignore - des.x + - (fullSize ? fullWidth : width) / 2 - - boxSize.width / 2 - - NODE.width / 2 - - (width - fullWidth) / 2 + (des.data.data.offset ?? 0) + + // @ts-ignore + des.x + + (fullSize ? fullWidth : width) / 2 - + boxSize.width / 2 - + NODE.width / 2 - + (width - fullWidth) / 2 : 0, y: des.y || 0 } diff --git a/frontend/src/lib/components/graph/graphBuilder.ts b/frontend/src/lib/components/graph/graphBuilder.ts index 0011106ade..01a45f4696 100644 --- a/frontend/src/lib/components/graph/graphBuilder.ts +++ b/frontend/src/lib/components/graph/graphBuilder.ts @@ -166,7 +166,7 @@ export function graphBuilder( disableMoveIds: options?.disableMoveIds, enableTrigger: sourceId === 'Input', // If the index is -1, it means that the target module is not in the modules array, so we set it to the length of the array - index: index >= 0 ? index : mods?.length ?? 0, + index: index >= 0 ? index : (mods?.length ?? 0), ...extra, insertable: extra.insertable && !options?.disableInsert && prefix == undefined } diff --git a/frontend/src/lib/components/graph/renderers/nodes/TriggersNode.svelte b/frontend/src/lib/components/graph/renderers/nodes/TriggersNode.svelte index 667c0e0904..958d07f971 100644 --- a/frontend/src/lib/components/graph/renderers/nodes/TriggersNode.svelte +++ b/frontend/src/lib/components/graph/renderers/nodes/TriggersNode.svelte @@ -93,7 +93,6 @@ }} selected={$selectedId == 'triggers'} newItem={data.newFlow} - modules={data.modules} /> {:else} {/snippet}