























@@ -16,13 +16,13 @@ import * as piAi from "@mariozechner/pi-ai";
1616 * Key behaviours:
1717 * - Per-session `OpenAIWebSocketManager` (keyed by sessionId)
1818 * - Tracks `previous_response_id` to send only incremental tool-result inputs
19- * - Falls back to `streamSimple` (HTTP) if the WebSocket connection fails
19+ * - Falls back to the OpenClaw HTTP transport if the WebSocket connection fails
2020 * - Cleanup helpers for releasing sessions after the run completes
2121 *
2222 * Complexity budget & risk mitigation:
2323 * - **Transport aware**: respects `transport` (`auto` | `websocket` | `sse`)
2424 * - **Transparent fallback in `auto` mode**: connect/send failures fall back to
25- * the existing HTTP `streamSimple`; forced `websocket` mode surfaces WS errors
25+ * the existing HTTP path; forced `websocket` mode surfaces WS errors
2626 * - **Zero shared state**: per-session registry; session cleanup on dispose prevents leaks
2727 * - **Full parity**: all generation options (temperature, top_p, max_output_tokens,
2828 * tool_choice, reasoning) forwarded identically to the HTTP path
@@ -63,7 +63,7 @@ import type { ResponseCreateEvent } from "./openai-ws-types.js";
6363import { log } from "./pi-embedded-runner/logger.js";
6464import { resolveProviderEndpoint } from "./provider-attribution.js";
6565import { normalizeProviderId } from "./provider-id.js";
66-import { createBoundaryAwareStreamFnForModel } from "./provider-transport-stream.js";
66+import { createOpenClawTransportStreamFnForModel } from "./provider-transport-stream.js";
6767import {
6868buildAssistantMessageWithZeroUsage,
6969buildStreamErrorAssistantMessage,
@@ -124,7 +124,9 @@ type AssistantMessageWithPhase = AssistantMessage & { phase?: OpenAIResponsesAss
124124125125const defaultOpenAIWsStreamDeps: OpenAIWsStreamDeps = {
126126createManager: (options) => new OpenAIWebSocketManager(options),
127-createHttpFallbackStreamFn: (model) => createBoundaryAwareStreamFnForModel(model),
127+// WebSocket auto-mode HTTP fallback must keep the OpenClaw transport path so
128+// degraded sessions do not leak cache-boundary markers or lose strict tools.
129+createHttpFallbackStreamFn: (model) => createOpenClawTransportStreamFnForModel(model),
128130streamSimple: (...args) => piAi.streamSimple(...args),
129131};
130132@@ -697,8 +699,8 @@ async function runWarmUp(params: {
697699 * connection; subsequent calls reuse it, sending only incremental tool-result
698700 * inputs with `previous_response_id`.
699701 *
700- * If the WebSocket connection is unavailable, the function falls back to the
701- * standard `streamSimple` HTTP path and logs a warning.
702+ * If the WebSocket connection is unavailable, the function falls back to an
703+ * OpenClaw HTTP transport when available, or the standard `streamSimple` path.
702704 *
703705 * @param apiKey OpenAI API key
704706 * @param sessionId Agent session ID (used as the registry key)
@@ -1358,6 +1360,9 @@ export const __testing = {
13581360}
13591361 : defaultOpenAIWsStreamDeps;
13601362},
1363+getDefaultHttpFallbackStreamFnForTest(model: ProviderRuntimeModel): StreamFn | undefined {
1364+return defaultOpenAIWsStreamDeps.createHttpFallbackStreamFn(model);
1365+},
13611366setWsDegradeCooldownMsForTest(nextMs?: number) {
13621367wsDegradeCooldownMsOverride = nextMs;
13631368},
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。