{"version":3,"file":"context-length-exceeded-error.mjs","names":[],"sources":["../../../../../../../ai/src/errors/context-length-exceeded-error.ts"],"sourcesContent":["import type { AIErrorOptions } from \"./ai-error\";\nimport type { ErrorCategory } from \"./error-category.type\";\nimport { ProviderError } from \"./provider-error\";\n\n/**\n * Payload for `ContextLengthExceededError`. All fields are optional —\n * providers inconsistently surface exact token counts and the\n * model's limit. When present, they let callers compute a trim\n * target; when absent, the error still categorizes the failure.\n */\nexport type ContextLengthExceededErrorOptions = AIErrorOptions & {\n  limit?: number;\n  actual?: number;\n  modelName?: string;\n};\n\n/**\n * The request's prompt (messages + tools + schema) exceeded the\n * model's context window. Not retryable without shortening the input.\n *\n * Typically surfaced as OpenAI 400 with `code: \"context_length_exceeded\"`.\n *\n * @example\n * if (result.error instanceof ContextLengthExceededError) {\n *   messages = truncateOldestTurns(messages);\n *   return agent.execute(input, { history: messages });\n * }\n */\nexport class ContextLengthExceededError extends ProviderError {\n  public static readonly defaultCategory: ErrorCategory = \"context-length\";\n\n  public readonly limit?: number;\n  public readonly actual?: number;\n  public readonly modelName?: string;\n\n  public constructor(\n    message: string,\n    options?: ContextLengthExceededErrorOptions,\n  ) {\n    super(message, options, \"CONTEXT_LENGTH_EXCEEDED\");\n    this.name = \"ContextLengthExceededError\";\n    this.limit = options?.limit;\n    this.actual = options?.actual;\n    this.modelName = options?.modelName;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,IAAa,6BAAb,cAAgD,cAAc;;yBACJ;;CAMxD,AAAO,YACL,SACA,SACA;EACA,MAAM,SAAS,SAAS,yBAAyB;EACjD,KAAK,OAAO;EACZ,KAAK,QAAQ,SAAS;EACtB,KAAK,SAAS,SAAS;EACvB,KAAK,YAAY,SAAS;CAC5B;AACF"}