{"version":3,"file":"errors-BuF9bYOQ.mjs","names":[],"sources":["../src/core/errors.ts"],"sourcesContent":["export const sandboxErrorCodes = [\n  \"authentication\",\n  \"permission\",\n  \"not_found\",\n  \"timeout\",\n  \"rate_limited\",\n  \"unavailable\",\n  \"unsupported\",\n  \"invalid_input\",\n  \"conflict\",\n  \"terminated\",\n  \"process_failed\",\n  \"internal\",\n] as const;\n\nexport type SandboxErrorCode = (typeof sandboxErrorCodes)[number];\n\nconst sensitive =\n  /((?:token|key|secret|authorization|credential|signature)=?)[^\\s&,]+|https?:\\/\\/[^\\s]+(?:token|sig|signature|key)=[^\\s&]+/gi;\n\nexport function redactSensitive(value: string): string {\n  return value.replace(sensitive, \"$1[REDACTED]\");\n}\n\nexport class SandboxError extends Error {\n  readonly code: SandboxErrorCode;\n  readonly provider: string;\n  readonly operation?: string;\n  readonly retryable: boolean;\n  override readonly cause?: unknown;\n\n  constructor(options: {\n    code: SandboxErrorCode;\n    provider: string;\n    message: string;\n    operation?: string;\n    retryable?: boolean;\n    cause?: unknown;\n  }) {\n    super(redactSensitive(options.message), { cause: options.cause });\n    this.name = \"SandboxError\";\n    this.code = options.code;\n    this.provider = options.provider;\n    this.operation = options.operation;\n    this.retryable =\n      options.retryable ?? [\"rate_limited\", \"timeout\", \"unavailable\"].includes(options.code);\n    this.cause = options.cause;\n  }\n\n  override toString(): string {\n    return `${this.name} [${this.code}]: ${this.message}`;\n  }\n}\n\nexport function isSandboxError(error: unknown): error is SandboxError {\n  return error instanceof SandboxError;\n}\n\nexport function normalizeError(\n  provider: string,\n  operation: string,\n  error: unknown,\n  fallback: SandboxErrorCode = \"internal\",\n): SandboxError {\n  if (isSandboxError(error)) return error;\n  const message = error instanceof Error ? error.message : \"Unknown provider error\";\n  const lower = `${error instanceof Error ? error.name : \"\"} ${message}`.toLowerCase();\n  const status = errorStatus(error);\n  const code =\n    status === 401 || lower.includes(\"unauthorized\") || lower.includes(\"api key\")\n      ? \"authentication\"\n      : status === 403 || lower.includes(\"forbidden\") || lower.includes(\"permission\")\n        ? \"permission\"\n        : status === 404 || lower.includes(\"not found\") || lower.includes(\"enoent\")\n          ? \"not_found\"\n          : status === 408 || lower.includes(\"timeout\") || lower.includes(\"timed out\")\n            ? \"timeout\"\n            : status === 429 || lower.includes(\"rate limit\") || lower.includes(\"429\")\n              ? \"rate_limited\"\n              : status === 409 || lower.includes(\"already exists\") || lower.includes(\"conflict\")\n                ? \"conflict\"\n                : fallback;\n  return new SandboxError({ code, provider, operation, message, cause: error });\n}\n\nfunction errorStatus(error: unknown): number | undefined {\n  if (typeof error !== \"object\" || error === null) return undefined;\n  if (\"statusCode\" in error && typeof error.statusCode === \"number\") return error.statusCode;\n  if (\"status\" in error && typeof error.status === \"number\") return error.status;\n  if (\n    \"response\" in error &&\n    typeof error.response === \"object\" &&\n    error.response !== null &&\n    \"status\" in error.response &&\n    typeof error.response.status === \"number\"\n  ) {\n    return error.response.status;\n  }\n  return undefined;\n}\n"],"mappings":";AAAA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAID,MAAM,YACJ;AAEF,SAAgB,gBAAgB,OAAuB;AACrD,QAAO,MAAM,QAAQ,WAAW,eAAe;;AAGjD,IAAa,eAAb,cAAkC,MAAM;CACtC,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAkB;CAElB,YAAY,SAOT;AACD,QAAM,gBAAgB,QAAQ,QAAQ,EAAE,EAAE,OAAO,QAAQ,OAAO,CAAC;AACjE,OAAK,OAAO;AACZ,OAAK,OAAO,QAAQ;AACpB,OAAK,WAAW,QAAQ;AACxB,OAAK,YAAY,QAAQ;AACzB,OAAK,YACH,QAAQ,aAAa;GAAC;GAAgB;GAAW;GAAc,CAAC,SAAS,QAAQ,KAAK;AACxF,OAAK,QAAQ,QAAQ;;CAGvB,AAAS,WAAmB;AAC1B,SAAO,GAAG,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK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