Disallow unsafe type assertions (#18688)

This commit is contained in:
Christian Gunderman
2026-02-10 00:10:15 +00:00
committed by GitHub
parent bce1caefd0
commit fd65416a2f
188 changed files with 592 additions and 47 deletions
+8
View File
@@ -174,6 +174,7 @@ export class HookRunner {
typeof additionalContext === 'string' &&
'prompt' in modifiedInput
) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
(modifiedInput as BeforeAgentInput).prompt +=
'\n\n' + additionalContext;
}
@@ -183,16 +184,19 @@ export class HookRunner {
case HookEventName.BeforeModel:
if ('llm_request' in hookOutput.hookSpecificOutput) {
// For BeforeModel, we update the LLM request
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const hookBeforeModelOutput = hookOutput as BeforeModelOutput;
if (
hookBeforeModelOutput.hookSpecificOutput?.llm_request &&
'llm_request' in modifiedInput
) {
// Merge the partial request with the existing request
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const currentRequest = (modifiedInput as BeforeModelInput)
.llm_request;
const partialRequest =
hookBeforeModelOutput.hookSpecificOutput.llm_request;
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
(modifiedInput as BeforeModelInput).llm_request = {
...currentRequest,
...partialRequest,
@@ -203,11 +207,14 @@ export class HookRunner {
case HookEventName.BeforeTool:
if ('tool_input' in hookOutput.hookSpecificOutput) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const newToolInput = hookOutput.hookSpecificOutput[
'tool_input'
] as Record<string, unknown>;
if (newToolInput && 'tool_input' in modifiedInput) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
(modifiedInput as BeforeToolInput).tool_input = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
...(modifiedInput as BeforeToolInput).tool_input,
...newToolInput,
};
@@ -355,6 +362,7 @@ export class HookRunner {
parsed = JSON.parse(parsed);
}
if (parsed) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
output = parsed as HookOutput;
}
} catch {