mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 21:00:44 +00:00
refactor: inline openai realtime config readers
This commit is contained in:
@@ -54,12 +54,6 @@ function normalizeProviderConfig(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function readProviderConfig(
|
|
||||||
providerConfig: RealtimeTranscriptionProviderConfig,
|
|
||||||
): OpenAIRealtimeTranscriptionProviderConfig {
|
|
||||||
return normalizeProviderConfig(providerConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
class OpenAIRealtimeTranscriptionSession implements RealtimeTranscriptionSession {
|
class OpenAIRealtimeTranscriptionSession implements RealtimeTranscriptionSession {
|
||||||
private static readonly MAX_RECONNECT_ATTEMPTS = 5;
|
private static readonly MAX_RECONNECT_ATTEMPTS = 5;
|
||||||
private static readonly RECONNECT_DELAY_MS = 1000;
|
private static readonly RECONNECT_DELAY_MS = 1000;
|
||||||
@@ -234,9 +228,9 @@ export function buildOpenAIRealtimeTranscriptionProvider(): RealtimeTranscriptio
|
|||||||
autoSelectOrder: 10,
|
autoSelectOrder: 10,
|
||||||
resolveConfig: ({ rawConfig }) => normalizeProviderConfig(rawConfig),
|
resolveConfig: ({ rawConfig }) => normalizeProviderConfig(rawConfig),
|
||||||
isConfigured: ({ providerConfig }) =>
|
isConfigured: ({ providerConfig }) =>
|
||||||
Boolean(readProviderConfig(providerConfig).apiKey || process.env.OPENAI_API_KEY),
|
Boolean(normalizeProviderConfig(providerConfig).apiKey || process.env.OPENAI_API_KEY),
|
||||||
createSession: (req) => {
|
createSession: (req) => {
|
||||||
const config = readProviderConfig(req.providerConfig);
|
const config = normalizeProviderConfig(req.providerConfig);
|
||||||
const apiKey = config.apiKey || process.env.OPENAI_API_KEY;
|
const apiKey = config.apiKey || process.env.OPENAI_API_KEY;
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw new Error("OpenAI API key missing");
|
throw new Error("OpenAI API key missing");
|
||||||
|
|||||||
@@ -105,12 +105,6 @@ function normalizeProviderConfig(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function readProviderConfig(
|
|
||||||
providerConfig: RealtimeVoiceProviderConfig,
|
|
||||||
): OpenAIRealtimeVoiceProviderConfig {
|
|
||||||
return normalizeProviderConfig(providerConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
function base64ToBuffer(b64: string): Buffer {
|
function base64ToBuffer(b64: string): Buffer {
|
||||||
return Buffer.from(b64, "base64");
|
return Buffer.from(b64, "base64");
|
||||||
}
|
}
|
||||||
@@ -493,9 +487,9 @@ export function buildOpenAIRealtimeVoiceProvider(): RealtimeVoiceProviderPlugin
|
|||||||
autoSelectOrder: 10,
|
autoSelectOrder: 10,
|
||||||
resolveConfig: ({ rawConfig }) => normalizeProviderConfig(rawConfig),
|
resolveConfig: ({ rawConfig }) => normalizeProviderConfig(rawConfig),
|
||||||
isConfigured: ({ providerConfig }) =>
|
isConfigured: ({ providerConfig }) =>
|
||||||
Boolean(readProviderConfig(providerConfig).apiKey || process.env.OPENAI_API_KEY),
|
Boolean(normalizeProviderConfig(providerConfig).apiKey || process.env.OPENAI_API_KEY),
|
||||||
createBridge: (req) => {
|
createBridge: (req) => {
|
||||||
const config = readProviderConfig(req.providerConfig);
|
const config = normalizeProviderConfig(req.providerConfig);
|
||||||
const apiKey = config.apiKey || process.env.OPENAI_API_KEY;
|
const apiKey = config.apiKey || process.env.OPENAI_API_KEY;
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw new Error("OpenAI API key missing");
|
throw new Error("OpenAI API key missing");
|
||||||
|
|||||||
Reference in New Issue
Block a user