Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

ToolExecutionContext.md

66 lines1.3 KB

1---
2id: ToolExecutionContext
3title: ToolExecutionContext
4---
5​
6# Interface: ToolExecutionContext
7​
8Defined in: [packages/typescript/ai/src/types.ts:449](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L449)
9​
10Context passed to tool execute functions, providing capabilities like
11emitting custom events during execution.
12​
13## Properties
14​
15### emitCustomEvent()
16​
17```ts
18emitCustomEvent: (eventName, value) => void;
19```
20​
21Defined in: [packages/typescript/ai/src/types.ts:470](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L470)
22​
23Emit a custom event during tool execution.
24Events are streamed to the client in real-time as AG-UI CUSTOM events.
25​
26#### Parameters
27​
28##### eventName
29​
30`string`
31​
32Name of the custom event
33​
34##### value
35​
36`Record`\<`string`, `any`\>
37​
38Event payload value
39​
40#### Returns
41​
42`void`
43​
44#### Example
45​
46```ts
47const tool = toolDefinition({ ... }).server(async (args, context) => {
48 context?.emitCustomEvent('progress', { step: 1, total: 3 })
49 // ... do work ...
50 context?.emitCustomEvent('progress', { step: 2, total: 3 })
51 // ... do more work ...
52 return result
53})
54```
55​
56***
57​
58### toolCallId?
59​
60```ts
61optional toolCallId: string;
62```
63​
64Defined in: [packages/typescript/ai/src/types.ts:451](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/types.ts#L451)
65​
66The ID of the tool call being executed