8a0903ebf2
The root barrel is now core-only and side-effect free: types, createModels/createProvider, auth substrate, lazyStream/lazyApi, faux, utils. Generated catalogs, api-registry, env-api-keys, images, global stream functions, and per-API lazy wrappers leave the root. New @earendil-works/pi-ai/compat preserves the old surface verbatim as a strict superset of the root: api-dispatch stream/complete with env key injection, the builtin registration side effect (skip-if-present so it cannot clobber earlier overrides), deprecated getModel/getModels/ getProviders aliases of the new getBuiltin* reads in providers/all, lazy api wrappers + setBedrockProviderModule, and image generation. Compat dies with the coding-agent ModelManager migration. Packaging: exports map gains ./compat, ./providers/*, ./api/*; sideEffects array lists only the effectful modules. Old-global imports across agent/coding-agent/examples and pi-ai tests switch to /compat (path-only; compat is a superset). The coding-agent extension loader resolves the pi-ai ROOT specifier to compat, so existing user extensions using the old global API keep working at runtime until compat is removed. vitest configs alias /compat to src; browser smoke imports old globals from /compat.
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { Type } from "typebox";
|
|
import { describe, expect, it } from "vitest";
|
|
import { complete, getModel } from "../src/compat.ts";
|
|
import type { Context, Model } from "../src/types.ts";
|
|
|
|
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");
|
|
});
|
|
});
|