import type { InferToolContext } from './infer-tool-context'; import type { ToolSet } from './tool-set'; /** * Builds the required portion of the tool context map for tools whose context * type does not include `undefined`. */ type RequiredToolSetContext = { [K in keyof TOOLS as InferToolContext> extends never ? never : undefined extends InferToolContext> ? never : K]: InferToolContext>; }; /** * Builds the optional portion of the tool context map for tools whose context * object itself may be `undefined`. */ type OptionalToolSetContext = { [K in keyof TOOLS as InferToolContext> extends never ? never : undefined extends InferToolContext> ? K : never]?: InferToolContext>; }; /** * Flattens intersected mapped types so type equality assertions and editor * hovers show the resulting object shape. */ type Normalize = { [KEY in keyof OBJECT]: OBJECT[KEY] }; /** * Infer the context type for a tool set. * * The inferred type maps each contextual tool name to its context type. * * Tools without concrete context are omitted. Tool contexts that include * `undefined` are represented as optional properties. */ export type InferToolSetContext = Normalize< RequiredToolSetContext & OptionalToolSetContext >;