|
1 | 1 | // Anthropic tests cover index plugin behavior. |
| 2 | +import { calculateCost, type Usage } from "openclaw/plugin-sdk/llm"; |
2 | 3 | import type { |
3 | 4 | ProviderResolveDynamicModelContext, |
4 | 5 | ProviderRuntimeModel, |
@@ -859,6 +860,70 @@ describe("anthropic provider replay hooks", () => { |
859 | 860 | expect(normalized?.cost).toEqual((resolved as ProviderRuntimeModel).cost); |
860 | 861 | }); |
861 | 862 |
|
| 863 | + it.each(["claude-sonnet-5", "claude-opus-5"])( |
| 864 | + "uses operator-configured %s pricing for assistant usage", |
| 865 | + async (modelId) => { |
| 866 | + const provider = await registerSingleProviderPlugin(anthropicPlugin); |
| 867 | + const configuredCost = { input: 777, output: 888, cacheRead: 999, cacheWrite: 666 }; |
| 868 | + const config: NonNullable<ProviderResolveDynamicModelContext["config"]> = { |
| 869 | + models: { |
| 870 | + providers: { |
| 871 | + anthropic: { |
| 872 | + baseUrl: "https://api.anthropic.com", |
| 873 | + models: [ |
| 874 | + { |
| 875 | + id: modelId, |
| 876 | + name: modelId, |
| 877 | + reasoning: true, |
| 878 | + input: ["text", "image"], |
| 879 | + cost: configuredCost, |
| 880 | + contextWindow: 1_000_000, |
| 881 | + maxTokens: 128_000, |
| 882 | + }, |
| 883 | + ], |
| 884 | + }, |
| 885 | + }, |
| 886 | + }, |
| 887 | + }; |
| 888 | + const discoveredModel = provider.resolveDynamicModel?.({ |
| 889 | + config, |
| 890 | + provider: "anthropic", |
| 891 | + modelId, |
| 892 | + modelRegistry: createModelRegistry([]), |
| 893 | + } as ProviderResolveDynamicModelContext); |
| 894 | + expect(discoveredModel).toBeDefined(); |
| 895 | + |
| 896 | + const configuredModel = { |
| 897 | + ...(discoveredModel as ProviderRuntimeModel), |
| 898 | + cost: configuredCost, |
| 899 | + }; |
| 900 | + const resolvedModel = |
| 901 | + provider.normalizeResolvedModel?.({ |
| 902 | + config, |
| 903 | + provider: "anthropic", |
| 904 | + modelId, |
| 905 | + model: configuredModel, |
| 906 | + } as never) ?? configuredModel; |
| 907 | + const usage: Usage = { |
| 908 | + input: 1_000, |
| 909 | + output: 1_000, |
| 910 | + cacheRead: 1_000, |
| 911 | + cacheWrite: 1_000, |
| 912 | + totalTokens: 4_000, |
| 913 | + cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }, |
| 914 | + }; |
| 915 | + |
| 916 | + calculateCost(resolvedModel as Parameters<typeof calculateCost>[0], usage); |
| 917 | + |
| 918 | + expect(resolvedModel.cost).toEqual(configuredCost); |
| 919 | + expect(usage.cost.input).toBeCloseTo(0.777); |
| 920 | + expect(usage.cost.output).toBeCloseTo(0.888); |
| 921 | + expect(usage.cost.cacheRead).toBeCloseTo(0.999); |
| 922 | + expect(usage.cost.cacheWrite).toBeCloseTo(0.666); |
| 923 | + expect(usage.cost.total).toBeCloseTo(3.33); |
| 924 | + }, |
| 925 | + ); |
| 926 | + |
862 | 927 | it("resolves Claude Mythos 5 with its direct-only mandatory-adaptive contract", async () => { |
863 | 928 | const provider = await registerSingleProviderPlugin(anthropicPlugin); |
864 | 929 | const resolved = provider.resolveDynamicModel?.({ |
|
0 commit comments