import { z } from 'zod';
import type { MarketstackClient, MarketstackApiParams } from '../../marketstackClient.js';
// Define the input schema shape for the Index Info tool
const getIndexInfoInputSchemaShape = {
index: z.string().describe('Specify your benchmark/index id for your request, e.g. australia_all_ordinaries.'),
};
type RawSchemaShape = typeof getIndexInfoInputSchemaShape;
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 Index Info tool
const getIndexInfoHandler = async (input: Input, client: MarketstackClient): Promise<Output> => {
try {
const { index } = input;
const apiRequestParams: MarketstackApiParams = {
endpoint: 'indexinfo',
index,
};
const data = await client.fetchApiData(apiRequestParams);
return data;
} catch (error: unknown) {
console.error('getIndexInfo tool error:', error);
const message = error instanceof Error ? error.message : 'An unknown error occurred.';
throw new Error(`getIndexInfo 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 getIndexInfoTool: MarketstackToolDefinition = {
name: 'get_index_info',
description: 'Get details for a specific stock market index.',
inputSchemaShape: getIndexInfoInputSchemaShape,
handler: getIndexInfoHandler,
};