Skip to content

Function: definePrompt()

Call Signature

ts
function definePrompt<TContext, S>(name, config): PromptBuilder<TContext>;

Defined in: packages/core/src/prompt/definePrompt.ts:187

Overload 1: Zod schema — full type inference via z.infer<>

typescript
definePrompt<AppContext>('audit', {
    args: z.object({ month: z.string(), strict: z.boolean() }),
    handler: async (ctx, { month, strict }) => { ... }
    //                     ^^^^^  ^^^^^^  ← fully typed!
});

Type Parameters

Type ParameterDefault type
TContextvoid
S extends ZodRawShapeZodRawShape

Parameters

ParameterType
namestring
configPromptConfigBase<TContext> & { args: ZodObject<S>; handler: (ctx, args) => Promise<PromptResult>; }

Returns

PromptBuilder<TContext>

Call Signature

ts
function definePrompt<TContext, T>(name, config): PromptBuilder<TContext>;

Defined in: packages/core/src/prompt/definePrompt.ts:211

Overload 2: JSON-first descriptors — type inference via InferPromptArgs<>

typescript
definePrompt('greet', {
    args: {
        name: { type: 'string', required: true },
        age:  'number',
    } as const,
    handler: async (ctx, { name, age }) => { ... }
    //                     ^^^^  ^^^  ← name: string, age: number!
});

💡 Use as const on the args object for full literal type inference.

Type Parameters

Type ParameterDefault type
TContextvoid
T extends Record<string, PromptParamDef>Record<string, PromptParamDef>

Parameters

ParameterType
namestring
configPromptConfigBase<TContext> & { args: T; handler: (ctx, args) => Promise<PromptResult>; }

Returns

PromptBuilder<TContext>