惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
人人都是产品经理
人人都是产品经理
V
Visual Studio Blog
Last Week in AI
Last Week in AI
V
V2EX
博客园_首页
IT之家
IT之家
Jina AI
Jina AI
博客园 - 叶小钗
The Cloudflare Blog
T
Tailwind CSS Blog
腾讯CDC
B
Blog
D
Docker
L
LangChain Blog
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: send OpenClaw attribution to OpenAI · openclaw/openc...
steipete · 2026-04-29 · via Recent Commits to openclaw:main

@@ -1,8 +1,8 @@

11

import { REALTIME_VOICE_AUDIO_FORMAT_PCM16_24KHZ } from "openclaw/plugin-sdk/realtime-voice";

2-

import { beforeEach, describe, expect, it, vi } from "vitest";

2+

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

33

import { buildOpenAIRealtimeVoiceProvider } from "./realtime-voice-provider.js";

445-

const { FakeWebSocket } = vi.hoisted(() => {

5+

const { FakeWebSocket, fetchWithSsrFGuardMock } = vi.hoisted(() => {

66

type Listener = (...args: unknown[]) => void;

7788

class MockWebSocket {

@@ -15,8 +15,10 @@ const { FakeWebSocket } = vi.hoisted(() => {

1515

sent: string[] = [];

1616

closed = false;

1717

terminated = false;

18+

args: unknown[];

181919-

constructor() {

20+

constructor(...args: unknown[]) {

21+

this.args = args;

2022

MockWebSocket.instances.push(this);

2123

}

2224

@@ -49,13 +51,17 @@ const { FakeWebSocket } = vi.hoisted(() => {

4951

}

5052

}

515352-

return { FakeWebSocket: MockWebSocket };

54+

return { FakeWebSocket: MockWebSocket, fetchWithSsrFGuardMock: vi.fn() };

5355

});

54565557

vi.mock("ws", () => ({

5658

default: FakeWebSocket,

5759

}));

586061+

vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({

62+

fetchWithSsrFGuard: fetchWithSsrFGuardMock,

63+

}));

64+5965

type FakeWebSocketInstance = InstanceType<typeof FakeWebSocket>;

6066

type SentRealtimeEvent = {

6167

type: string;

@@ -70,9 +76,93 @@ function parseSent(socket: FakeWebSocketInstance): SentRealtimeEvent[] {

7076

return socket.sent.map((payload: string) => JSON.parse(payload) as SentRealtimeEvent);

7177

}

727879+

function createJsonResponse(body: unknown, init?: { status?: number }): Response {

80+

return new Response(JSON.stringify(body), {

81+

status: init?.status ?? 200,

82+

headers: {

83+

"Content-Type": "application/json",

84+

},

85+

});

86+

}

87+7388

describe("buildOpenAIRealtimeVoiceProvider", () => {

7489

beforeEach(() => {

7590

FakeWebSocket.instances = [];

91+

fetchWithSsrFGuardMock.mockReset();

92+

});

93+94+

afterEach(() => {

95+

vi.unstubAllEnvs();

96+

});

97+98+

it("adds OpenClaw attribution headers to native realtime websocket requests", () => {

99+

vi.stubEnv("OPENCLAW_VERSION", "2026.3.22");

100+

const provider = buildOpenAIRealtimeVoiceProvider();

101+

const bridge = provider.createBridge({

102+

providerConfig: { apiKey: "sk-test" }, // pragma: allowlist secret

103+

onAudio: vi.fn(),

104+

onClearAudio: vi.fn(),

105+

});

106+107+

void bridge.connect();

108+

bridge.close();

109+110+

const socket = FakeWebSocket.instances[0];

111+

const options = socket?.args[1] as { headers?: Record<string, string> } | undefined;

112+

expect(options?.headers).toMatchObject({

113+

originator: "openclaw",

114+

version: "2026.3.22",

115+

"User-Agent": "openclaw/2026.3.22",

116+

});

117+

});

118+119+

it("returns browser-safe OpenClaw attribution headers for native WebRTC offers", async () => {

120+

vi.stubEnv("OPENCLAW_VERSION", "2026.3.22");

121+

fetchWithSsrFGuardMock.mockResolvedValueOnce({

122+

response: createJsonResponse({

123+

client_secret: { value: "client-secret-123" },

124+

expires_at: 1_765_000_000,

125+

}),

126+

release: vi.fn(async () => undefined),

127+

});

128+

const provider = buildOpenAIRealtimeVoiceProvider();

129+

if (!provider.createBrowserSession) {

130+

throw new Error("expected OpenAI realtime provider to support browser sessions");

131+

}

132+133+

const session = await provider.createBrowserSession({

134+

providerConfig: { apiKey: "sk-test" }, // pragma: allowlist secret

135+

instructions: "Be concise.",

136+

});

137+138+

expect(fetchWithSsrFGuardMock).toHaveBeenCalledWith(

139+

expect.objectContaining({

140+

url: "https://api.openai.com/v1/realtime/client_secrets",

141+

init: expect.objectContaining({

142+

method: "POST",

143+

headers: expect.objectContaining({

144+

Authorization: "Bearer sk-test", // pragma: allowlist secret

145+

"Content-Type": "application/json",

146+

originator: "openclaw",

147+

version: "2026.3.22",

148+

"User-Agent": "openclaw/2026.3.22",

149+

}),

150+

}),

151+

}),

152+

);

153+

expect(session).toMatchObject({

154+

provider: "openai",

155+

transport: "webrtc-sdp",

156+

clientSecret: "client-secret-123",

157+

offerUrl: "https://api.openai.com/v1/realtime/calls",

158+

offerHeaders: {

159+

originator: "openclaw",

160+

version: "2026.3.22",

161+

},

162+

});

163+

expect((session as { offerHeaders?: Record<string, string> }).offerHeaders).not.toHaveProperty(

164+

"User-Agent",

165+

);

76166

});

7716778168

it("normalizes provider-owned voice settings from raw provider config", () => {