{"version":3,"file":"budget-exceeded-error.mjs","names":[],"sources":["../../../../../../../ai/src/errors/budget-exceeded-error.ts"],"sourcesContent":["import { AIError, type AIErrorOptions } from \"./ai-error\";\nimport type { ErrorCategory } from \"./error-category.type\";\n\n/**\n * Unit of the budget being enforced. `tokens` for context/output\n * caps, `usd` for monetary caps, `requests` for call-count caps.\n */\nexport type BudgetUnit = \"tokens\" | \"usd\" | \"requests\";\n\n/**\n * Payload for `BudgetExceededError`. All three fields are required so\n * consumers can present the breach numerically without having to\n * reparse the message.\n */\nexport type BudgetExceededErrorOptions = AIErrorOptions & {\n  limit: number;\n  actual: number;\n  unit: BudgetUnit;\n};\n\n/**\n * A user- or framework-configured budget was exceeded mid-execution.\n *\n * **Not thrown yet.** The class is defined here so v2's budget\n * middleware can throw it without a breaking release of the error\n * hierarchy. Shape is locked: `{ limit, actual, unit }`.\n *\n * @example\n * if (error instanceof BudgetExceededError && error.unit === \"usd\") {\n *   alertFinance(error.actual, error.limit);\n * }\n */\nexport class BudgetExceededError extends AIError {\n  public static readonly defaultCategory: ErrorCategory = \"budget\";\n\n  public readonly limit: number;\n  public readonly actual: number;\n  public readonly unit: BudgetUnit;\n\n  public constructor(message: string, options: BudgetExceededErrorOptions) {\n    super(\"BUDGET_EXCEEDED\", message, options);\n    this.name = \"BudgetExceededError\";\n    this.limit = options.limit;\n    this.actual = options.actual;\n    this.unit = options.unit;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,IAAa,sBAAb,cAAyC,QAAQ;;yBACS;;CAMxD,AAAO,YAAY,SAAiB,SAAqC;EACvE,MAAM,mBAAmB,SAAS,OAAO;EACzC,KAAK,OAAO;EACZ,KAAK,QAAQ,QAAQ;EACrB,KAAK,SAAS,QAAQ;EACtB,KAAK,OAAO,QAAQ;CACtB;AACF"}