> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Turn

> A running turn: it to observe typed events as they stream, and it (before, after, or instead of iterating) for the .

A running turn: `for await` it to observe typed events as they stream, and
`await` it (before, after, or instead of iterating) for the
[SessionOutcome](https://docs.devin.ai/sdk/reference/interfaces/SessionOutcome.md). Awaiting without iterating consumes the remaining
events internally.

```ts
const turn = session.run("Fix the flaky test");
for await (const event of turn) {
  if (event.type === "tool_call") console.log(event.call.title);
}
const { text, toolCalls } = await turn;
```

```typescript
class Turn implements AsyncIterable<SessionEvent>, PromiseLike<SessionOutcome<T>>
```

## Constructor

```typescript
Turn(updates: AsyncGenerator<SessionUpdate, PromptResult, undefined>, schema?: StandardSchema<T>, accepted?: Promise<void>): Turn<T>
```

### Parameters

**updates** `AsyncGenerator\<SessionUpdate, PromptResult, undefined\>` *required*

**Type:** `AsyncGenerator<SessionUpdate, PromptResult, undefined>`

**schema** `StandardSchema\<T\>`

**Type:** `StandardSchema<T>`

**accepted** `Promise\<void\>`

### Returns

`Turn<T>`

## Properties

**accepted** `Promise\<void\>` *required*

The prompt was accepted, not necessarily completed. ACP v2 acknowledges
explicitly; v1 uses the matching user-message echo, falling back to the
prompt response if the agent does not echo. Rejection before acceptance
rejects this promise; subsequent failures reject the turn's outcome.

## Methods

### \[asyncIterator]\()

```typescript
[asyncIterator](): AsyncIterator<SessionEvent>
```

Stream the turn's typed events (single-pass, from the beginning).

#### Returns

`AsyncIterator<SessionEvent>`

### then()

```typescript
then(onfulfilled?: null | (value: SessionOutcome<T>) => TResult1 | PromiseLike<TResult1>, onrejected?: null | (reason: unknown) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>
```

Resolve the turn's [SessionOutcome](https://docs.devin.ai/sdk/reference/interfaces/SessionOutcome.md) once every event has streamed.

#### Parameters

**onfulfilled** `null | (value: SessionOutcome\<T\>) =\> TResult1 | PromiseLike\<TResult1\>`

**Type:** `null | (value: SessionOutcome<T>) => TResult1 | PromiseLike<TResult1>`

**onrejected** `null | (reason: unknown) =\> TResult2 | PromiseLike\<TResult2\>`

#### Returns

`Promise<TResult1 | TResult2>`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.