mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-23 02:45:38 -06:00
d5dcc3fb19
* fix(providers): refresh onboarding defaults * fix(moonshot): import manifest default from catalog
121 lines
3.5 KiB
TypeScript
121 lines
3.5 KiB
TypeScript
// Moonshot tests cover provider catalog plugin behavior.
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
applyMoonshotNativeStreamingUsageCompat,
|
|
buildMoonshotProvider,
|
|
MOONSHOT_BASE_URL,
|
|
MOONSHOT_CN_BASE_URL,
|
|
} from "./api.js";
|
|
|
|
type MoonshotProvider = ReturnType<typeof buildMoonshotProvider>;
|
|
type MoonshotModel = MoonshotProvider["models"][number];
|
|
|
|
function requireMoonshotModel(provider: MoonshotProvider, modelId: string): MoonshotModel {
|
|
const model = provider.models.find((candidate) => candidate.id === modelId);
|
|
if (!model) {
|
|
throw new Error(`expected Moonshot model ${modelId}`);
|
|
}
|
|
return model;
|
|
}
|
|
|
|
function requireFirstMoonshotModel(provider: MoonshotProvider): MoonshotModel {
|
|
const model = provider.models[0];
|
|
if (!model) {
|
|
throw new Error("expected first Moonshot model");
|
|
}
|
|
return model;
|
|
}
|
|
|
|
function requireMoonshotCompat(model: MoonshotModel): NonNullable<MoonshotModel["compat"]> {
|
|
if (!model.compat) {
|
|
throw new Error(`expected Moonshot model ${model.id} compat`);
|
|
}
|
|
return model.compat;
|
|
}
|
|
|
|
describe("moonshot provider catalog", () => {
|
|
it("builds the bundled Moonshot provider defaults", () => {
|
|
const provider = buildMoonshotProvider();
|
|
|
|
expect(provider.baseUrl).toBe(MOONSHOT_BASE_URL);
|
|
expect(provider.api).toBe("openai-completions");
|
|
expect(provider.models.map((model) => model.id)).toEqual([
|
|
"kimi-k3",
|
|
"kimi-k2.7-code",
|
|
"kimi-k2.7-code-highspeed",
|
|
]);
|
|
expect(requireMoonshotModel(provider, "kimi-k3")).toMatchObject({
|
|
reasoning: true,
|
|
thinkingLevelMap: {
|
|
off: null,
|
|
minimal: null,
|
|
low: "low",
|
|
medium: null,
|
|
high: "high",
|
|
xhigh: "max",
|
|
max: "max",
|
|
},
|
|
input: ["text", "image"],
|
|
contextWindow: 1_048_576,
|
|
maxTokens: 1_048_576,
|
|
cost: {
|
|
input: 3,
|
|
output: 15,
|
|
cacheRead: 0.3,
|
|
cacheWrite: 0,
|
|
},
|
|
compat: {
|
|
supportsReasoningEffort: true,
|
|
supportedReasoningEfforts: ["low", "high", "max"],
|
|
},
|
|
});
|
|
expect(requireMoonshotModel(provider, "kimi-k2.7-code")).toMatchObject({
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
contextWindow: 262144,
|
|
maxTokens: 262144,
|
|
cost: {
|
|
input: 0.95,
|
|
output: 4,
|
|
cacheRead: 0.19,
|
|
cacheWrite: 0,
|
|
},
|
|
});
|
|
expect(requireMoonshotModel(provider, "kimi-k2.7-code-highspeed")).toMatchObject({
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
contextWindow: 262144,
|
|
maxTokens: 262144,
|
|
cost: {
|
|
input: 1.9,
|
|
output: 8,
|
|
cacheRead: 0.38,
|
|
cacheWrite: 0,
|
|
},
|
|
});
|
|
});
|
|
|
|
it("opts native Moonshot baseUrls into streaming usage only inside the extension", () => {
|
|
const defaultProvider = applyMoonshotNativeStreamingUsageCompat(buildMoonshotProvider());
|
|
expect(
|
|
requireMoonshotCompat(requireFirstMoonshotModel(defaultProvider)).supportsUsageInStreaming,
|
|
).toBe(true);
|
|
|
|
const cnProvider = applyMoonshotNativeStreamingUsageCompat({
|
|
...buildMoonshotProvider(),
|
|
baseUrl: MOONSHOT_CN_BASE_URL,
|
|
});
|
|
expect(
|
|
requireMoonshotCompat(requireFirstMoonshotModel(cnProvider)).supportsUsageInStreaming,
|
|
).toBe(true);
|
|
|
|
const customProvider = applyMoonshotNativeStreamingUsageCompat({
|
|
...buildMoonshotProvider(),
|
|
baseUrl: "https://proxy.example.com/v1",
|
|
});
|
|
expect(
|
|
"supportsUsageInStreaming" in (requireFirstMoonshotModel(customProvider).compat ?? {}),
|
|
).toBe(false);
|
|
});
|
|
});
|