{"version":3,"file":"user-error-ClE_1vih-sec20261128.js","names":["VOICE_ACCOUNT_ERROR_CODES","const","VoiceAccountErrorCode","isVoiceAccountErrorCode","value","includes","MessageBlock","CALL_CLIENT_NONCE_PREFIX","phoneCallSettings","source","Record","positive","value","fallback","parsed","Number","isFinite","phoneCallsEnabled","PHONE_CALLS_ENABLED","phoneCallCooldownMinutes","PHONE_CALL_COOLDOWN_MINUTES","phoneCallRingSeconds","PHONE_CALL_RING_SECONDS","CallRequestBlock","Extract","kind","callRequestClientNonce","callId","includes","Error","callRequestBlock","blocks","block","undefined","ringingCall","messages","ReadonlyArray","role","now","Date","Pick","message","Array","isArray","status","callIsRinging","reason","opening","expiresAt","call","parse","nextIncomingCall","incomingCall","bots","T","handled","ReadonlySet","find","bot","has","CALL_NOT_RINGING_ERROR","respondToIncomingCall","respond","Promise","i18n","_i18n","CONNECTOR_AUTH_UNAVAILABLE","isVoiceAccountErrorCode","MCP_OAUTH_CLIENT_REQUIRED","CredentialField","authErrorMessage","CALL_NOT_RINGING_ERROR","errorHelpUrl","MAX_PASSWORD_LENGTH","MODEL_IMAGE_INPUT_ERROR","MODEL_IMAGE_INPUT_UNKNOWN","userErrorMessage","errorText","error","fallback","_","id","message","undefined","trim","errorCode","voiceAccountErrorText","offline","code","credentialIssueText","field","authErrorText","values","email","password","errorDetails","helpUrl","ErrorDetails","ReturnType","_i18n","i18n","authErrorMessage","userErrorMessage","errorHelpUrl","VOICE_ACCOUNT_ERROR_CODES","isVoiceAccountErrorCode","value","callRequestBlock","block","blocks","callIsRinging","call","now","nextIncomingCall","bots","bot","handled","CALL_NOT_RINGING_ERROR","respondToIncomingCall","respond","errorText","message","error","errorCode","voiceAccountErrorText","code","credentialIssueText","field","authErrorText","errorDetails","fallback"],"sources":["../../../../packages/contracts/src/models/voice-errors.ts","../../../../packages/core/src/calls/call-request.ts","../../src/lib/query/user-error.ts"],"sourcesContent":["/** Voice failures the user fixes in their own provider account. Clients show their own copy. */\nexport const VOICE_ACCOUNT_ERROR_CODES = [\"VOICE_OUT_OF_CREDIT\", \"VOICE_KEY_REJECTED\"] as const;\n\nexport type VoiceAccountErrorCode = (typeof VOICE_ACCOUNT_ERROR_CODES)[number];\n\nexport function isVoiceAccountErrorCode(value: unknown): value is VoiceAccountErrorCode {\n  return (VOICE_ACCOUNT_ERROR_CODES as readonly unknown[]).includes(value);\n}\n","import type { MessageBlock } from \"@rakazo/contracts\";\nimport { CALL_CLIENT_NONCE_PREFIX } from \"./call-nonce.js\";\n\n/** Server settings shared by the API and worker. Calls require an explicit opt-in. */\nexport function phoneCallSettings(source: Record<string, string | undefined> = {}) {\n  const positive = (value: string | undefined, fallback: number) => {\n    const parsed = Number(value);\n    return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;\n  };\n  return {\n    phoneCallsEnabled: source.PHONE_CALLS_ENABLED === \"true\",\n    phoneCallCooldownMinutes: positive(source.PHONE_CALL_COOLDOWN_MINUTES, 2),\n    phoneCallRingSeconds: positive(source.PHONE_CALL_RING_SECONDS, 45),\n  };\n}\n\nexport type CallRequestBlock = Extract<MessageBlock, { kind: \"call_request\" }>;\n\n/**\n * The call request's own nonce: it carries the call id like every message on\n * the call, so the transcript groups the request with the conversation, and it\n * is the idempotency key for the request.\n */\nexport function callRequestClientNonce(callId: string): string {\n  if (callId.includes(\":\")) throw new Error(`callId must not contain \":\": ${callId}`);\n  return `${CALL_CLIENT_NONCE_PREFIX}${callId}:request`;\n}\n\nexport function callRequestBlock(\n  blocks: readonly MessageBlock[] | null | undefined,\n): CallRequestBlock | undefined {\n  const block = blocks?.[0];\n  return block?.kind === \"call_request\" ? block : undefined;\n}\n\n/** The call still ringing among a chat's newest messages, if any. */\nexport function ringingCall(\n  messages: ReadonlyArray<{ role: string; blocks: unknown }>,\n  now = Date.now(),\n): Pick<CallRequestBlock, \"callId\" | \"reason\" | \"opening\" | \"expiresAt\"> | null {\n  for (const message of messages) {\n    if (message.role !== \"bot\" || !Array.isArray(message.blocks)) continue;\n    const block = callRequestBlock(message.blocks as MessageBlock[]);\n    if (block?.status !== \"ringing\") continue;\n    if (!callIsRinging(block, now)) continue;\n    return {\n      callId: block.callId,\n      reason: block.reason,\n      opening: block.opening,\n      expiresAt: block.expiresAt,\n    };\n  }\n  return null;\n}\n\n/** One expiry rule for roster state, foreground UI, and native push handoffs. */\nexport function callIsRinging(call: { expiresAt: string }, now = Date.now()): boolean {\n  return Date.parse(call.expiresAt) > now;\n}\n\nexport function nextIncomingCall<\n  T extends { incomingCall?: { callId: string; expiresAt: string } | null },\n>(bots: readonly T[], handled: ReadonlySet<string>, now = Date.now()): T | undefined {\n  return bots.find(\n    (bot) =>\n      bot.incomingCall &&\n      !handled.has(bot.incomingCall.callId) &&\n      callIsRinging(bot.incomingCall, now),\n  );\n}\n\nexport const CALL_NOT_RINGING_ERROR = \"This call is no longer ringing.\";\n\n/** Both surfaces use the same action and reject stale answers before opening audio. */\nexport async function respondToIncomingCall<T>(\n  call: { expiresAt: string },\n  respond: () => Promise<T>,\n): Promise<T> {\n  if (!callIsRinging(call)) throw new Error(CALL_NOT_RINGING_ERROR);\n  return respond();\n}\n","import { t } from \"@lingui/core/macro\";\nimport {\n  CONNECTOR_AUTH_UNAVAILABLE,\n  isVoiceAccountErrorCode,\n  MCP_OAUTH_CLIENT_REQUIRED,\n} from \"@rakazo/contracts\";\nimport type { CredentialField } from \"@rakazo/core\";\nimport {\n  authErrorMessage,\n  CALL_NOT_RINGING_ERROR,\n  errorHelpUrl,\n  MAX_PASSWORD_LENGTH,\n  MODEL_IMAGE_INPUT_ERROR,\n  MODEL_IMAGE_INPUT_UNKNOWN,\n  userErrorMessage,\n} from \"@rakazo/core\";\n\n/** Text for a failure: human messages pass through; network and implementation detail become copy. */\nexport function errorText(error: unknown, fallback = t`Something went wrong. Try again.`): string {\n  const message =\n    typeof error === \"string\"\n      ? error\n      : error && typeof error === \"object\" && \"message\" in error\n        ? error.message\n        : undefined;\n  if (typeof message === \"string\" && message.trim() === MODEL_IMAGE_INPUT_ERROR)\n    return t`This model cannot read images. Choose a model that supports images.`;\n  if (typeof message === \"string\" && message.trim() === MODEL_IMAGE_INPUT_UNKNOWN)\n    return t`Image input is not configured for this model.`;\n  if (typeof message === \"string\" && message.trim() === CALL_NOT_RINGING_ERROR)\n    return t`This call is no longer ringing.`;\n  if (errorCode(error) === CONNECTOR_AUTH_UNAVAILABLE)\n    return t`This app needs its own sign-in setup to connect.`;\n  if (errorCode(error) === MCP_OAUTH_CLIENT_REQUIRED) return t`Needs an OAuth client ID`;\n  return (\n    voiceAccountErrorText(error) ??\n    userErrorMessage(error, { fallback, offline: t`Could not reach the server` })\n  );\n}\n\n/** Text for an RPC error or `/api/voice` body whose code says the voice account needs attention. */\nexport function voiceAccountErrorText(error: unknown): string | undefined {\n  const code = errorCode(error);\n  if (!isVoiceAccountErrorCode(code)) return undefined;\n  return code === \"VOICE_OUT_OF_CREDIT\"\n    ? t`Your voice provider is out of credit.`\n    : t`Your voice provider key was rejected.`;\n}\n\nexport function errorCode(error: unknown): unknown {\n  return error && typeof error === \"object\" && \"code\" in error ? error.code : undefined;\n}\n\nexport function credentialIssueText(field: CredentialField): string {\n  return field === \"email\" ? t`Enter a valid email` : t`Enter a password`;\n}\n\n/** Text for a failed Better Auth client result (`{ code, message }`). */\nexport function authErrorText(error: unknown, fallback: string): string {\n  const code = error && typeof error === \"object\" && \"code\" in error ? error.code : undefined;\n  if (code === \"SSO_UNAVAILABLE\") return t`SSO is temporarily unavailable. Try again.`;\n  if (code === \"account_not_linked\")\n    return t`Sign in to your account, then link this provider in settings`;\n  if (code === \"email_does_not_match\") return t`Use an account with the same email address`;\n  if (code === \"ACCOUNT_DEACTIVATED\") return t`This account is deactivated`;\n  if (code === \"REGISTRATION_CLOSED\") return t`Registration is closed`;\n  if (code === \"EMAIL_NOT_ALLOWED\") return t`Email is not allowed to register`;\n  if (code === \"EMAIL_VERIFICATION_REQUIRED\" || code === \"unable_to_link_account\")\n    return t`Email verification required`;\n  if (code === \"REAUTHENTICATION_REQUIRED\") return t`Sign in again`;\n  if (code === \"PASSWORD_AUTH_DISABLED\") return t`Password sign-in is turned off on this server`;\n  if (code === \"PASSWORD_TOO_LONG\")\n    return t`Password must be ${MAX_PASSWORD_LENGTH} characters or fewer`;\n  if (code === \"EMAIL_DELETION_UNAVAILABLE\") return t`Could not continue`;\n  if (code === \"INVALID_OTP\") return t`Invalid code`;\n  if (code === \"OTP_EXPIRED\" || code === \"TOO_MANY_ATTEMPTS\") return t`Request a new code`;\n  return authErrorMessage(error, {\n    fallback,\n    email: credentialIssueText(\"email\"),\n    password: credentialIssueText(\"password\"),\n  });\n}\n\n/** Keep the documented error code's help link when turning a failure into UI copy. */\nexport function errorDetails(error: unknown, fallback?: string) {\n  return { message: errorText(error, fallback), helpUrl: errorHelpUrl(error) };\n}\n\nexport type ErrorDetails = ReturnType<typeof errorDetails>;\n"],"mappings":"A,uHACA,IAAaA,EAA4B,CAAC,sBAAuB,oBAAoB,EAIrF,SAAgBG,EAAwBC,EAAgD,CACtF,OAAQJ,EAAiDK,SAASD,CAAK,CACzE,CCqBA,SAAgB0B,EACdC,EAC8B,CAC9B,IAAMC,EAAQD,IAAS,GACvB,OAAOC,GAAOP,OAAS,eAAiBO,EAAQC,IAAAA,EAClD,CAuBA,SAAgBY,EAAcI,EAA6BX,EAAMC,KAAKD,IAAI,EAAY,CACpF,OAAOC,KAAKW,MAAMD,EAAKD,SAAS,EAAIV,CACtC,CAEA,SAAgBa,EAEdE,EAAoBE,EAA8BjB,EAAMC,KAAKD,IAAI,EAAkB,CACnF,OAAOe,EAAKI,KACTC,GACCA,EAAIN,cACJ,CAACG,EAAQI,IAAID,EAAIN,aAAazB,MAAM,GACpCkB,EAAca,EAAIN,aAAcd,CAAG,CACvC,CACF,CAEA,IAAasB,EAAyB,kCAGtC,eAAsBC,EACpBZ,EACAa,EACY,CACZ,GAAI,CAACjB,EAAcI,CAAI,EAAG,MAAUpB,MAAM+B,CAAsB,EAChE,OAAOE,E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