mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-10-07 16:02:27 +00:00
optimize mainargsignature inference
This commit is contained in:
@@ -71,7 +71,9 @@
|
||||
isDefault.push(k)
|
||||
}
|
||||
})
|
||||
|
||||
await inferArgs(lang, code, schema)
|
||||
|
||||
schema = schema
|
||||
|
||||
isDefault
|
||||
|
||||
@@ -4,7 +4,7 @@ import { inferArgs } from '$lib/infer'
|
||||
import { loadSchema } from '$lib/scripts'
|
||||
import { workspaceStore } from '$lib/stores'
|
||||
import { emptySchema } from '$lib/utils'
|
||||
import { get } from 'svelte/store'
|
||||
import { get, writable } from 'svelte/store'
|
||||
import type { FlowModuleState, FlowState } from './flowState'
|
||||
|
||||
export function cleanInputs(flow: Flow | any): Flow {
|
||||
@@ -74,11 +74,13 @@ export function selectedIdToModuleState(selectedId: string, flow: FlowState): Fl
|
||||
}
|
||||
}
|
||||
|
||||
const loadSchemaLastRun = writable<[string | undefined, Schema]>(undefined)
|
||||
|
||||
export async function loadSchemaFromModule(module: FlowModule): Promise<{
|
||||
input_transforms: Record<string, InputTransform>
|
||||
schema: Schema
|
||||
}> {
|
||||
|
||||
const mod = module.value
|
||||
|
||||
if (mod.type == 'rawscript' || mod.type === 'script') {
|
||||
|
||||
+24
-14
@@ -1,27 +1,37 @@
|
||||
import { ScriptService, type MainArgSignature } from '$lib/gen'
|
||||
import { get, writable } from 'svelte/store'
|
||||
import type { Schema, SchemaProperty } from './common.js'
|
||||
|
||||
const loadSchemaLastRun = writable<[string | undefined, MainArgSignature | undefined]>(undefined)
|
||||
|
||||
|
||||
export async function inferArgs(
|
||||
language: 'python3' | 'deno' | 'go',
|
||||
code: string,
|
||||
schema: Schema
|
||||
): Promise<void> {
|
||||
let lastRun = get(loadSchemaLastRun)
|
||||
let inferedSchema: MainArgSignature
|
||||
if (code == '') { code = ' ' }
|
||||
if (language == 'python3') {
|
||||
inferedSchema = await ScriptService.pythonToJsonschema({
|
||||
requestBody: code
|
||||
})
|
||||
} else if (language == 'deno') {
|
||||
inferedSchema = await ScriptService.denoToJsonschema({
|
||||
requestBody: code
|
||||
})
|
||||
} else if (language == 'go') {
|
||||
inferedSchema = await ScriptService.goToJsonschema({
|
||||
requestBody: code
|
||||
})
|
||||
if (code == lastRun[0] && lastRun[1]) {
|
||||
inferedSchema = lastRun[1]
|
||||
} else {
|
||||
return
|
||||
if (code == '') { code = ' ' }
|
||||
if (language == 'python3') {
|
||||
inferedSchema = await ScriptService.pythonToJsonschema({
|
||||
requestBody: code
|
||||
})
|
||||
} else if (language == 'deno') {
|
||||
inferedSchema = await ScriptService.denoToJsonschema({
|
||||
requestBody: code
|
||||
})
|
||||
} else if (language == 'go') {
|
||||
inferedSchema = await ScriptService.goToJsonschema({
|
||||
requestBody: code
|
||||
})
|
||||
} else {
|
||||
return
|
||||
}
|
||||
loadSchemaLastRun.set([code, inferedSchema])
|
||||
}
|
||||
|
||||
schema.required = []
|
||||
|
||||
Reference in New Issue
Block a user