import { GenericToolSpec, ToolExecutionContext } from '../core/handlers/base-handler.js';
import { ToolArguments } from '../core/handlers/base-handler.js';
import { ScriptDebuggerClient } from '../clients/script-debugger/index.js';
export const SCRIPT_DEBUGGER_TOOL_NAMES = ['evaluate_script'] as const;
export type ScriptDebuggerToolName = (typeof SCRIPT_DEBUGGER_TOOL_NAMES)[number];
export const SCRIPT_DEBUGGER_TOOL_NAMES_SET = new Set<ScriptDebuggerToolName>(SCRIPT_DEBUGGER_TOOL_NAMES);
/**
* Configuration for script debugger tools
* Maps each tool to its validation, execution, and messaging logic
*/
export const SCRIPT_DEBUGGER_TOOL_CONFIG: Record<
ScriptDebuggerToolName,
GenericToolSpec<ToolArguments, unknown>
> = {
evaluate_script: {
exec: async (args: ToolArguments, context: ToolExecutionContext) => {
const client = context.scriptDebuggerClient as ScriptDebuggerClient;
const result = await client.evaluateScript(args.script as string, {
timeout: args.timeout as number | undefined,
siteId: args.siteId as string | undefined,
locale: args.locale as string | undefined,
breakpointFile: args.breakpointFile as string | undefined,
breakpointLine: args.breakpointLine as number | undefined,
});
return result;
},
logMessage: (args: ToolArguments) => {
const script = (args?.script as string) ?? '';
const preview = script.length > 50 ? `${script.substring(0, 50) }...` : script;
return `Evaluate script: ${preview}`;
},
},
};