"use strict";
var import_vitest = require("vitest");
var import_zod = require("zod");
var import_tool_context = require("./tool_context.cjs");
(0, import_vitest.describe)("tool type inference", () => {
  (0, import_vitest.it)("should infer argument type from zod schema", () => {
    const toolType = (0, import_tool_context.tool)({
      name: "test",
      description: "test",
      parameters: import_zod.z.object({ number: import_zod.z.number() }),
      execute: async () => "test"
    });
    (0, import_vitest.expectTypeOf)(toolType).toEqualTypeOf();
  });
  (0, import_vitest.it)("should infer argument type for an anonymous (name-less) tool with a schema", () => {
    (0, import_tool_context.tool)({
      description: "test",
      parameters: import_zod.z.object({ number: import_zod.z.number() }),
      execute: async (args) => {
        (0, import_vitest.expectTypeOf)(args).toEqualTypeOf();
        return `${args.number}`;
      }
    });
  });
  (0, import_vitest.it)("should infer empty args for an anonymous tool when parameters are omitted", () => {
    const toolType = (0, import_tool_context.tool)({
      description: "test",
      execute: async (args) => {
        (0, import_vitest.expectTypeOf)(args).toEqualTypeOf();
        return "done";
      }
    });
    (0, import_vitest.expectTypeOf)(toolType).toEqualTypeOf();
    (0, import_vitest.expectTypeOf)(toolType).toMatchTypeOf();
  });
  (0, import_vitest.it)("should infer empty args for an anonymous tool when parameters are explicitly undefined", () => {
    const toolType = (0, import_tool_context.tool)({
      description: "test",
      parameters: void 0,
      execute: async (args) => {
        (0, import_vitest.expectTypeOf)(args).toEqualTypeOf();
        return "done";
      }
    });
    (0, import_vitest.expectTypeOf)(toolType).toEqualTypeOf();
  });
  (0, import_vitest.it)("should infer args from an explicit empty object schema on anonymous tools", () => {
    const parameters = import_zod.z.object({});
    const toolType = (0, import_tool_context.tool)({
      description: "test",
      parameters,
      execute: async (args) => {
        (0, import_vitest.expectTypeOf)(args).toMatchTypeOf();
        (0, import_vitest.expectTypeOf)(args).toEqualTypeOf();
        return "done";
      }
    });
    (0, import_vitest.expectTypeOf)(toolType).toEqualTypeOf();
  });
  (0, import_vitest.it)("should infer args from populated object schemas on anonymous tools", () => {
    const parameters = import_zod.z.object({
      location: import_zod.z.string(),
      units: import_zod.z.enum(["celsius", "fahrenheit"]).optional()
    });
    const toolType = (0, import_tool_context.tool)({
      description: "test",
      parameters,
      execute: async (args) => {
        (0, import_vitest.expectTypeOf)(args).toEqualTypeOf();
        (0, import_vitest.expectTypeOf)(args.location).toEqualTypeOf();
        (0, import_vitest.expectTypeOf)(args.units).toEqualTypeOf();
        return { location: args.location, ok: true };
      }
    });
    (0, import_vitest.expectTypeOf)(toolType).toEqualTypeOf();
  });
  (0, import_vitest.it)("rejects direct instantiation of the abstract ProviderTool base", () => {
    new import_tool_context.ProviderTool({ id: "code-interpreter" });
    class CodeInterpreter extends import_tool_context.ProviderTool {
    }
    const providerTool = new CodeInterpreter({ id: "code-interpreter" });
    (0, import_vitest.expectTypeOf)(providerTool).toMatchTypeOf();
    (0, import_vitest.expect)(providerTool.id).toBe("code-interpreter");
    (0, import_vitest.expect)(providerTool.type).toBe("provider");
  });
  (0, import_vitest.it)("should infer run context type", () => {
    const toolType = (0, import_tool_context.tool)({
      name: "test",
      description: "test",
      parameters: import_zod.z.object({ number: import_zod.z.number() }),
      execute: async ({ number }, { ctx }) => {
        return `The number is ${number}, ${ctx.userData.name}`;
      }
    });
    (0, import_vitest.expectTypeOf)(toolType).toEqualTypeOf();
  });
  (0, import_vitest.it)("should not accept primitive zod schemas", () => {
    (0, import_vitest.expect)(() => {
      (0, import_tool_context.tool)({
        name: "test",
        description: "test",
        parameters: import_zod.z.string(),
        execute: async () => "test"
      });
    }).toThrowError("Tool parameters must be a Zod object schema (z.object(...))");
  });
  (0, import_vitest.it)("should not accept array schemas", () => {
    (0, import_vitest.expect)(() => {
      (0, import_tool_context.tool)({
        name: "test",
        description: "test",
        parameters: import_zod.z.array(import_zod.z.string()),
        execute: async () => "test"
      });
    }).toThrowError("Tool parameters must be a Zod object schema (z.object(...))");
  });
  (0, import_vitest.it)("should not accept union schemas", () => {
    (0, import_vitest.expect)(() => {
      (0, import_tool_context.tool)({
        name: "test",
        description: "test",
        parameters: import_zod.z.union([import_zod.z.object({ a: import_zod.z.string() }), import_zod.z.object({ b: import_zod.z.number() })]),
        execute: async () => "test"
      });
    }).toThrowError("Tool parameters must be a Zod object schema (z.object(...))");
  });
  (0, import_vitest.it)("should not accept non-Zod values as parameters", () => {
    (0, import_vitest.expect)(() => {
      (0, import_tool_context.tool)({
        name: "test",
        description: "test",
        // @ts-expect-error - Testing that non-Zod values are rejected
        parameters: "invalid schema",
        execute: async () => "test"
      });
    }).toThrowError("Tool parameters must be a Zod object schema or a raw JSON schema");
  });
  (0, import_vitest.it)("should infer empty object type when parameters are omitted", () => {
    const toolType = (0, import_tool_context.tool)({
      name: "simpleAction",
      description: "Simple action without parameters",
      execute: async () => "done"
    });
    (0, import_vitest.expectTypeOf)(toolType).toEqualTypeOf();
  });
  (0, import_vitest.it)("names tool context input shapes by role", () => {
    const objectTools = {
      lookupOrder: (0, import_tool_context.tool)({
        description: "Look up an order",
        execute: async () => "done"
      })
    };
    const namedTool = (0, import_tool_context.tool)({
      name: "simpleAction",
      description: "Simple action",
      execute: async () => "done"
    });
    (0, import_vitest.expectTypeOf)(objectTools).toMatchTypeOf();
    (0, import_vitest.expectTypeOf)(objectTools).toMatchTypeOf();
    (0, import_vitest.expectTypeOf)([namedTool]).toMatchTypeOf();
    (0, import_vitest.expectTypeOf)(new import_tool_context.ToolContext(objectTools)).toMatchTypeOf();
    (0, import_vitest.expectTypeOf)(namedTool).toMatchTypeOf();
  });
  (0, import_vitest.it)("should infer correct types with context but no parameters", () => {
    const toolType = (0, import_tool_context.tool)({
      name: "actionWithCtx",
      description: "Action with context",
      execute: async (args, { ctx }) => {
        (0, import_vitest.expectTypeOf)(args).toEqualTypeOf();
        (0, import_vitest.expectTypeOf)(ctx.userData.userId).toEqualTypeOf();
        return ctx.userData.userId;
      }
    });
    (0, import_vitest.expectTypeOf)(toolType).toEqualTypeOf();
  });
});
//# sourceMappingURL=tool_context.type.test.cjs.map