mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 23:21:23 +00:00
fix(agents): normalize strict openai-compatible turn ordering
Co-authored-by: liuwenyong1985 <48443240+liuwenyong1985@users.noreply.github.com>
This commit is contained in:
@@ -43,4 +43,22 @@ describe("resolveTranscriptPolicy", () => {
|
||||
expect(policy.sanitizeToolCallIds).toBe(false);
|
||||
expect(policy.toolCallIdMode).toBeUndefined();
|
||||
});
|
||||
|
||||
it("enables user-turn merge for strict OpenAI-compatible providers", () => {
|
||||
const policy = resolveTranscriptPolicy({
|
||||
provider: "moonshot",
|
||||
modelId: "kimi-k2.5",
|
||||
modelApi: "openai-completions",
|
||||
});
|
||||
expect(policy.validateAnthropicTurns).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps OpenRouter on its existing turn-validation path", () => {
|
||||
const policy = resolveTranscriptPolicy({
|
||||
provider: "openrouter",
|
||||
modelId: "openai/gpt-4.1",
|
||||
modelApi: "openai-completions",
|
||||
});
|
||||
expect(policy.validateAnthropicTurns).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,6 +38,7 @@ const OPENAI_MODEL_APIS = new Set([
|
||||
"openai-codex-responses",
|
||||
]);
|
||||
const OPENAI_PROVIDERS = new Set(["openai", "openai-codex"]);
|
||||
const OPENAI_COMPAT_TURN_MERGE_EXCLUDED_PROVIDERS = new Set(["openrouter", "opencode"]);
|
||||
|
||||
function isOpenAiApi(modelApi?: string | null): boolean {
|
||||
if (!modelApi) {
|
||||
@@ -84,6 +85,10 @@ export function resolveTranscriptPolicy(params: {
|
||||
const isGoogle = isGoogleModelApi(params.modelApi);
|
||||
const isAnthropic = isAnthropicApi(params.modelApi, provider);
|
||||
const isOpenAi = isOpenAiProvider(provider) || (!provider && isOpenAiApi(params.modelApi));
|
||||
const isStrictOpenAiCompatible =
|
||||
params.modelApi === "openai-completions" &&
|
||||
!isOpenAi &&
|
||||
!OPENAI_COMPAT_TURN_MERGE_EXCLUDED_PROVIDERS.has(provider);
|
||||
const isMistral = isMistralModel({ provider, modelId });
|
||||
const isOpenRouterGemini =
|
||||
(provider === "openrouter" || provider === "opencode") &&
|
||||
@@ -118,7 +123,7 @@ export function resolveTranscriptPolicy(params: {
|
||||
dropThinkingBlocks,
|
||||
applyGoogleTurnOrdering: !isOpenAi && isGoogle,
|
||||
validateGeminiTurns: !isOpenAi && isGoogle,
|
||||
validateAnthropicTurns: !isOpenAi && isAnthropic,
|
||||
validateAnthropicTurns: !isOpenAi && (isAnthropic || isStrictOpenAiCompatible),
|
||||
allowSyntheticToolResults: !isOpenAi && (isGoogle || isAnthropic),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user