Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch in support overloaded input types on create tool #772

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions packages/inngest/src/components/InngestStepTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,40 @@

import { type InngestExecution } from "./execution/InngestExecution.js";

//
// This gnarly type allows us to infer the types of the arguments for a function
// with up to 4 overloads.
//
// This make step.ai.wrap work with, among other things, the vercel ai sdk generateObject function.
//
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (

Check warning on line 43 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

'UnionToIntersection' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 43 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
k: infer I
) => void
? I
: never;

type GetOverloadArgs<T> = T extends {
(...args: infer A1): any;

Check failure on line 50 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
(...args: infer A2): any;

Check failure on line 51 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
(...args: infer A3): any;

Check failure on line 52 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
(...args: infer A4): any;

Check failure on line 53 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
}
? A1 | A2 | A3 | A4
: T extends {
(...args: infer A1): any;

Check failure on line 57 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
(...args: infer A2): any;

Check failure on line 58 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
(...args: infer A3): any;

Check failure on line 59 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
}
? A1 | A2 | A3
: T extends {
(...args: infer A1): any;

Check failure on line 63 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
(...args: infer A2): any;

Check failure on line 64 in packages/inngest/src/components/InngestStepTools.ts

View workflow job for this annotation

GitHub Actions / inngest: Lint

Unexpected any. Specify a different type
}
? A1 | A2
: T extends (...args: infer A) => any
? A
: never;

export interface FoundStep extends HashedOp {
hashedId: string;
fn?: (...args: unknown[]) => unknown;
Expand Down Expand Up @@ -188,23 +222,8 @@
return createTool<
<TFn extends (...args: Parameters<TFn>) => unknown>(
idOrOptions: StepOptionsOrId,

/**
* The function to run when this step is executed. Can be synchronous or
* asynchronous.
*
* The return value of this function will be the return value of this
* call to `run`, meaning you can return and reason about return data
* for next steps.
*/
fn: TFn,

/**
* Optional input to pass to the function. If this is specified, Inngest
* will keep track of the input for this step and be able to display it
* in the UI.
*/
...input: Parameters<TFn>
...input: GetOverloadArgs<TFn>
) => Promise<
/**
* TODO Middleware can affect this. If run input middleware has returned
Expand Down
Loading