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.
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { getModel, streamSimple } from "../src/compat.ts";
|
|
import type { Context, Model, SimpleStreamOptions } from "../src/types.ts";
|
|
|
|
interface MistralPayload {
|
|
promptMode?: "reasoning";
|
|
reasoningEffort?: "none" | "high";
|
|
}
|
|
|
|
function makeContext(): Context {
|
|
return {
|
|
messages: [{ role: "user", content: "Hello", timestamp: Date.now() }],
|
|
};
|
|
}
|
|
|
|
async function capturePayload(
|
|
model: Model<"mistral-conversations">,
|
|
options?: SimpleStreamOptions,
|
|
): Promise<MistralPayload> {
|
|
let capturedPayload: MistralPayload | undefined;
|
|
const payloadCaptureModel: Model<"mistral-conversations"> = {
|
|
...model,
|
|
baseUrl: "http://127.0.0.1:9",
|
|
};
|
|
|
|
const stream = streamSimple(payloadCaptureModel, makeContext(), {
|
|
...options,
|
|
apiKey: "fake-key",
|
|
onPayload: (payload) => {
|
|
capturedPayload = payload as MistralPayload;
|
|
return payload;
|
|
},
|
|
});
|
|
|
|
await stream.result();
|
|
|
|
if (!capturedPayload) {
|
|
throw new Error("Expected payload to be captured before request failure");
|
|
}
|
|
|
|
return capturedPayload;
|
|
}
|
|
|
|
describe("Mistral reasoning mode selection", () => {
|
|
it("uses reasoning_effort for Mistral Small 4", async () => {
|
|
const payload = await capturePayload(getModel("mistral", "mistral-small-2603"), { reasoning: "medium" });
|
|
|
|
expect(payload.reasoningEffort).toBe("high");
|
|
expect(payload.promptMode).toBeUndefined();
|
|
});
|
|
|
|
it("omits reasoning controls for Mistral Small 4 when thinking is off", async () => {
|
|
const payload = await capturePayload(getModel("mistral", "mistral-small-2603"));
|
|
|
|
expect(payload.reasoningEffort).toBeUndefined();
|
|
expect(payload.promptMode).toBeUndefined();
|
|
});
|
|
|
|
it("uses prompt_mode for Magistral reasoning models", async () => {
|
|
const payload = await capturePayload(getModel("mistral", "magistral-medium-latest"), { reasoning: "medium" });
|
|
|
|
expect(payload.promptMode).toBe("reasoning");
|
|
expect(payload.reasoningEffort).toBeUndefined();
|
|
});
|
|
|
|
it("uses reasoning_effort for Mistral Medium 3.5", async () => {
|
|
const payload = await capturePayload(getModel("mistral", "mistral-medium-3.5"), { reasoning: "medium" });
|
|
|
|
expect(payload.reasoningEffort).toBe("high");
|
|
expect(payload.promptMode).toBeUndefined();
|
|
});
|
|
|
|
it("omits reasoning controls for Mistral Medium 3.5 when thinking is off", async () => {
|
|
const payload = await capturePayload(getModel("mistral", "mistral-medium-3.5"));
|
|
|
|
expect(payload.reasoningEffort).toBeUndefined();
|
|
expect(payload.promptMode).toBeUndefined();
|
|
});
|
|
});
|