mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:10:44 +00:00
refactor: share openai realtime close capture
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { captureWsEvent } from "openclaw/plugin-sdk/proxy-capture";
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export const trimToUndefined = normalizeOptionalString;
|
||||
@@ -31,3 +32,27 @@ export function resolveOpenAIProviderConfigRecord(
|
||||
asObjectRecord(providers?.openai) ?? asObjectRecord(config.openai) ?? asObjectRecord(config)
|
||||
);
|
||||
}
|
||||
|
||||
export function captureOpenAIRealtimeWsClose(params: {
|
||||
url: string;
|
||||
flowId: string;
|
||||
capability: "realtime-transcription" | "realtime-voice";
|
||||
code: unknown;
|
||||
reasonBuffer: unknown;
|
||||
}): void {
|
||||
captureWsEvent({
|
||||
url: params.url,
|
||||
direction: "local",
|
||||
kind: "ws-close",
|
||||
flowId: params.flowId,
|
||||
closeCode: typeof params.code === "number" ? params.code : undefined,
|
||||
meta: {
|
||||
provider: "openai",
|
||||
capability: params.capability,
|
||||
reason:
|
||||
Buffer.isBuffer(params.reasonBuffer) && params.reasonBuffer.length > 0
|
||||
? params.reasonBuffer.toString("utf8")
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-i
|
||||
import WebSocket from "ws";
|
||||
import {
|
||||
asFiniteNumber,
|
||||
captureOpenAIRealtimeWsClose,
|
||||
readRealtimeErrorDetail,
|
||||
resolveOpenAIProviderConfigRecord,
|
||||
trimToUndefined,
|
||||
@@ -192,20 +193,12 @@ class OpenAIRealtimeTranscriptionSession implements RealtimeTranscriptionSession
|
||||
});
|
||||
|
||||
this.ws.on("close", (code, reasonBuffer) => {
|
||||
captureWsEvent({
|
||||
captureOpenAIRealtimeWsClose({
|
||||
url,
|
||||
direction: "local",
|
||||
kind: "ws-close",
|
||||
flowId: this.flowId,
|
||||
closeCode: typeof code === "number" ? code : undefined,
|
||||
meta: {
|
||||
provider: "openai",
|
||||
capability: "realtime-transcription",
|
||||
reason:
|
||||
Buffer.isBuffer(reasonBuffer) && reasonBuffer.length > 0
|
||||
? reasonBuffer.toString("utf8")
|
||||
: undefined,
|
||||
},
|
||||
capability: "realtime-transcription",
|
||||
code,
|
||||
reasonBuffer,
|
||||
});
|
||||
this.connected = false;
|
||||
if (this.closed) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-i
|
||||
import WebSocket from "ws";
|
||||
import {
|
||||
asFiniteNumber,
|
||||
captureOpenAIRealtimeWsClose,
|
||||
readRealtimeErrorDetail,
|
||||
resolveOpenAIProviderConfigRecord,
|
||||
trimToUndefined,
|
||||
@@ -293,20 +294,12 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {
|
||||
});
|
||||
|
||||
this.ws.on("close", (code, reasonBuffer) => {
|
||||
captureWsEvent({
|
||||
captureOpenAIRealtimeWsClose({
|
||||
url,
|
||||
direction: "local",
|
||||
kind: "ws-close",
|
||||
flowId: this.flowId,
|
||||
closeCode: typeof code === "number" ? code : undefined,
|
||||
meta: {
|
||||
provider: "openai",
|
||||
capability: "realtime-voice",
|
||||
reason:
|
||||
Buffer.isBuffer(reasonBuffer) && reasonBuffer.length > 0
|
||||
? reasonBuffer.toString("utf8")
|
||||
: undefined,
|
||||
},
|
||||
capability: "realtime-voice",
|
||||
code,
|
||||
reasonBuffer,
|
||||
});
|
||||
this.connected = false;
|
||||
if (this.intentionallyClosed) {
|
||||
|
||||
Reference in New Issue
Block a user