mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:50:44 +00:00
fix(openai-responses): normalize Copilot response item IDs (#69362) (thanks @Menci)
This commit is contained in:
@@ -7,8 +7,21 @@ import {
|
||||
hasCopilotVisionInput,
|
||||
streamWithPayloadPatch,
|
||||
} from "openclaw/plugin-sdk/provider-stream-shared";
|
||||
import { rewriteCopilotResponsePayloadConnectionBoundIds } from "./connection-bound-ids.js";
|
||||
|
||||
type _StreamContext = Parameters<StreamFn>[1];
|
||||
type StreamOptions = Parameters<StreamFn>[2];
|
||||
|
||||
function patchOnPayloadResult(result: unknown): unknown {
|
||||
if (result && typeof result === "object" && "then" in result) {
|
||||
return Promise.resolve(result).then((next) => {
|
||||
rewriteCopilotResponsePayloadConnectionBoundIds(next);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
rewriteCopilotResponsePayloadConnectionBoundIds(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function wrapCopilotAnthropicStream(baseStreamFn: StreamFn | undefined): StreamFn {
|
||||
const underlying = baseStreamFn ?? streamSimple;
|
||||
@@ -36,6 +49,25 @@ export function wrapCopilotAnthropicStream(baseStreamFn: StreamFn | undefined):
|
||||
};
|
||||
}
|
||||
|
||||
export function wrapCopilotProviderStream(ctx: ProviderWrapStreamFnContext): StreamFn {
|
||||
return wrapCopilotAnthropicStream(ctx.streamFn);
|
||||
export function wrapCopilotOpenAIResponsesStream(baseStreamFn: StreamFn | undefined): StreamFn {
|
||||
const underlying = baseStreamFn ?? streamSimple;
|
||||
return (model, context, options) => {
|
||||
if (model.provider !== "github-copilot" || model.api !== "openai-responses") {
|
||||
return underlying(model, context, options);
|
||||
}
|
||||
|
||||
const originalOnPayload = options?.onPayload;
|
||||
const wrappedOptions: StreamOptions = {
|
||||
...options,
|
||||
onPayload: (payload, payloadModel) => {
|
||||
rewriteCopilotResponsePayloadConnectionBoundIds(payload);
|
||||
return patchOnPayloadResult(originalOnPayload?.(payload, payloadModel));
|
||||
},
|
||||
};
|
||||
return underlying(model, context, wrappedOptions);
|
||||
};
|
||||
}
|
||||
|
||||
export function wrapCopilotProviderStream(ctx: ProviderWrapStreamFnContext): StreamFn {
|
||||
return wrapCopilotOpenAIResponsesStream(wrapCopilotAnthropicStream(ctx.streamFn));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user