UNPKG

agents

Version:

A home for your AI agents

41 lines (40 loc) 1.64 kB
//#region src/voice/errors.ts const MAX_CLIENT_MESSAGE_LENGTH = 300; /** * Error raised at a voice provider boundary. Only known, content-free provider * metadata belongs here. Provider response bodies and raw events must stay out. */ var VoiceProviderError = class extends Error { constructor(message, options = {}) { super(message); this.name = "VoiceProviderError"; if (options.code !== void 0) this.code = options.code; if (options.status !== void 0) this.status = options.status; if (options.closeCode !== void 0) this.closeCode = options.closeCode; if (options.closeReason !== void 0) this.closeReason = options.closeReason; if (options.wasClean !== void 0) this.wasClean = options.wasClean; } }; /** Convert a value caught from an external boundary without inspecting it. */ function toVoiceError(error, fallback) { return error instanceof Error ? error : new Error(fallback); } /** Return a bounded direct message suitable for the existing string wire API. */ function voiceErrorMessage(error, fallback) { const message = error.message.trim(); if (!message || message === "[object Object]") return fallback; return message.slice(0, MAX_CLIENT_MESSAGE_LENGTH); } /** Emit one structured object so Workers Logs can extract diagnostic fields. */ function logVoiceError(options) { console.error({ component: options.component, stage: options.stage, message: options.message, ...options.connectionId ? { connectionId: options.connectionId } : {}, error: options.error }); } //#endregion export { VoiceProviderError, logVoiceError, toVoiceError, voiceErrorMessage }; //# sourceMappingURL=errors.js.map