mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 14:11:26 +00:00
refactor(providers): share xai and replay helpers
This commit is contained in:
27
src/plugins/provider-replay-helpers.test.ts
Normal file
27
src/plugins/provider-replay-helpers.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildOpenAICompatibleReplayPolicy,
|
||||
buildStrictAnthropicReplayPolicy,
|
||||
} from "./provider-replay-helpers.js";
|
||||
|
||||
describe("provider replay helpers", () => {
|
||||
it("builds strict openai-completions replay policy", () => {
|
||||
expect(buildOpenAICompatibleReplayPolicy("openai-completions")).toMatchObject({
|
||||
sanitizeToolCallIds: true,
|
||||
toolCallIdMode: "strict",
|
||||
applyAssistantFirstOrderingFix: true,
|
||||
validateGeminiTurns: true,
|
||||
validateAnthropicTurns: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("builds strict anthropic replay policy", () => {
|
||||
expect(buildStrictAnthropicReplayPolicy({ dropThinkingBlocks: true })).toMatchObject({
|
||||
sanitizeMode: "full",
|
||||
preserveSignatures: true,
|
||||
repairToolUseResultPairing: true,
|
||||
allowSyntheticToolResults: true,
|
||||
dropThinkingBlocks: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
45
src/plugins/provider-replay-helpers.ts
Normal file
45
src/plugins/provider-replay-helpers.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { ProviderReplayPolicy } from "./types.js";
|
||||
|
||||
export function buildOpenAICompatibleReplayPolicy(
|
||||
modelApi: string | null | undefined,
|
||||
): ProviderReplayPolicy | undefined {
|
||||
if (
|
||||
modelApi !== "openai-completions" &&
|
||||
modelApi !== "openai-responses" &&
|
||||
modelApi !== "openai-codex-responses" &&
|
||||
modelApi !== "azure-openai-responses"
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
sanitizeToolCallIds: true,
|
||||
toolCallIdMode: "strict",
|
||||
...(modelApi === "openai-completions"
|
||||
? {
|
||||
applyAssistantFirstOrderingFix: true,
|
||||
validateGeminiTurns: true,
|
||||
validateAnthropicTurns: true,
|
||||
}
|
||||
: {
|
||||
applyAssistantFirstOrderingFix: false,
|
||||
validateGeminiTurns: false,
|
||||
validateAnthropicTurns: false,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildStrictAnthropicReplayPolicy(
|
||||
options: { dropThinkingBlocks?: boolean } = {},
|
||||
): ProviderReplayPolicy {
|
||||
return {
|
||||
sanitizeMode: "full",
|
||||
sanitizeToolCallIds: true,
|
||||
toolCallIdMode: "strict",
|
||||
preserveSignatures: true,
|
||||
repairToolUseResultPairing: true,
|
||||
validateAnthropicTurns: true,
|
||||
allowSyntheticToolResults: true,
|
||||
...(options.dropThinkingBlocks ? { dropThinkingBlocks: true } : {}),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user