Skip to content

Gadget

Gadget<TSchema>(config): () => GadgetBase<TSchema> & object

Defined in: gadgets/typed-gadget.ts:110

Factory function to create a typed gadget base class.

The returned class automatically infers parameter types from the Zod schema, eliminating the need for manual type assertions in the execute method.

TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

GadgetConfig<TSchema>

Configuration with description and schema

Base class to extend with typed execute method

new Gadget(): GadgetBase<TSchema> & object

GadgetBase<TSchema> & object

import { z } from 'zod';
import { Gadget } from 'llmist';
class Calculator extends Gadget({
description: "Performs arithmetic operations",
schema: z.object({
operation: z.enum(["add", "subtract", "multiply", "divide"]),
a: z.number().describe("First number"),
b: z.number().describe("Second number"),
}),
}) {
execute(params: this['params']): string {
// params is automatically typed as:
// { operation: "add" | "subtract" | "multiply" | "divide"; a: number; b: number }
const { operation, a, b } = params;
switch (operation) {
case "add": return String(a + b);
case "subtract": return String(a - b);
case "multiply": return String(a * b);
case "divide": return String(a / b);
}
}
}
// With async execution
class WeatherGadget extends Gadget({
description: "Fetches weather for a city",
schema: z.object({
city: z.string().min(1).describe("City name"),
}),
timeoutMs: 10000,
}) {
async execute(params: this['params']): Promise<string> {
const { city } = params; // Automatically typed as { city: string }
const weather = await fetchWeather(city);
return `Weather in ${city}: ${weather}`;
}
}