Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

5.1 KB
Raw Blame
import type { ILobeAgentRuntimeErrorType } from './agentRuntime';

export const ChatErrorType = {
  // ******* Business Error Semantics ******* //

  InvalidAccessCode: 'InvalidAccessCode', // is in valid password
  FreePlanLimit: 'FreePlanLimit', // Free plan usage limit
  SubscriptionPlanLimit: 'SubscriptionPlanLimit', // Subscription user limit exceeded
  InsufficientBudgetForModel: 'InsufficientBudgetForModel', // Has credits but not enough for estimated model cost
  WorkspaceFrozenByAdmin: 'WorkspaceFrozenByAdmin', // Workspace manually frozen by admin (reason is operator-written, safe to surface)
  WorkspaceFrozenByRiskControl: 'WorkspaceFrozenByRiskControl', // Workspace auto-frozen by risk control (reason is engineer debug text, hide from user)
  WorkspaceModelRestricted: 'WorkspaceModelRestricted', // A workspace admin restricted the LobeHub model this member asked for
  WorkspaceSubscriptionInactive: 'WorkspaceSubscriptionInactive', // Workspace's paid subscription has lapsed β€” view-only for non-primary members; spend blocked until renewed
  ShareMessageLimitExceeded: 'ShareMessageLimitExceeded', // Visitor hit shareConfig.maxMessagesPerVisitor on this shared agent
  ShareSpendLimitExceeded: 'ShareSpendLimitExceeded', // Shared agent reached shareConfig.monthlySpendLimit for the current month β€” recovers on the next reset
  SharePromptTooLong: 'SharePromptTooLong', // Visitor's message to a shared agent is longer than SHARE_VISITOR_PROMPT_MAX_LENGTH
  ShareHeterogeneousAgentUnsupported: 'ShareHeterogeneousAgentUnsupported', // This agent configuration is not supported for shared visitors
  ShareHeteroDeviceUnavailable: 'ShareHeteroDeviceUnavailable', // The shared local CLI agent's device is offline or not set β€” visitor can retry later
  ChannelAttachmentUnavailable: 'ChannelAttachmentUnavailable', // A Channel send names a file the sender cannot attach there (e.g. uploaded in another workspace) β€” resending the same files never succeeds
  AgentShareProviderNotSupported: 'AgentShareProviderNotSupported', // This shared agent uses a provider that is not supported for shared visitors
  SupervisorDecisionFailed: 'SupervisorDecisionFailed', // Supervisor decision failed
  AgentConcurrencyLimitExceeded: 'AgentConcurrencyLimitExceeded', // The user already has as many agent runs in flight as allowed β€” recovers when one finishes
  InsufficientBudgetForAgentRunFee: 'InsufficientBudgetForAgentRunFee', // The user's credits cannot pay the per-run agent fee β€” refused before the run starts, also on the user's own provider key

  InvalidUserKey: 'InvalidUserKey', // is not valid User key
  CreateMessageError: 'CreateMessageError',
  LobeHubModelDeprecated: 'LobeHubModelDeprecated', // requested LobeHub model is no longer available
  /**
   * @deprecated
   */
  NoOpenAIAPIKey: 'NoOpenAIAPIKey',
  OllamaServiceUnavailable: 'OllamaServiceUnavailable', // Ollama service not started/detected
  PluginFailToTransformArguments: 'PluginFailToTransformArguments',
  UnknownChatFetchError: 'UnknownChatFetchError',
  SystemTimeNotMatchError: 'SystemTimeNotMatchError',
  ServerAgentRuntimeError: 'ServerAgentRuntimeError',
  DeviceGatewayNotConfigured: 'DeviceGatewayNotConfigured', // Heterogeneous agent has no reachable run device / gateway
  DeviceResponseTimeout: 'DeviceResponseTimeout', // Run reached the device, which did not answer in time

  // ******* Desktop Backend-Proxy Network Errors ******* //
  // Emitted by the Electron backend proxy when the upstream fetch fails at the
  // network level β€” usually the user's own network/proxy/VPN, not a server bug.
  RemoteServerOffline: 'RemoteServerOffline',
  RemoteServerTimeout: 'RemoteServerTimeout',
  RemoteServerDNSFailed: 'RemoteServerDNSFailed',
  RemoteServerConnectionRefused: 'RemoteServerConnectionRefused',
  RemoteServerCertInvalid: 'RemoteServerCertInvalid',
  RemoteServerUnreachable: 'RemoteServerUnreachable',

  // ******* Client Errors ******* //
  BadRequest: 400,
  Unauthorized: 401,
  Forbidden: 403,
  ContentNotFound: 404, // Endpoint not found
  MethodNotAllowed: 405, // Method not supported
  TooManyRequests: 429,

  // ******* Server Errors ******* //InvalidPluginArgumentsTransform
  InternalServerError: 500,
  BadGateway: 502,
  ServiceUnavailable: 503,
  GatewayTimeout: 504,
} as const;

export type ErrorType = (typeof ChatErrorType)[keyof typeof ChatErrorType];

const remoteServerNetworkErrorTypes = [
  ChatErrorType.RemoteServerOffline,
  ChatErrorType.RemoteServerTimeout,
  ChatErrorType.RemoteServerDNSFailed,
  ChatErrorType.RemoteServerConnectionRefused,
  ChatErrorType.RemoteServerCertInvalid,
  ChatErrorType.RemoteServerUnreachable,
] as const;

export type RemoteServerNetworkErrorType = (typeof remoteServerNetworkErrorTypes)[number];

const remoteServerNetworkErrorTypeSet = new Set<string>(remoteServerNetworkErrorTypes);

export const isRemoteServerNetworkError = (
  errorType: unknown,
): errorType is RemoteServerNetworkErrorType =>
  typeof errorType === 'string' && remoteServerNetworkErrorTypeSet.has(errorType);

export interface ErrorResponse {
  body: any;
  errorType: ErrorType | ILobeAgentRuntimeErrorType;
}