Skip to main content
Represents a handler for a graph execution.

Properties

index

readonly index: number
The index of the execution.

Methods

abort

abort(): void
Aborts the graph execution stream, canceling any pending operations. This can be used to interrupt ongoing graph processing and clean up resources.

Returns

void

Example

const { outputStream } = await graph.start(
  new GraphTypes.LLMChatRequest({
    messages: [{ role: 'user', content: 'Tell me a long story' }]
  })
);

// Start processing
const processStream = async () => {
  for await (const result of outputStream) {
    await result.processResponse({
      Content: (response) => console.log(response.content),
    });
  }
};

// Cancel after 5 seconds
setTimeout(() => {
  outputStream.abort();
  console.log('Stream aborted');
}, 5000);

processStream();

[asyncIterator]

"[asyncIterator]"(): AsyncIterator<GraphOutputStreamResponse<any>>
Enables async iteration over graph output responses.

Returns

AsyncIterator<GraphOutputStreamResponse<any>>

next

next(): Promise<GraphOutputStreamResponse<any>>
Handles the response from a node.

Returns

Promise<GraphOutputStreamResponse<any>> A promise that resolves to the response from the node

setOnFinished

setOnFinished(callback: () => void): void
Sets a callback to be called when the stream is finished. This allows automatic cleanup without user intervention.

Parameters

NameTypeDescription
callback() => voidFunction to call when stream ends

Returns

void