import { MastraClient } from '@mastra/client-js';
import { weatherTool } from './mastra/tools/weather';
const client = new MastraClient({ baseUrl: 'http://localhost:4111' });
const weatherAgent = client.getAgent('weatherAgent');
const res = await weatherAgent.stream({
messages: [
{
role: 'user',
content: 'How is the weather in Tokyo?',
},
],
clientTools: {
weatherTool,
},
});
const reader = res.body?.getReader();
if (!reader) {
throw new Error('Reader is not available');
}
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value, { stream: true });
console.log(text);
}
import { MastraClient } from '@mastra/client-js';
import { weatherTool } from './mastra/tools/weather';
const client = new MastraClient({ baseUrl: 'http://localhost:4111' });
const weatherAgent = client.getAgent('weatherAgent');
const res = await weatherAgent.stream({
messages: [
{
role: 'user',
content: 'How is the weather in Tokyo?',
},
],
clientTools: {
weatherTool,
},
});
const reader = res.body?.getReader();
if (!reader) {
throw new Error('Reader is not available');
}
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value, { stream: true });
console.log(text);
}