fix: align SkillTool schema error output
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
import { describe, expect, test } from 'bun:test'
|
import { describe, expect, test } from 'bun:test'
|
||||||
|
|
||||||
import { SkillTool } from '../../tools/SkillTool/SkillTool.js'
|
import { SkillTool } from '../../tools/SkillTool/SkillTool.js'
|
||||||
import { getSchemaValidationErrorOverride } from './toolExecution.js'
|
import {
|
||||||
|
getSchemaValidationErrorOverride,
|
||||||
|
getSchemaValidationToolUseResult,
|
||||||
|
} from './toolExecution.js'
|
||||||
|
|
||||||
describe('getSchemaValidationErrorOverride', () => {
|
describe('getSchemaValidationErrorOverride', () => {
|
||||||
test('returns actionable missing-skill error for SkillTool', () => {
|
test('returns actionable missing-skill error for SkillTool', () => {
|
||||||
@@ -21,4 +24,10 @@ describe('getSchemaValidationErrorOverride', () => {
|
|||||||
getSchemaValidationErrorOverride(SkillTool, { skill: 'commit' }),
|
getSchemaValidationErrorOverride(SkillTool, { skill: 'commit' }),
|
||||||
).toBe(null)
|
).toBe(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('uses the actionable override for structured toolUseResult too', () => {
|
||||||
|
expect(getSchemaValidationToolUseResult(SkillTool, {} as never)).toBe(
|
||||||
|
'InputValidationError: Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -613,6 +613,15 @@ export function getSchemaValidationErrorOverride(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSchemaValidationToolUseResult(
|
||||||
|
tool: Tool,
|
||||||
|
input: unknown,
|
||||||
|
fallbackMessage?: string,
|
||||||
|
): string {
|
||||||
|
const override = getSchemaValidationErrorOverride(tool, input)
|
||||||
|
return `InputValidationError: ${override ?? fallbackMessage ?? ''}`
|
||||||
|
}
|
||||||
|
|
||||||
async function checkPermissionsAndCallTool(
|
async function checkPermissionsAndCallTool(
|
||||||
tool: Tool,
|
tool: Tool,
|
||||||
toolUseID: string,
|
toolUseID: string,
|
||||||
@@ -631,9 +640,9 @@ async function checkPermissionsAndCallTool(
|
|||||||
// Validate input types with zod (surprisingly, the model is not great at generating valid input)
|
// Validate input types with zod (surprisingly, the model is not great at generating valid input)
|
||||||
const parsedInput = tool.inputSchema.safeParse(input)
|
const parsedInput = tool.inputSchema.safeParse(input)
|
||||||
if (!parsedInput.success) {
|
if (!parsedInput.success) {
|
||||||
|
const fallbackErrorContent = formatZodValidationError(tool.name, parsedInput.error)
|
||||||
let errorContent =
|
let errorContent =
|
||||||
getSchemaValidationErrorOverride(tool, input) ??
|
getSchemaValidationErrorOverride(tool, input) ?? fallbackErrorContent
|
||||||
formatZodValidationError(tool.name, parsedInput.error)
|
|
||||||
|
|
||||||
const schemaHint = buildSchemaNotSentHint(
|
const schemaHint = buildSchemaNotSentHint(
|
||||||
tool,
|
tool,
|
||||||
@@ -691,7 +700,11 @@ async function checkPermissionsAndCallTool(
|
|||||||
tool_use_id: toolUseID,
|
tool_use_id: toolUseID,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
toolUseResult: `InputValidationError: ${parsedInput.error.message}`,
|
toolUseResult: getSchemaValidationToolUseResult(
|
||||||
|
tool,
|
||||||
|
input,
|
||||||
|
parsedInput.error.message,
|
||||||
|
),
|
||||||
sourceToolAssistantUUID: assistantMessage.uuid,
|
sourceToolAssistantUUID: assistantMessage.uuid,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user