Skip to content

Interface: PipelineStage

@providerprotocol/ai


@providerprotocol/ai / middleware/pipeline / PipelineStage

Defined in: src/middleware/pipeline/index.ts:100

A single pipeline stage that runs after turn completion.

Stages can mutate the turn object to attach computed properties (like slugs, image URLs, etc.) that will be available in the .then() callback. Use a type assertion to add properties:

// Define extended turn type
interface ExtendedTurn { slug?: string; imageUrl?: string; }
// In stage run function
run: (turn, emit) => {
const slug = generateSlug(turn.data!.title);
(turn as Turn<TData> & ExtendedTurn).slug = slug;
emit({ slug });
}
// Access in .then() callback
model.stream(prompt).then(turn => {
const extended = turn as typeof turn & ExtendedTurn;
console.log(extended.slug); // Available!
});

TData = unknown

Type of the turn’s structured data

run: (turn, emit) => void | Promise<void>

Defined in: src/middleware/pipeline/index.ts:110

Execute this stage.

Turn<TData>

The completed turn (can mutate via type assertion to add properties)

PipelineEmit

Function to emit progress events to subscribers

void | Promise<void>


type: string

Defined in: src/middleware/pipeline/index.ts:102

Unique identifier for this stage (used in events)