feat: implemented dynamic coercion for legacy tool argument aliases
- Added `normalizeSingleStringField` to dynamically map misplaced string inputs to required schema fields for single-argument tools. - Integrated argument normalization into `validateToolArguments` to handle model-specific variations in JSON payloads during validation passes. - Updated `coding-agent` streaming and rendering components to recognize `_input` as a legacy alias for `input` across various UI paths and logic flows. - Refactored `hashlineEditParamsSchema` to strictly enforce the `input` field while maintaining support for legacy aliases via runtime coercion rather than schema definition. - Corrected unit tests to reflect that `_input` is rejected by the strict schema but handled gracefully by the validation layer.
This commit is contained in:
@@ -306,11 +306,7 @@ describe("hashlineEditParamsSchema — payload shape", () => {
|
||||
}
|
||||
|
||||
it("declares only `input` as the model-facing field", () => {
|
||||
// Create an arktype schema that mirrors hashlineEditParamsSchema structure
|
||||
const testSchema = type({
|
||||
input: "string",
|
||||
});
|
||||
const jsonSchema = getJsonSchema(testSchema) as {
|
||||
const jsonSchema = getJsonSchema(hashlineEditParamsSchema) as {
|
||||
properties?: Record<string, unknown>;
|
||||
required?: string[];
|
||||
};
|
||||
@@ -327,12 +323,11 @@ describe("hashlineEditParamsSchema — payload shape", () => {
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts `_input` as a provider-emitted alias for `input`", () => {
|
||||
it("rejects `_input` as an alias for `input`", () => {
|
||||
const result = arkSafeParse(hashlineEditParamsSchema, {
|
||||
_input: `[x.ts]\nINS.HEAD:\n${repl("x")}`,
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) expect(result.data.input).toBe(`[x.ts]\nINS.HEAD:\n${repl("x")}`);
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it("still requires `input`", () => {
|
||||
|
||||
Reference in New Issue
Block a user