mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
Kimi Coding (claude-format upstream) never engaged reasoning replay: requiresReasoningReplay() had no kimi-coding/kimi-coding-apikey provider entry and only matched /kimi-k2/i model ids, so thinking was neither captured nor re-injected on multi-turn requests. Additionally, streamed Claude thinking_delta chunks were accumulated into content instead of accumulatedReasoning in createSSEStream, so the reconstructed completion body carried no reasoning_content for the cache to capture. - reasoningCache: add kimi-coding/kimi-coding-apikey providers; broaden model pattern to /kimi[-/]k\d/i (covers k2.6/k2.7 incl. namespaced ids, excludes kimi-latest and non-thinking aliases) - stream: accumulate Claude delta.thinking into accumulatedReasoning so the completion body exposes reasoning_content for replay capture - tests: provider/model predicate cases + a reconstructed-stream-body regression test separating thinking from visible text - docs: sync REASONING_REPLAY provider/pattern lists Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
176 lines
5.0 KiB
TypeScript
176 lines
5.0 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const mod = await import("../../open-sse/services/reasoningCache.ts");
|
|
|
|
describe("reasoningCache helpers", () => {
|
|
describe("isDeepSeekReasoningModel", () => {
|
|
it("returns true for deepseek-v4 models with thinking enabled", () => {
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({
|
|
provider: "deepseek",
|
|
model: "deepseek-v4-flash",
|
|
thinkingEnabled: true,
|
|
}),
|
|
true
|
|
);
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({
|
|
provider: "deepseek",
|
|
model: "deepseek/v4-pro",
|
|
thinkingEnabled: true,
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("returns false without thinkingEnabled", () => {
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({ provider: "deepseek", model: "deepseek-v4-flash" }),
|
|
false
|
|
);
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({
|
|
provider: "deepseek",
|
|
model: "deepseek-v4-flash",
|
|
thinkingEnabled: false,
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
|
|
it("returns false for non-v4 models", () => {
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({
|
|
provider: "deepseek",
|
|
model: "deepseek-chat",
|
|
thinkingEnabled: true,
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("requiresReasoningReplay", () => {
|
|
it("returns true for reasoning_content interleaved field", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "any",
|
|
model: "any",
|
|
interleavedField: "reasoning_content",
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("returns false for reasoning_details interleaved field", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "any",
|
|
model: "any",
|
|
interleavedField: "reasoning_details",
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
|
|
it("returns false for deepseek-reasoner", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({ provider: "deepseek", model: "deepseek-reasoner" }),
|
|
false
|
|
);
|
|
});
|
|
|
|
it("returns false for deepseek-r1", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({ provider: "deepseek", model: "deepseek-r1" }),
|
|
false
|
|
);
|
|
});
|
|
|
|
it("returns true for DeepSeek V4 thinking models", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "deepseek",
|
|
model: "deepseek-v4-flash",
|
|
thinkingEnabled: true,
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("returns true for known replay providers", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({ provider: "deepseek", model: "some-model" }),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("returns true for Kimi Coding providers regardless of model alias", () => {
|
|
assert.equal(mod.requiresReasoningReplay({ provider: "kimi-coding", model: "k3" }), true);
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({ provider: "kimi-coding-apikey", model: "kimi-k2.6" }),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("detects native Kimi thinking model IDs without matching unrelated aliases", () => {
|
|
for (const model of [
|
|
"kimi-k2",
|
|
"kimi-k2.6",
|
|
"kimi-k2.6-thinking",
|
|
"kimi-k2.7-code",
|
|
"kimi-k2.7-code-highspeed",
|
|
"moonshotai/kimi-k2.7-code",
|
|
]) {
|
|
assert.equal(mod.requiresReasoningReplay({ provider: "some-other", model }), true, model);
|
|
}
|
|
|
|
for (const model of ["k3", "moonshot-v1-8k", "kimi-latest"]) {
|
|
assert.equal(mod.requiresReasoningReplay({ provider: "some-other", model }), false, model);
|
|
}
|
|
});
|
|
|
|
it("returns false when allowLegacyFallback is false and no explicit signal", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "unknown",
|
|
model: "unknown",
|
|
allowLegacyFallback: false,
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("cache operations", () => {
|
|
it("getReasoningCacheServiceStats returns expected shape", () => {
|
|
const stats = mod.getReasoningCacheServiceStats();
|
|
assert.equal(typeof stats.hits, "number");
|
|
assert.equal(typeof stats.misses, "number");
|
|
assert.equal(typeof stats.replays, "number");
|
|
assert.equal(typeof stats.memoryEntries, "number");
|
|
});
|
|
|
|
it("clearReasoningCacheAll returns a number", () => {
|
|
const cleared = mod.clearReasoningCacheAll();
|
|
assert.equal(typeof cleared, "number");
|
|
});
|
|
|
|
it("lookupReasoning returns null for unknown key", () => {
|
|
const result = mod.lookupReasoning("nonexistent-key-" + Date.now());
|
|
assert.equal(result, null);
|
|
});
|
|
|
|
it("deleteReasoningCacheEntry returns 0 for unknown key", () => {
|
|
const result = mod.deleteReasoningCacheEntry("nonexistent-" + Date.now());
|
|
assert.equal(result, 0);
|
|
});
|
|
|
|
it("cleanupReasoningCache returns a number", () => {
|
|
const cleaned = mod.cleanupReasoningCache();
|
|
assert.equal(typeof cleaned, "number");
|
|
});
|
|
});
|
|
});
|