* fix(typebox): migrate to v1 with extension compat Replace AJV-based validation with TypeBox-native validation, keep legacy extension imports working (including @sinclair/typebox/compiler), and restore coercion for serialized/plain JSON schemas. This change closes #3112. * fix(typebox): use canonical imports and harden coercion Switch first-party code to canonical typebox imports while retaining legacy extension aliases in the loader. Remove obsolete runtime codegen guards, expand serialized JSON-schema coercion coverage, and update related tests and fixtures. Fixes #3112. --------- Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { Type } from "typebox";
|
|
import { describe, expect, it } from "vitest";
|
|
import { getModel } from "../src/models.js";
|
|
import { complete } from "../src/stream.js";
|
|
import type { Context, Model } from "../src/types.js";
|
|
|
|
interface MistralToolPayload {
|
|
tools?: Array<{
|
|
type: "function";
|
|
function: {
|
|
name: string;
|
|
parameters: Record<string, unknown>;
|
|
};
|
|
}>;
|
|
}
|
|
|
|
describe("Mistral tool schema serialization", () => {
|
|
it("strips TypeBox symbol keys before the SDK validates tool schemas", async () => {
|
|
const model: Model<"mistral-conversations"> = {
|
|
...getModel("mistral", "devstral-medium-latest"),
|
|
baseUrl: "http://127.0.0.1:9",
|
|
};
|
|
const parameters = Type.Object({
|
|
nested: Type.Object({
|
|
value: Type.String(),
|
|
}),
|
|
});
|
|
const context: Context = {
|
|
messages: [{ role: "user", content: "Hi", timestamp: Date.now() }],
|
|
tools: [
|
|
{
|
|
name: "inspect_schema",
|
|
description: "Inspect the schema",
|
|
parameters,
|
|
},
|
|
],
|
|
};
|
|
let capturedPayload: MistralToolPayload | undefined;
|
|
|
|
const response = await complete(model, context, {
|
|
apiKey: "fake-key",
|
|
onPayload: (payload) => {
|
|
capturedPayload = payload as MistralToolPayload;
|
|
return payload;
|
|
},
|
|
});
|
|
|
|
expect(capturedPayload?.tools).toHaveLength(1);
|
|
const payloadParameters = capturedPayload?.tools?.[0]?.function.parameters;
|
|
expect(payloadParameters).toBeDefined();
|
|
expect(Object.getOwnPropertySymbols(payloadParameters ?? {})).toHaveLength(0);
|
|
const properties = payloadParameters?.properties;
|
|
expect(properties).toBeTruthy();
|
|
expect(Object.getOwnPropertySymbols((properties as Record<string, unknown>) ?? {})).toHaveLength(0);
|
|
const nested = (properties as Record<string, unknown> | undefined)?.nested;
|
|
expect(nested).toBeTruthy();
|
|
expect(Object.getOwnPropertySymbols((nested as Record<string, unknown>) ?? {})).toHaveLength(0);
|
|
expect(response.stopReason).toBe("error");
|
|
expect(response.errorMessage).not.toContain("Input validation failed");
|
|
});
|
|
});
|