11import { AISpanType , InternalSpans } from "@mastra/core/ai-tracing" ;
2- import { InferUITool , createTool } from "@mastra/core/tools" ;
2+ import type { InferUITool } from "@mastra/core/tools" ;
3+ import { createTool } from "@mastra/core/tools" ;
34import { z } from "zod" ;
45
56/**
@@ -63,11 +64,11 @@ export const alphaVantageCryptoTool = createTool({
6364 tracingPolicy : { internal : InternalSpans . TOOL }
6465 } ) ;
6566
66- await writer ?. write ( { type : 'progress' , data : { message : `📈 Fetching Alpha Vantage crypto data for ${ context . symbol } /${ context . market } ` } } ) ;
67+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : `📈 Fetching Alpha Vantage crypto data for ${ context . symbol } /${ context . market } ` } } ) ;
6768 const apiKey = process . env . ALPHA_VANTAGE_API_KEY ;
6869
6970 if ( typeof apiKey !== "string" || apiKey . trim ( ) === '' ) {
70- await writer ?. write ( { type : 'progress' , data : { message : '❌ Missing ALPHA_VANTAGE_API_KEY' } } ) ;
71+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : '❌ Missing ALPHA_VANTAGE_API_KEY' } } ) ;
7172 return {
7273 data : null ,
7374 error : "ALPHA_VANTAGE_API_KEY environment variable is required"
@@ -95,7 +96,7 @@ export const alphaVantageCryptoTool = createTool({
9596
9697 const url = `https://www.alphavantage.co/query?${ params . toString ( ) } ` ;
9798
98- await writer ?. write ( { type : 'progress' , data : { message : '📡 Querying Alpha Vantage API...' } } ) ;
99+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : '📡 Querying Alpha Vantage API...' } } ) ;
99100 const response = await fetch ( url ) ;
100101
101102 if ( ! response . ok ) {
@@ -152,7 +153,7 @@ export const alphaVantageCryptoTool = createTool({
152153 return null ;
153154 } ;
154155
155- await writer ?. write ( { type : 'progress' , data : { message : `✅ Crypto data ready for ${ context . symbol } ` } } ) ;
156+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : `✅ Crypto data ready for ${ context . symbol } ` } } ) ;
156157 const result = {
157158 data,
158159 metadata : {
@@ -170,7 +171,7 @@ export const alphaVantageCryptoTool = createTool({
170171
171172 } catch ( error ) {
172173 const errMsg = error instanceof Error ? error . message : "Unknown error occurred" ;
173- await writer ?. write ( { type : 'progress' , data : { message : `❌ Crypto fetch error: ${ errMsg } ` } } ) ;
174+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : `❌ Crypto fetch error: ${ errMsg } ` } } ) ;
174175 span ?. error ( { error : error instanceof Error ? error : new Error ( errMsg ) , endSpan : true } ) ;
175176 return {
176177 data : null ,
@@ -243,11 +244,11 @@ export const alphaVantageStockTool = createTool({
243244 tracingPolicy : { internal : InternalSpans . TOOL }
244245 } ) ;
245246
246- await writer ?. write ( { type : 'progress' , data : { message : `📈 Fetching Alpha Vantage stock data for ${ context . symbol || 'symbol' } ` } } ) ;
247+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : `📈 Fetching Alpha Vantage stock data for ${ context . symbol || 'symbol' } ` } } ) ;
247248 const apiKey = process . env . ALPHA_VANTAGE_API_KEY ;
248249
249250 if ( typeof apiKey !== "string" || apiKey . trim ( ) === '' ) {
250- await writer ?. write ( { type : 'progress' , data : { message : '❌ Missing ALPHA_VANTAGE_API_KEY' } } ) ;
251+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : '❌ Missing ALPHA_VANTAGE_API_KEY' } } ) ;
251252 return {
252253 data : null ,
253254 error : "ALPHA_VANTAGE_API_KEY environment variable is required"
@@ -438,11 +439,11 @@ export const alphaVantageTool = createTool({
438439 tracingPolicy : { internal : InternalSpans . TOOL }
439440 } ) ;
440441
441- await writer ?. write ( { type : 'data-tool-progress' , data : { message : `💰 Fetching general Alpha Vantage data for ${ context . function } ` } } ) ;
442+ await writer ?. custom ( { type : 'data-tool-progress' , data : { message : `💰 Fetching general Alpha Vantage data for ${ context . function } ` } } ) ;
442443 const apiKey = process . env . ALPHA_VANTAGE_API_KEY ;
443444
444445 if ( typeof apiKey !== "string" || apiKey . trim ( ) === "" ) {
445- await writer ?. write ( { type : 'data-tool-progress' , data : { message : '❌ Missing ALPHA_VANTAGE_API_KEY' } } ) ;
446+ await writer ?. custom ( { type : 'data-tool-progress' , data : { message : '❌ Missing ALPHA_VANTAGE_API_KEY' } } ) ;
446447 return {
447448 data : null ,
448449 error : "ALPHA_VANTAGE_API_KEY environment variable is required"
@@ -488,7 +489,7 @@ export const alphaVantageTool = createTool({
488489 params . append ( "function" , context . economic_indicator ) ;
489490 }
490491
491- await writer ?. write ( { type : 'progress' , data : { message : '📡 Querying Alpha Vantage API...' } } ) ;
492+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : '📡 Querying Alpha Vantage API...' } } ) ;
492493
493494 const url = `https://www.alphavantage.co/query?${ params . toString ( ) } ` ;
494495
@@ -524,7 +525,7 @@ export const alphaVantageTool = createTool({
524525
525526 const metadataObj = metadata as unknown ;
526527
527- await writer ?. write ( { type : 'progress' , data : { message : `✅ General data ready for ${ context . function } ` } } ) ;
528+ await writer ?. custom ( { type : 'data-tool- progress' , data : { message : `✅ General data ready for ${ context . function } ` } } ) ;
528529
529530 const result = {
530531 data,
0 commit comments