import type { z } from "zod"; import type { AppRef } from "./apps"; export interface ZapierClient { fetch(url: string, options: { connection?: string; method?: string; headers?: Record; body?: string | Record | null; timeout?: number; }): Promise; } export interface DefineContext { zapier: ZapierClient; } export interface StepOptions { name: string; run: () => Promise; maxAttempts?: number; retryDelaySeconds?: number; outputSchema?: z.ZodSchema; } export interface WaitOptions { name: string; seconds: number; } export interface CallbackOptions { name: string; timeoutSeconds?: number; payloadSchema?: z.ZodSchema; } export type ToolContext = DefineContext; export interface SingleConnectionToolContext extends DefineContext { connection: string; } export interface MultiConnectionToolContext> extends DefineContext { connections: { [K in keyof TConn]: string; }; } export interface DurableContext extends DefineContext { step(name: string, fn: () => Promise): Promise; step(options: StepOptions): Promise; wait(name: string, seconds: number): Promise; wait(options: WaitOptions): Promise; createCallback(name: string): Promise<[Promise, string]>; createCallback(options: CallbackOptions): Promise<[Promise, string]>; } export type ComponentCtx = DefineContext; declare const CONNECTION_BRAND: unique symbol; export type ConnectionId = string & { readonly [CONNECTION_BRAND]: TApp; }; export interface SingleConnExecuteOptions { connection: ConnectionId; } export interface MultiConnExecuteOptions> { connections: { [K in keyof TConn]: ConnectionId; }; } export type RefProxy = { [P in K]: { $ref: P; }; }; export type ResolveDirective = { kind: "options"; tool: unknown; binds?: Record; } | { kind: "schema"; tool: unknown; binds?: Record; }; export interface WithInputDependencies { inputDependencies?: ($: RefProxy & string>) => Record; } export interface WithResultProcessors { options?: (result: unknown) => Array<{ label: string; value: string; }>; schema?: (result: unknown) => z.ZodType; digest?: (result: unknown) => unknown; } export interface DescribeResult { kind: "tool" | "durable" | "component"; name: string; description?: string; inputSchema?: Record; connection?: AppRef; connections?: Record; } export interface ConnectionlessToolConfig extends WithInputDependencies, WithResultProcessors { name: string; description: string; connection?: never; connections?: never; inputSchema: TInput; run: (ctx: ToolContext, input: z.infer) => Promise; } export interface SingleConnToolConfig extends WithInputDependencies, WithResultProcessors { name: string; description: string; connection: TApp; connections?: never; inputSchema: TInput; run: (ctx: SingleConnectionToolContext, input: z.infer) => Promise; } export interface MultiConnToolConfig> extends WithInputDependencies, WithResultProcessors { name: string; description: string; connection?: never; connections: TConn; inputSchema: TInput; run: (ctx: MultiConnectionToolContext, input: z.infer) => Promise; } interface ToolFnMeta | undefined> extends WithInputDependencies, WithResultProcessors { kind: "tool"; name: string; description: string; connection: TConn extends AppRef ? TConn : undefined; connections: TConn extends Record ? TConn : undefined; inputSchema: TInput; run: TConn extends Record ? (ctx: MultiConnectionToolContext, input: z.infer) => Promise : TConn extends AppRef ? (ctx: SingleConnectionToolContext, input: z.infer) => Promise : (ctx: ToolContext, input: z.infer) => Promise; describe(): DescribeResult; } export type ToolFn> = (TConn extends AppRef ? (input: z.infer, opts: SingleConnExecuteOptions) => Promise : TConn extends Record ? (input: z.infer, opts: MultiConnExecuteOptions) => Promise : never) & ToolFnMeta; export type ConnectionlessToolFn = ((input: z.infer) => Promise) & ToolFnMeta; export interface ConnectionlessDurableConfig extends WithInputDependencies { name: string; description: string; connection?: never; connections?: never; inputSchema: TInput; run: (ctx: DurableContext, input: z.infer) => Promise; } export interface SingleConnDurableConfig extends WithInputDependencies { name: string; description: string; connection: TApp; connections?: never; inputSchema: TInput; run: (ctx: DurableContext & { connection: string; }, input: z.infer) => Promise; } export interface MultiConnDurableConfig> extends WithInputDependencies { name: string; description: string; connection?: never; connections: TConn; inputSchema: TInput; run: (ctx: DurableContext & { connections: { [K in keyof TConn]: string; }; }, input: z.infer) => Promise; } export interface DurableResult { done: boolean; result?: T; error?: Error; executionId?: string; } interface DurableFnMeta | undefined> extends WithInputDependencies { kind: "durable"; name: string; description: string; connection: TConn extends AppRef ? TConn : undefined; connections: TConn extends Record ? TConn : undefined; inputSchema: TInput; run: TConn extends Record ? (ctx: DurableContext & { connections: { [K in keyof TConn]: string; }; }, input: z.infer) => Promise : TConn extends AppRef ? (ctx: DurableContext & { connection: string; }, input: z.infer) => Promise : (ctx: DurableContext, input: z.infer) => Promise; describe(): DescribeResult; } export type ConnectionlessDurableFn = ((input: z.infer) => Promise) & DurableFnMeta; export type DurableFn> = (TConn extends AppRef ? (input: z.infer, opts: SingleConnExecuteOptions) => Promise : TConn extends Record ? (input: z.infer, opts: MultiConnExecuteOptions) => Promise : never) & DurableFnMeta; export interface ReservedComponentProps { connection?: never; connections?: never; zapier?: never; } export type AssertNoReservedComponentProps = Extract extends never ? TProps : never; export interface SingleConnectionCtx { connection: ConnectionId; connections?: never; } export interface MultiConnectionCtx> { connection?: never; connections: { [K in keyof TConn]: ConnectionId; }; } export interface ConnectionlessComponentConfig { name: string; description?: string; connection?: never; connections?: never; render: (props: AssertNoReservedComponentProps & ComponentCtx) => unknown; } export interface SingleConnComponentConfig { name: string; description?: string; connection: TApp; connections?: never; render: (props: AssertNoReservedComponentProps & SingleConnectionCtx & ComponentCtx) => unknown; } export interface MultiConnComponentConfig> { name: string; description?: string; connection?: never; connections: TConn; render: (props: AssertNoReservedComponentProps & MultiConnectionCtx & ComponentCtx) => unknown; } export type ComponentConfig = ConnectionlessComponentConfig | SingleConnComponentConfig | MultiConnComponentConfig>; export type ComponentFn = ((props: TProps) => unknown) & { kind: "component"; name: string; description?: string; connection?: AppRef; connections?: Record; describe(): DescribeResult; }; export {}; //# sourceMappingURL=types.d.ts.map