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