Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/export-tool-call-state-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

Export `ToolCallState` type from the `ai` package. This is a string union type representing all possible states of a tool call invocation (`input-streaming`, `input-available`, `approval-requested`, `approval-responded`, `output-available`, `output-error`, `output-denied`). It can be used to type helper functions, component props, and other constructs that work with tool call states.
15 changes: 15 additions & 0 deletions content/docs/07-reference/01-ai-sdk-core/31-ui-message.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ type ReasoningUIPart = {
};
```

### `ToolCallState`

A type representing the possible states of a tool invocation within a `ToolUIPart`.

```typescript
type ToolCallState =
| 'input-streaming'
| 'input-available'
| 'approval-requested'
| 'approval-responded'
| 'output-available'
| 'output-error'
| 'output-denied';
```

### `ToolUIPart`

A tool part of a message that represents tool invocations and their results.
Expand Down
1 change: 1 addition & 0 deletions packages/ai/src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export {
type SourceUrlUIPart,
type StepStartUIPart,
type TextUIPart,
type ToolCallState,
type ToolUIPart,
type UIDataTypes,
type UIMessage,
Expand Down
13 changes: 13 additions & 0 deletions packages/ai/src/ui/ui-messages.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expectTypeOf } from 'vitest';
import { ToolCallState } from './ui-messages';

// test ToolCallState type
expectTypeOf<ToolCallState>().toEqualTypeOf<
| 'input-streaming'
| 'input-available'
| 'approval-requested'
| 'approval-responded'
| 'output-available'
| 'output-error'
| 'output-denied'
>();
20 changes: 20 additions & 0 deletions packages/ai/src/ui/ui-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ export function isDataUIPart<DATA_TYPES extends UIDataTypes>(
return part.type.startsWith('data-');
}

/**
* The possible states of a tool call invocation.
*
* - `input-streaming`: The tool call input is still being streamed.
* - `input-available`: The tool call input is fully available.
* - `approval-requested`: The tool call requires user approval before execution.
* - `approval-responded`: The user has responded to the approval request.
* - `output-available`: The tool call has completed and output is available.
* - `output-error`: The tool call has completed with an error.
* - `output-denied`: The tool call was denied by the user.
*/
export type ToolCallState =
| 'input-streaming'
| 'input-available'
| 'approval-requested'
| 'approval-responded'
| 'output-available'
| 'output-error'
| 'output-denied';

/**
* A UI tool invocation contains all the information needed to render a tool invocation in the UI.
* It can be derived from a tool without knowing the tool name, and can be used to define
Expand Down