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.
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Parameters
Section titled “Parameters”config
Section titled “config”GadgetConfig<TSchema>
Configuration with description and schema
Returns
Section titled “Returns”Base class to extend with typed execute method
new Gadget():
GadgetBase<TSchema> &object
Returns
Section titled “Returns”GadgetBase<TSchema> & object
Examples
Section titled “Examples”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 executionclass 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}`; }}