fix(ai): corrected AI tool handling via JSON-schema validation flow
- Replaced fromTypeBox conversion with a JSON-schema validator flow in ai tool handling and execution paths. - Added recursive schema validation and expanded TypeBox checks for refs, enums, uniqueItems, and constraint keywords. - Sanitized Azure/CCA tool schemas by dropping unsupported fields and rewriting oneOf tool branches as anyOf. - Tightened argument and model-config validation, preserving unknown tool fields and adding apiKey plus compatibility flags.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import type { AssistantMessage } from "@oh-my-pi/pi-ai";
|
||||
import { createConventionalAnalysisTool, parseConventionalAnalysisResponse } from "../src/commit/shared-llm";
|
||||
|
||||
describe("commit shared LLM parsing", () => {
|
||||
it("ignores harmless extra fields in conventional analysis tool output", () => {
|
||||
const tool = createConventionalAnalysisTool("Analyze a diff.");
|
||||
const message = {
|
||||
role: "assistant",
|
||||
content: [
|
||||
{
|
||||
type: "toolCall",
|
||||
id: "call-analysis",
|
||||
name: tool.name,
|
||||
arguments: {
|
||||
type: "fix",
|
||||
scope: null,
|
||||
details: [],
|
||||
issue_refs: [],
|
||||
summary: "fix: handle parser edge case",
|
||||
},
|
||||
},
|
||||
],
|
||||
} as unknown as AssistantMessage;
|
||||
|
||||
expect(parseConventionalAnalysisResponse(message, tool)).toEqual({
|
||||
type: "fix",
|
||||
scope: null,
|
||||
details: [],
|
||||
issueRefs: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user