// GENERATED FILE — DO NOT EDIT.
// Source: .contracts/tools/rig_context.contract.ts
// Edit the .contract.ts file(s), then run `bun run gen`.

import type { ToolHandler } from '@rig/mcp/dispatch.ts';
import { ToolError } from '@rig/mcp/dispatch.ts';
import contract from '../../../.contracts/tools/rig_context.contract.ts';
import { run as impl } from '@rig/mcp/tool-impls/rig_context.ts';

export const rigContextHandler: ToolHandler = {
  name: 'rig_context',
  tier: 'heavy',
  mainSessionForbidden: true,
  run: async (args, ctx) => {
    if (ctx.isMainSession) {
      throw new ToolError('MAIN_SESSION_FORBIDDEN', 'rig_context cannot run in the main session');
    }
    const parsedIn = contract.input.safeParse(args);
    if (!parsedIn.success) {
      throw new ToolError('INPUT_INVALID', parsedIn.error.message);
    }
    const out = await impl(parsedIn.data, ctx);
    const parsedOut = contract.output.safeParse(out);
    if (!parsedOut.success) {
      throw new ToolError('OUTPUT_INVALID', parsedOut.error.message);
    }
    return parsedOut.data;
  },
};
