-
-
Notifications
You must be signed in to change notification settings - Fork 133
Tools/custom events dispatch #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
070efb9
fba4a47
9efd520
c3782e5
e73ea9d
f49c3cd
795b68f
356097d
e73133f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| '@tanstack/ai': minor | ||
| '@tanstack/ai-client': minor | ||
| '@tanstack/ai-react': patch | ||
| '@tanstack/ai-solid': patch | ||
| '@tanstack/ai-svelte': patch | ||
| '@tanstack/ai-vue': patch | ||
| --- | ||
|
|
||
| feat: add custom event dispatch support for tools | ||
|
|
||
| Tools can now emit custom events during execution via `dispatchEvent()`. Custom events are streamed to clients as `custom_event` stream chunks and surfaced through the client chat hook's `onCustomEvent` callback. This enables tools to send progress updates, intermediate results, or any structured data back to the UI during long-running operations. | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,7 @@ export function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>( | |||||||||
| optionsRef.current.onError?.(error) | ||||||||||
| }, | ||||||||||
| tools: optionsRef.current.tools, | ||||||||||
| onCustomEvent: optionsRef.current.onCustomEvent, | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested fix: wrap in a closure for consistency- onCustomEvent: optionsRef.current.onCustomEvent,
+ onCustomEvent: (eventType: string, data: unknown, context: { toolCallId?: string }) => {
+ optionsRef.current.onCustomEvent?.(eventType, data, context)
+ },π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||
| streamProcessor: options.streamProcessor, | ||||||||||
| onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => { | ||||||||||
| setMessages(newMessages) | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π§© Analysis chain
π Script executed:
Repository: TanStack/ai
Length of output: 626
π Script executed:
Repository: TanStack/ai
Length of output: 5790
π Script executed:
Repository: TanStack/ai
Length of output: 1569
π Script executed:
Repository: TanStack/ai
Length of output: 221
Incorrect API name in documentation.
The changeset states tools emit events via
dispatchEvent(), but the actual API iscontext.emitCustomEvent()wherecontextis theToolExecutionContextpassed to the tool's execute function. The implementation, tests, and all usage examples consistently useemitCustomEvent().Update the documentation to reflect the correct API name:
Suggested fix
π Committable suggestion
π€ Prompt for AI Agents