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