Place scripts in a folder. After writing, tell the user they can run:
wmill generate-metadata - Generate .script.yaml and .lock files
wmill sync push - Deploy to Windmill
Do NOT run these commands yourself. Instead, inform the user that they should run them.
Use wmill resource-type list --schema to discover available resource types.
TypeScript (Deno)
Deno runtime with npm support via npm: prefix and native Deno libraries.
Structure
Export a single async function called main:
export async function main(param1: string, param2: number) {
// Your code here
return { result: param1, count: param2 };
}
Do not call the main function. Libraries are installed automatically.
相關技能
Resource Types
On Windmill, credentials and configuration are stored in resources and passed as parameters to main.
Use the RT namespace for resource types:
export async function main(stripe: RT.Stripe) {
// stripe contains API key and config from the resource
}
Only use resource types if you need them to satisfy the instructions. Always use the RT namespace.
Before using a resource type, check the rt.d.ts file in the project root to see all available resource types and their fields. This file is generated by wmill resource-type generate-namespace.
Imports
// npm packages use npm: prefix
import Stripe from "npm:stripe";
import { someFunction } from "npm:some-package";
// Deno standard library
import { serve } from "https://deno.land/std/http/server.ts";
Windmill Client
Import the windmill client for platform interactions:
import * as wmill from "windmill-client";
See the SDK documentation for available methods.
Preprocessor Scripts
For preprocessor scripts, the function should be named preprocessor and receives an event parameter:
@returns Job result when completed
*/
async waitJob(jobId: string, verbose: boolean = false): Promise<any>
/**
Get the result of a completed job
@param jobId - ID of the completed job
@returns Job result
*/
async getResult(jobId: string): Promise<any>
/**
Get the result of a job if completed, or its current status
@param jobId - ID of the job
@returns Object with started, completed, success, and result properties
*/
async getResultMaybe(jobId: string): Promise<any>
/**
@deprecated Use runScriptByPathAsync or runScriptByHashAsync instead
*/
async runScriptAsync(path: string | null, hash_: string | null, args: Record<string, any> | null, scheduledInSeconds: number | null = null): Promise<string>
/**
Run a script asynchronously by its path
@param path - Script path in Windmill
@param args - Arguments to pass to the script
@param scheduledInSeconds - Schedule execution for a future time (in seconds)
@returns Job ID of the created job
*/
async runScriptByPathAsync(path: string, args: Record<string, any> | null = null, scheduledInSeconds: number | null = null): Promise<string>
/**
Run a script asynchronously by its hash
@param hash_ - Script hash in Windmill
@param args - Arguments to pass to the script
@param scheduledInSeconds - Schedule execution for a future time (in seconds)
@returns Job ID of the created job
*/
async runScriptByHashAsync(hash_: string, args: Record<string, any> | null = null, scheduledInSeconds: number | null = null): Promise<string>
/**
Run a flow asynchronously by its path
@param path - Flow path in Windmill
@param args - Arguments to pass to the flow
@param scheduledInSeconds - Schedule execution for a future time (in seconds)
@param doNotTrackInParent - If false, tracks state in parent job (only use when fully awaiting the job)
@returns Job ID of the created job
*/
async runFlowAsync(path: string | null, args: Record<string, any> | null, scheduledInSeconds: number | null = null, // can only be set to false if this the job will be fully await and not concurrent with any other job // as otherwise the child flow and its own child will store their state in the parent job which will // lead to incorrectness and failures doNotTrackInParent: boolean = true): Promise<string>
/**
Resolve a resource value in case the default value was picked because the input payload was undefined
@param obj resource value or path of the resource under the format $res:path
@returns resource value
*/
async resolveDefaultResource(obj: any): Promise<any>
/**
Get the state file path from environment variables
@returns State path string
*/
getStatePath(): string
/**
Set a resource value by path
@param path path of the resource to set, default to state path
@param value new value of the resource to set
@param initializeToTypeIfNotExist if the resource does not exist, initialize it with this type
*/
async setResource(value: any, path?: string, initializeToTypeIfNotExist?: string): Promise<void>
/**
Set the state
@param state state to set
@deprecated use setState instead
*/
async setInternalState(state: any): Promise<void>
/**
Set the state
@param state state to set
@param path Optional state resource path override. Defaults to getStatePath().
*/
async setState(state: any, path?: string): Promise<void>
/**
Set the progress
Progress cannot go back and limited to 0% to 99% range
@param percent Progress to set in %
@param jobId? Job to set progress for
*/
async setProgress(percent: number, jobId?: any): Promise<void>
/**
Get the progress
@param jobId? Job to get progress from
@returns Optional clamped between 0 and 100 progress value
*/
async getProgress(jobId?: any): Promise<number | null>
/**
Set a flow user state
@param key key of the state
@param value value of the state
*/
async setFlowUserState(key: string, value: any, errorIfNotPossible?: boolean): Promise<void>
/**
Get a flow user state
@param path path of the variable
*/
async getFlowUserState(key: string, errorIfNotPossible?: boolean): Promise<any>
/**
Get the internal state
@deprecated use getState instead
*/
async getInternalState(): Promise<any>
/**
Get the state shared across executions
@param path Optional state resource path override. Defaults to getStatePath().
*/
async getState(path?: string): Promise<any>
/**
Get a variable by path
@param path path of the variable
@returns variable value
*/
async getVariable(path: string): Promise<string>
/**
Set a variable by path, create if not exist
@param path path of the variable
@param value value of the variable
@param isSecretIfNotExist if the variable does not exist, create it as secret or not (default: false)
@param descriptionIfNotExist if the variable does not exist, create it with this description (default: "")
*/
async setVariable(path: string, value: string, isSecretIfNotExist?: boolean, descriptionIfNotExist?: string): Promise<void>
/**
Build a PostgreSQL connection URL from a database resource
Sign S3 objects to be used by anonymous users in public apps
@param s3objects s3 objects to sign
@returns signed s3 objects
*/
async signS3Objects(s3objects: S3Object[]): Promise<S3Object[]>
/**
Sign S3 object to be used by anonymous users in public apps
@param s3object s3 object to sign
@returns signed s3 object
*/
async signS3Object(s3object: S3Object): Promise<S3Object>
/**
Generate a presigned public URL for an array of S3 objects.
If an S3 object is not signed yet, it will be signed first.
@param s3Objects s3 objects to sign
@returns list of signed public URLs
*/
async getPresignedS3PublicUrls(s3Objects: S3Object[], { baseUrl }: { baseUrl?: string } = {}): Promise<string[]>
/**
Generate a presigned public URL for an S3 object. If the S3 object is not signed yet, it will be signed first.
@param s3Object s3 object to sign
@returns signed public URL
*/
async getPresignedS3PublicUrl(s3Objects: S3Object, { baseUrl }: { baseUrl?: string } = {}): Promise<string>
/**
Get URLs needed for resuming a flow after this step
@param approver approver name
@param flowLevel if true, generate resume URLs for the parent flow instead of the specific step.
This allows pre-approvals that can be consumed by any later suspend step in the same flow.
@returns approval page UI URL, resume and cancel API URLs for resuming the flow
*/
async getResumeUrls(approver?: string, flowLevel?: boolean): Promise<{
approvalPage: string;
resume: string;
cancel: string;
}>
@param {Object} options - The configuration options for the Teams approval request.
@param {string} options.teamName - The Teams team name where the approval request will be sent.
@param {string} options.channelName - The Teams channel name where the approval request will be sent.
@param {string} [options.message] - Optional custom message to include in the Teams approval request.
@param {string} [options.approver] - Optional user ID or name of the approver for the request.
@param {DefaultArgs} [options.defaultArgsJson] - Optional object defining or overriding the default arguments to a form field.
@param {Enums} [options.dynamicEnumsJson] - Optional object overriding the enum default values of an enum form field.
@returns {Promise<void>} Resolves when the Teams approval request is successfully sent.
@throws {Error} If the function is not called within a flow or flow preview.
@throws {Error} If the JobService.getTeamsApprovalPayload call fails.
Usage Example:
await requestInteractiveTeamsApproval({
teamName: "admins-teams",
channelName: "admins-teams-channel",
message: "Please approve this request",
approver: "approver123",
defaultArgsJson: { key1: "value1", key2: 42 },
dynamicEnumsJson: { foo: ["choice1", "choice2"], bar: ["optionA", "optionB"] },
});
Note: This function requires execution within a Windmill flow or flow preview.
*/
async requestInteractiveTeamsApproval({ teamName, channelName, message, approver, defaultArgsJson, dynamicEnumsJson, }: TeamsApprovalOptions): Promise<void>
/**
Parse an S3 object from URI string or record format
@param s3Object - S3 object as URI string (s3://storage/key) or record
@returns S3 object record with storage and s3 key
*/
parseS3Object(s3Object: S3Object): S3ObjectRecord
setWorkflowCtx(ctx: WorkflowCtx | null): void
async sleep(seconds: number): Promise<void>
async step<T>(name: string, fn: () => T | Promise<T>): Promise<T>
/**
Create a task that dispatches to a separate Windmill script.