Skip to main content

Interface: StepAiApi

Defined in: packages/workflow-engine/src/core/step-ai.ts:149

Durable AI operations. Every method is memoized through the step ledger: on replay a completed call returns its stored result without contacting the model.

Stored results carry text/object, tokens, cost and reasoning but not the raw SDK object, so anything on the raw result is unavailable after a replay.

Methods​

evaluate()​

evaluate<Q>(id, modelKey, spec, options?, stepOptions?): Promise<AIEvaluateResult<Q>>

Defined in: packages/workflow-engine/src/core/step-ai.ts:187

Answer typed questions about one state with a decision model, durably. The answers are memoised under id, so a stage that replays after a suspension takes the same branch it took the first time instead of asking again and possibly deciding differently.

Type Parameters​

Q​

Q extends Readonly<Record<string, EvaluationQuestion>>

Parameters​

id​

string

modelKey​

ModelKey

spec​

EvaluationSpec<Q>

options?​

EvaluateOptions

stepOptions?​

StepRunOptions

Returns​

Promise<AIEvaluateResult<Q>>


generateObject()​

generateObject<S>(id, modelKey, prompt, schema, options?, stepOptions?): Promise<AIObjectResult<output<S>>>

Defined in: packages/workflow-engine/src/core/step-ai.ts:157

Type Parameters​

S​

S extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

Parameters​

id​

string

modelKey​

ModelKey

prompt​

TextInput

schema​

S

options?​

ObjectOptions<ToolSet>

stepOptions?​

StepRunOptions

Returns​

Promise<AIObjectResult<output<S>>>


generateText()​

generateText(id, modelKey, prompt, options?, stepOptions?): Promise<AITextResult>

Defined in: packages/workflow-engine/src/core/step-ai.ts:150

Parameters​

id​

string

modelKey​

ModelKey

prompt​

TextInput

options?​

TextOptions<ToolSet>

stepOptions?​

StepRunOptions

Returns​

Promise<AITextResult>


map()​

map<TIn, TOut>(id, items, spec): Promise<AiMapResult<TOut>[]>

Defined in: packages/workflow-engine/src/core/step-ai.ts:211

Run one prompt per item under an execution policy (realtime or batch), with schema validation and repair applied identically on both paths. Results are returned in input order.

Type Parameters​

TIn​

TIn

TOut​

TOut = string

Parameters​

id​

string

items​

readonly TIn[]

spec​

AiMapSpec<TIn, TOut>

Returns​

Promise<AiMapResult<TOut>[]>


streamText()​

streamText(id, modelKey, prompt, options?, stepOptions?): Promise<StepStreamResult>

Defined in: packages/workflow-engine/src/core/step-ai.ts:174

Stream one call durably. The first execution streams through ctx.ai.streamText (forwarding onChunk) and stores the final text, tokens, cost and reasoning as a single run step; a replay returns the stored result without contacting the model and calls onChunk once with the whole text, so a consumer that renders incrementally still receives the content. Hosts with an idle-connection timeout (Cloudflare Workers) need this where a non-streaming call would trip the timeout.

Parameters​

id​

string

modelKey​

ModelKey

prompt​

TextInput

options?​

StreamOptions

stepOptions?​

StepRunOptions

Returns​

Promise<StepStreamResult>


transcribe()​

transcribe(id, modelKey, audio, options?, stepOptions?): Promise<AITranscribeResult>

Defined in: packages/workflow-engine/src/core/step-ai.ts:199

Transcribe audio durably. The transcript is memoised under id, so a replay after a suspension neither re-sends the audio nor pays for it again. The audio itself is never stored; only the result is.

Parameters​

id​

string

modelKey​

ModelKey

audio​

TranscriptionAudio

options?​

TranscribeOptions

stepOptions?​

StepRunOptions

Returns​

Promise<AITranscribeResult>