6989a98d75
- Arkitektur: docs/auth/passwordless-architecture.md - Backend: iom/quixzoom-auth-service/ (FastAPI + Redis) - Webb: quixzoom-market-pages/se/login/ (QR-kod + polling) - App: iom/quixzoom-app/src/features/auth/ (push + deep links) Flöde: QR-kod → app-godkännande → webb-inloggad
64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
import { EventEmitter } from "../../lib/EventEmitter.mjs";
|
|
import { OpenAIError } from "../../error.mjs";
|
|
import { AzureOpenAI } from "../../index.mjs";
|
|
export class OpenAIRealtimeError extends OpenAIError {
|
|
constructor(message, event) {
|
|
super(message);
|
|
this.error = event?.error;
|
|
this.event_id = event?.event_id;
|
|
}
|
|
}
|
|
export class OpenAIRealtimeEmitter extends EventEmitter {
|
|
_onError(event, message, cause) {
|
|
message =
|
|
event?.error ?
|
|
`${event.error.message} code=${event.error.code} param=${event.error.param} type=${event.error.type} event_id=${event.error.event_id}`
|
|
: message ?? 'unknown error';
|
|
if (!this._hasListener('error')) {
|
|
const error = new OpenAIRealtimeError(message +
|
|
`\n\nTo resolve these unhandled rejection errors you should bind an \`error\` callback, e.g. \`rt.on('error', (error) => ...)\` `, event);
|
|
// @ts-ignore
|
|
error.cause = cause;
|
|
Promise.reject(error);
|
|
return;
|
|
}
|
|
const error = new OpenAIRealtimeError(message, event);
|
|
// @ts-ignore
|
|
error.cause = cause;
|
|
this._emit('error', error);
|
|
}
|
|
}
|
|
export function isAzure(client) {
|
|
return client instanceof AzureOpenAI;
|
|
}
|
|
export function buildRealtimeURL(client, connection) {
|
|
const config = typeof connection === 'string' ? { model: connection } : connection;
|
|
const baseURL = client.baseURL;
|
|
const azure = isAzure(client);
|
|
const hasModel = !!config.model;
|
|
const hasCallID = !!config.callID;
|
|
const path = '/realtime';
|
|
const url = new URL(baseURL + (baseURL.endsWith('/') ? path.slice(1) : path));
|
|
if (hasModel === hasCallID) {
|
|
throw new Error('Pass exactly one of `model` or `callID` when opening a Realtime WebSocket.');
|
|
}
|
|
url.protocol = 'wss';
|
|
// Sideband control connections attach to an existing call via `call_id`.
|
|
if (azure) {
|
|
if (hasCallID) {
|
|
throw new Error('Azure `callID` connections require the stable Realtime helpers.');
|
|
}
|
|
url.searchParams.set('api-version', client.apiVersion);
|
|
url.searchParams.set('deployment', config.model);
|
|
}
|
|
else {
|
|
if (hasCallID) {
|
|
url.searchParams.set('call_id', config.callID);
|
|
}
|
|
else {
|
|
url.searchParams.set('model', config.model);
|
|
}
|
|
}
|
|
return url;
|
|
}
|
|
//# sourceMappingURL=internal-base.mjs.map
|