{"version":3,"file":"utils/error-handler.mjs","sources":["webpack://@agent-tars/server/./src/utils/error-handler.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * ErrorWithCode - Extended Error class with error code\n * Provides structured error information for better handling\n */\nexport class ErrorWithCode extends Error {\n  constructor(\n    message: string,\n    public code: string,\n    public details?: Record<string, any>,\n  ) {\n    super(message);\n    this.name = 'AgentTARSError';\n  }\n}\n\n/**\n * Safely handles agent errors to prevent process crashes\n * @param error The error to handle\n * @param context Additional context for logging\n * @returns Normalized error object\n */\nexport function handleAgentError(error: unknown, context?: string): ErrorWithCode {\n  // Log the error with context\n  console.error(`Agent error${context ? ` [${context}]` : ''}:`, error);\n\n  // Normalize to ErrorWithCode\n  if (error instanceof ErrorWithCode) {\n    return error;\n  }\n\n  // Create structured error from generic error\n  if (error instanceof Error) {\n    return new ErrorWithCode(\n      error.message,\n      'AGENT_EXECUTION_ERROR',\n      { stack: error.stack }\n    );\n  }\n\n  // Handle non-Error objects\n  return new ErrorWithCode(\n    typeof error === 'string' ? error : 'Unknown agent execution error',\n    'UNKNOWN_ERROR',\n    { originalError: error }\n  );\n}\n\n/**\n * Error response structure for agent errors\n */\nexport interface AgentErrorResponse {\n  success: false;\n  error: {\n    code: string;\n    message: string;\n    details?: Record<string, any>;\n  };\n}\n\n/**\n * Creates a standardized error response\n */\nexport function createErrorResponse(error: unknown): AgentErrorResponse {\n  const normalizedError = handleAgentError(error);\n  \n  return {\n    success: false,\n    error: {\n      code: normalizedError.code,\n      message: normalizedError.message,\n      details: normalizedError.details,\n    }\n  };\n}\n"],"names":["ErrorWithCode","Error","message","code","details","handleAgentError","error","context","console","createErrorResponse","normalizedError"],"mappings":";;;;AAQC;;;;;;;;;;AACM,MAAMA,sBAAsBC;IACjC,YACEC,OAAe,EACRC,IAAY,EACZC,OAA6B,CACpC;QACA,KAAK,CAACF,UAAAA,iBAAAA,IAAAA,EAAAA,QAAAA,KAAAA,IAAAA,iBAAAA,IAAAA,EAAAA,WAAAA,KAAAA,IAAAA,IAAAA,CAHCC,IAAI,GAAJA,MAAAA,IAAAA,CACAC,OAAO,GAAPA;QAGP,IAAI,CAAC,IAAI,GAAG;IACd;AACF;AAQO,SAASC,iBAAiBC,KAAc,EAAEC,OAAgB;IAE/DC,QAAQ,KAAK,CAAC,CAAC,WAAW,EAAED,UAAU,CAAC,EAAE,EAAEA,QAAQ,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAED;IAG/D,IAAIA,iBAAiBN,eACnB,OAAOM;IAIT,IAAIA,iBAAiBL,OACnB,OAAO,IAAID,cACTM,MAAM,OAAO,EACb,yBACA;QAAE,OAAOA,MAAM,KAAK;IAAC;IAKzB,OAAO,IAAIN,cACT,AAAiB,YAAjB,OAAOM,QAAqBA,QAAQ,iCACpC,iBACA;QAAE,eAAeA;IAAM;AAE3B;AAiBO,SAASG,oBAAoBH,KAAc;IAChD,MAAMI,kBAAkBL,iBAAiBC;IAEzC,OAAO;QACL,SAAS;QACT,OAAO;YACL,MAAMI,gBAAgB,IAAI;YAC1B,SAASA,gBAAgB,OAAO;YAChC,SAASA,gBAAgB,OAAO;QAClC;IACF;AACF"}