-
-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Description
TanStack AI version
v0.2.2
Framework/Library version
React v19.2.3
Describe the bug and the steps to reproduce it
The global aiEventClient singleton in @tanstack/ai does not seem to emit events when the chat function is executed. Subscribing to events via aiEventClient.on() or aiEventClient.onAllPluginEvents() yields no output, even though the AI stream is successfully consumed and returns content.
import { chat, aiEventClient } from "@tanstack/ai";
import { geminiText } from "@tanstack/ai-gemini";
async function test() {
// Ensure API key is set in your environment
const apiKey = process.env.GEMINI_API_KEY;
if (!apiKey) return console.error("Missing API Key");
process.env.GOOGLE_GENERATIVE_AI_API_KEY = apiKey;
console.log("Starting test...");
// Listen to all events
aiEventClient.onAllPluginEvents((e) => {
console.log("Event received:", e.type, e.data);
});
// Specifically listen for tokens
aiEventClient.on("usage:tokens", (e) => {
console.log("Tokens event:", JSON.stringify(e, null, 2));
});
const stream = chat({
adapter: geminiText("gemini-1.5-flash"),
messages: [{ role: "user", content: [{ type: "text", content: "Say hello" }] }],
});
console.log("Stream created, consuming...");
for await (const chunk of stream) {
// Content is received here correctly
}
console.log("Stream finished.");
}
test().catch(console.error);Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
No, because I do not have time to dig into it
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Metadata
Metadata
Assignees
Labels
No labels