Skip to content

Commit 7cdffd4

Browse files
committed
fix: correct type for nextTurnParams function parameters
Fixed TypeScript error where nextTurnParams function parameters were typed as unknown instead of Record<string, unknown>, causing type incompatibility with the actual function signatures. Changes: - Updated Map type to use Record<string, unknown> for params - Added type assertions when storing functions to match expected signature - Added type assertion for function return value to preserve type safety
1 parent 4b78a19 commit 7cdffd4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/lib/next-turn-params.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ export async function executeNextTurnParamsFunctions(
4343
// Group tool calls by parameter they modify
4444
const paramFunctions = new Map<
4545
keyof NextTurnParamsContext,
46-
Array<{ params: unknown; fn: Function }>
46+
Array<{ params: Record<string, unknown>; fn: (params: Record<string, unknown>, context: NextTurnParamsContext) => unknown }>
4747
>();
4848

4949
// Collect all nextTurnParams functions from tools (in tools array order)
5050
for (const tool of tools) {
51-
if (!tool.function.nextTurnParams) continue;
51+
if (!tool.function.nextTurnParams) {
52+
continue;
53+
}
5254

5355
// Find tool calls for this tool
5456
const callsForTool = toolCalls.filter(tc => tc.name === tool.function.name);
@@ -60,8 +62,8 @@ export async function executeNextTurnParamsFunctions(
6062
paramFunctions.set(paramKey as keyof NextTurnParamsContext, []);
6163
}
6264
paramFunctions.get(paramKey as keyof NextTurnParamsContext)!.push({
63-
params: call.arguments,
64-
fn,
65+
params: call.arguments as Record<string, unknown>,
66+
fn: fn as (params: Record<string, unknown>, context: NextTurnParamsContext) => unknown,
6567
});
6668
}
6769
}
@@ -80,7 +82,8 @@ export async function executeNextTurnParamsFunctions(
8082
workingContext = { ...workingContext, [paramKey]: currentValue };
8183

8284
// Execute function with composition
83-
currentValue = await Promise.resolve(fn(params, workingContext));
85+
// Type assertion needed because fn returns unknown but we know it returns the correct type
86+
currentValue = await Promise.resolve(fn(params, workingContext)) as typeof currentValue;
8487
}
8588

8689
// TypeScript can't infer that paramKey corresponds to the correct value type

0 commit comments

Comments
 (0)