公众号验证码功能完成 yeah!!!

This commit is contained in:
2025-11-21 15:33:03 +08:00
parent ad35173301
commit 6330f6faa1
614 changed files with 31574 additions and 4571 deletions

View File

@@ -9,12 +9,20 @@ class OpenAIRealtimeWS extends internal_base_1.OpenAIRealtimeEmitter {
constructor(props, client) {
super();
client ?? (client = new index_1.OpenAI());
const hasProvider = typeof client?._options?.apiKey === 'function';
if (hasProvider && !props.__resolvedApiKey) {
throw new Error([
'Cannot open Realtime WebSocket with a function-based apiKey.',
'Use the .create() method so that the key is resolved before connecting:',
'await OpenAIRealtimeWS.create(client, { model })',
].join('\n'));
}
this.url = (0, internal_base_1.buildRealtimeURL)(client, props.model);
this.socket = new WS.WebSocket(this.url, {
...props.options,
headers: {
...props.options?.headers,
...((0, internal_base_1.isAzure)(client) ? {} : { Authorization: `Bearer ${client.apiKey}` }),
...((0, internal_base_1.isAzure)(client) && !props.__resolvedApiKey ? {} : { Authorization: `Bearer ${client.apiKey}` }),
'OpenAI-Beta': 'realtime=v1',
},
});
@@ -43,12 +51,26 @@ class OpenAIRealtimeWS extends internal_base_1.OpenAIRealtimeEmitter {
this._onError(null, err.message, err);
});
}
static async azure(client, options = {}) {
const deploymentName = options.deploymentName ?? client.deploymentName;
static async create(client, props) {
return new OpenAIRealtimeWS({ ...props, __resolvedApiKey: await client._callApiKey() }, client);
}
static async azure(client, props = {}) {
const isApiKeyProvider = await client._callApiKey();
const deploymentName = props.deploymentName ?? client.deploymentName;
if (!deploymentName) {
throw new Error('No deployment name provided');
}
return new OpenAIRealtimeWS({ model: deploymentName, options: { headers: await getAzureHeaders(client) } }, client);
return new OpenAIRealtimeWS({
model: deploymentName,
options: {
...props.options,
headers: {
...props.options?.headers,
...(isApiKeyProvider ? {} : { 'api-key': client.apiKey }),
},
},
__resolvedApiKey: isApiKeyProvider,
}, client);
}
send(event) {
try {
@@ -68,18 +90,4 @@ class OpenAIRealtimeWS extends internal_base_1.OpenAIRealtimeEmitter {
}
}
exports.OpenAIRealtimeWS = OpenAIRealtimeWS;
async function getAzureHeaders(client) {
if (client.apiKey !== '<Missing Key>') {
return { 'api-key': client.apiKey };
}
else {
const token = await client._getAzureADToken();
if (token) {
return { Authorization: `Bearer ${token}` };
}
else {
throw new Error('AzureOpenAI is not instantiated correctly. No API key or token provided.');
}
}
}
//# sourceMappingURL=ws.js.map