diff --git a/packages/typescript/ai/src/extend-adapter.ts b/packages/typescript/ai/src/extend-adapter.ts index 8547ebef..9e4f69b6 100644 --- a/packages/typescript/ai/src/extend-adapter.ts +++ b/packages/typescript/ai/src/extend-adapter.ts @@ -97,15 +97,6 @@ type InferFactoryModels = TFactory extends ( : string : string -/** - * Infer the config parameter type from an adapter factory function. - */ -type InferConfig = TFactory extends ( - model: any, - config?: infer TConfig, -) => any - ? TConfig - : undefined /** * Infer the adapter return type from a factory function. @@ -116,6 +107,12 @@ type InferAdapterReturn = TFactory extends ( ? TReturn : never +/** + * Extracts all parameter types after the first parameter from a function. + */ +type InferRestArgs any> = + Parameters extends [any, ...infer Rest] ? Rest : [] + // =========================== // extendAdapter Function // =========================== @@ -164,19 +161,17 @@ type InferAdapterReturn = TFactory extends ( * ``` */ export function extendAdapter< - TFactory extends (...args: Array) => any, + TFactory extends (model: any, ...args: Array) => any, const TDefs extends ReadonlyArray, >( factory: TFactory, _customModels: TDefs, -): ( - model: InferFactoryModels | ExtractCustomModelNames, - ...args: InferConfig extends undefined - ? [] - : [config?: InferConfig] -) => InferAdapterReturn { +) { // At runtime, we simply pass through to the original factory. // The _customModels parameter is only used for type inference. // No runtime validation - users are trusted to pass valid model names. - return factory as any -} + return factory as unknown as ( + model: InferFactoryModels | ExtractCustomModelNames, + ...args: InferRestArgs + ) => InferAdapterReturn +} \ No newline at end of file