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.
104 lines
2.9 KiB
TypeScript
104 lines
2.9 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 AnthropicTemperaturePayload {
|
|
temperature?: number;
|
|
}
|
|
|
|
class PayloadCaptured extends Error {
|
|
constructor() {
|
|
super("payload captured");
|
|
this.name = "PayloadCaptured";
|
|
}
|
|
}
|
|
|
|
function makeContext(): Context {
|
|
return {
|
|
messages: [{ role: "user", content: "Hello", timestamp: Date.now() }],
|
|
};
|
|
}
|
|
|
|
function makeCustomModel(compat?: Model<"anthropic-messages">["compat"]): Model<"anthropic-messages"> {
|
|
return {
|
|
id: "vendor--claude-opus-4-7",
|
|
name: "Vendor Proxy Opus 4.7",
|
|
api: "anthropic-messages",
|
|
provider: "vendor-proxy",
|
|
baseUrl: "http://127.0.0.1:9",
|
|
reasoning: true,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200000,
|
|
maxTokens: 32000,
|
|
compat,
|
|
};
|
|
}
|
|
|
|
async function capturePayload(
|
|
model: Model<"anthropic-messages">,
|
|
options?: SimpleStreamOptions,
|
|
): Promise<AnthropicTemperaturePayload> {
|
|
let capturedPayload: AnthropicTemperaturePayload | undefined;
|
|
|
|
const payloadCaptureModel: Model<"anthropic-messages"> = {
|
|
...model,
|
|
baseUrl: "http://127.0.0.1:9",
|
|
};
|
|
|
|
const s = streamSimple(payloadCaptureModel, makeContext(), {
|
|
...options,
|
|
apiKey: "fake-key",
|
|
onPayload: (payload) => {
|
|
capturedPayload = payload as AnthropicTemperaturePayload;
|
|
throw new PayloadCaptured();
|
|
},
|
|
});
|
|
|
|
await s.result();
|
|
|
|
if (!capturedPayload) {
|
|
throw new Error("Expected payload to be captured before request failure");
|
|
}
|
|
|
|
return capturedPayload;
|
|
}
|
|
|
|
describe("Anthropic temperature compatibility", () => {
|
|
it("omits temperature for Claude Opus 4.7", async () => {
|
|
const payload = await capturePayload(getModel("anthropic", "claude-opus-4-7"), { temperature: 0 });
|
|
|
|
expect(payload.temperature).toBeUndefined();
|
|
});
|
|
|
|
it("omits temperature for Claude Opus 4.8", async () => {
|
|
const payload = await capturePayload(getModel("anthropic", "claude-opus-4-8"), { temperature: 0 });
|
|
|
|
expect(payload.temperature).toBeUndefined();
|
|
});
|
|
|
|
it("omits default temperature for Claude Opus 4.7", async () => {
|
|
const payload = await capturePayload(getModel("anthropic", "claude-opus-4-7"), { temperature: 1 });
|
|
|
|
expect(payload.temperature).toBeUndefined();
|
|
});
|
|
|
|
it("keeps temperature for Claude Opus 4.6", async () => {
|
|
const payload = await capturePayload(getModel("anthropic", "claude-opus-4-6"), { temperature: 0 });
|
|
|
|
expect(payload.temperature).toBe(0);
|
|
});
|
|
|
|
it("keeps temperature for Claude Sonnet 4.6", async () => {
|
|
const payload = await capturePayload(getModel("anthropic", "claude-sonnet-4-6"), { temperature: 0 });
|
|
|
|
expect(payload.temperature).toBe(0);
|
|
});
|
|
|
|
it("omits temperature for custom models with supportsTemperature disabled", async () => {
|
|
const payload = await capturePayload(makeCustomModel({ supportsTemperature: false }), { temperature: 0 });
|
|
|
|
expect(payload.temperature).toBeUndefined();
|
|
});
|
|
});
|