getTickerInfo.ts•1.58 kB
import { z } from 'zod';
import type { MarketstackClient, MarketstackApiParams } from '../../marketstackClient.js';
// Define the input schema shape for the Ticker Info tool
const getTickerInfoInputSchemaShape = {
ticker: z.string().describe('To get results based on a ticker.'),
};
type RawSchemaShape = typeof getTickerInfoInputSchemaShape;
type Input = z.infer<z.ZodObject<RawSchemaShape>>;
type Output = any; // TODO: Define a more specific output type based on Marketstack response
// Define the handler function for the Ticker Info tool
const getTickerInfoHandler = async (input: Input, client: MarketstackClient): Promise<Output> => {
try {
const { ticker } = input;
const apiRequestParams: MarketstackApiParams = {
endpoint: 'tickerinfo',
ticker,
};
const data = await client.fetchApiData(apiRequestParams);
return data;
} catch (error: unknown) {
console.error('getTickerInfo tool error:', error);
const message = error instanceof Error ? error.message : 'An unknown error occurred.';
throw new Error(`getTickerInfo tool failed: ${message}`);
}
};
// Define the tool definition object structure
type MarketstackToolDefinition = {
name: string;
description: string;
inputSchemaShape: RawSchemaShape;
handler: (input: Input, client: MarketstackClient) => Promise<Output>;
};
export const getTickerInfoTool: MarketstackToolDefinition = {
name: 'get_ticker_info',
description: 'Look up information about tickers.',
inputSchemaShape: getTickerInfoInputSchemaShape,
handler: getTickerInfoHandler,
};