






















1+import OpenAI from "openai";
2+import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
3+import type { Model } from "openclaw/plugin-sdk/llm";
4+import { createAssistantMessageEventStream } from "openclaw/plugin-sdk/llm";
5+import { describe, expect, it } from "vitest";
6+import { isLiveTestEnabled } from "../../../agents/live-test-helpers.js";
7+import { createOpenAIAnthropicToolPayloadCompatibilityWrapper } from "./anthropic-family-tool-payload-compat.js";
8+9+const OPENAI_KEY = process.env.OPENAI_API_KEY ?? "";
10+const LIVE = isLiveTestEnabled(["OPENAI_LIVE_TEST"]) && Boolean(OPENAI_KEY);
11+const describeLive = LIVE ? describe : describe.skip;
12+13+describeLive("OpenAI-compatible Anthropic tool payload wrapper live", () => {
14+it("sends a healthy pinned tool after quarantining an unreadable sibling", async () => {
15+const liveModelId = process.env.OPENCLAW_LIVE_OPENAI_CHAT_TOOL_MODEL || "gpt-5.5";
16+let projectedPayload: Record<string, unknown> | undefined;
17+const baseStreamFn: StreamFn = (model, context, options) => {
18+const payload: Record<string, unknown> = {
19+model: liveModelId,
20+messages: [
21+{
22+role: "user",
23+content: "Call live_probe with value exactly OPENAI_WRAPPER_OK.",
24+},
25+],
26+tools: [
27+{
28+name: "unreadable_probe",
29+parameters: {
30+type: "object",
31+properties: {
32+get value(): never {
33+throw new Error("live unreadable nested schema getter");
34+},
35+},
36+},
37+},
38+{
39+name: "live_probe",
40+description: "Return the requested probe value.",
41+input_schema: {
42+type: "object",
43+properties: { value: { type: "string" } },
44+required: ["value"],
45+},
46+},
47+],
48+tool_choice: { type: "tool", name: "live_probe" },
49+max_completion_tokens: 128,
50+};
51+options?.onPayload?.(payload, model);
52+projectedPayload = structuredClone(payload);
53+return createAssistantMessageEventStream();
54+};
55+const wrapped = createOpenAIAnthropicToolPayloadCompatibilityWrapper(baseStreamFn);
56+const model = {
57+api: "anthropic-messages",
58+provider: "openai-compatible-anthropic",
59+id: liveModelId,
60+compat: { requiresOpenAiAnthropicToolPayload: true },
61+} as unknown as Model<"anthropic-messages">;
62+63+void wrapped(model, { messages: [] }, {});
64+if (!projectedPayload) {
65+throw new Error("wrapper did not produce a payload");
66+}
67+68+const client = new OpenAI({ apiKey: OPENAI_KEY });
69+const response = await client.chat.completions.create(
70+projectedPayload as unknown as OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming,
71+);
72+const toolCall = response.choices[0]?.message.tool_calls?.[0];
73+74+if (!toolCall || toolCall.type !== "function") {
75+throw new Error("OpenAI did not return the expected function tool call");
76+}
77+expect(toolCall.function.name).toBe("live_probe");
78+expect(JSON.parse(toolCall.function.arguments)).toEqual({
79+value: "OPENAI_WRAPPER_OK",
80+});
81+}, 45_000);
82+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。