rothnic
rothnic5d ago

Using Types as Inputs to Script

One thing I've always found to be confusing is why we can't reuse a type for the input definition for a script. For example, to make the input inference work for this example, I'd need to copy and paste the RelativeDateConfig definition and replace the type reference with it for gt and lt. Maybe I'm just missing how you'd expect this to be handled.
export type RelativeDateConfig = {label: "today", hours?: number, days?: number} | {label: "now"} | {label: "custom", value: string};

export async function main(
filterObj: {},
dateFieldConfigs: {
field: string,
gt?: RelativeDateConfig,
lt?: RelativeDateConfig
}[]
) {
export type RelativeDateConfig = {label: "today", hours?: number, days?: number} | {label: "now"} | {label: "custom", value: string};

export async function main(
filterObj: {},
dateFieldConfigs: {
field: string,
gt?: RelativeDateConfig,
lt?: RelativeDateConfig
}[]
) {
In this example, the UI will render an input for a generic object, rather than the type definition that is inferred correctly if i were to duplicate the code and replace the reference. This feels bad from a DRY standpoint. While I'm here, I also wish that for these kinds of types we might want to reuse across the project, we could define just reusable types within windmill. This would be something different than defining a new Resource Type. I know we could import them from another script, but it feels like that is a lot less discoverable in the project UI.
2 Replies
rothnic
rothnicOP5d ago
One additional issue related to this i ran into is it seems that there must not be a system prompt provided to the LLM when generating code because it tries this approach over and over of defining an input type and reusing it across multiple input properties
Hugo
Hugo4d ago
@Farhad could you check and update the prompt to make sure it inlines the type definition? Hi, we should be able to make it work if the type definition is in the same script however, it's a bit harder if it's imported from elsewhere

Did you find this page helpful?