Skip to content

Interface: AskFunction()

Defined in: packages/core/src/core/elicitation/ask.ts:99

The ask type — both a callable function and a namespace.

This interface describes the shape of the ask export. TypeScript sees it as (message, fields) => Promise<AskResponse> with static methods .string(), .number(), .boolean(), .enum(), .redirect().

ts
AskFunction<T>(message, fields): Promise<AskResponse<InferAskFields<T>>>;

Defined in: packages/core/src/core/elicitation/ask.ts:121

Ask the user for structured input via a client-rendered form.

Fields are defined with ask.* descriptors — no raw JSON Schema. Return type is fully inferred from the field descriptors.

Type Parameters

Type Parameter
T extends Record<string, AskField<any>>

Parameters

ParameterTypeDescription
messagestringHuman-readable prompt shown to the user
fieldsTObject of ask.* field descriptors

Returns

Promise<AskResponse<InferAskFields<T>>>

AskResponse<T> with .accepted, .declined, .data

Throws

when called outside .interactive() context

Example

typescript
const prefs = await ask('Configure your account:', {
    name: ask.string('Display name'),
    plan: ask.enum(['free', 'pro'] as const, 'Plan'),
});

Methods

boolean()

ts
boolean(description?): AskBooleanField;

Defined in: packages/core/src/core/elicitation/ask.ts:154

Create a boolean field descriptor.

Parameters

ParameterTypeDescription
description?stringHuman-readable label

Returns

AskBooleanField

AskBooleanField for chaining

Example

ts
`ask.boolean('Accept terms').default(true)`

enum()

ts
enum<V>(values, description?): AskEnumField<V>;

Defined in: packages/core/src/core/elicitation/ask.ts:165

Create an enum field descriptor with type-safe literal union inference.

Type Parameters

Type Parameter
V extends string

Parameters

ParameterTypeDescription
valuesreadonly [V, V]Allowed values (as const for literal types)
description?stringHuman-readable label

Returns

AskEnumField<V>

AskEnumField<V> for chaining

Example

ts
`ask.enum(['us-east-1', 'eu-west-1'] as const, 'Region')`

number()

ts
number(description?): AskNumberField;

Defined in: packages/core/src/core/elicitation/ask.ts:144

Create a number field descriptor.

Parameters

ParameterTypeDescription
description?stringHuman-readable label

Returns

AskNumberField

AskNumberField with .min(), .max() chainable

Example

ts
`ask.number('Team size').min(1).max(500)`

redirect()

ts
redirect(message, url): Promise<AskResponse<void>>;

Defined in: packages/core/src/core/elicitation/ask.ts:184

Redirect the user to an external URL (OAuth, payment, credentials).

Use for sensitive operations that MUST NOT be handled via form fields.

Parameters

ParameterTypeDescription
messagestringExplanation of why the redirect is needed
urlstringThe URL to open in the user's browser

Returns

Promise<AskResponse<void>>

AskResponse<void> with .accepted / .declined

Throws

when called outside .interactive() context

Example

typescript
const auth = await ask.redirect('Authenticate with GitHub:', oauthUrl);
if (auth.declined) return f.error('CANCELLED', 'Auth cancelled');

string()

ts
string(description?): AskStringField;

Defined in: packages/core/src/core/elicitation/ask.ts:134

Create a string field descriptor.

Parameters

ParameterTypeDescription
description?stringHuman-readable label

Returns

AskStringField

AskStringField for chaining

Example

ts
`ask.string('Your full name')`