@prestyj/ai 5.29.0 → 5.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -223,6 +223,15 @@ interface StreamOptions {
223
223
  promptCacheKey?: string;
224
224
  /** OpenAI service tier for latency-sensitive requests. Only sent to first-party OpenAI API calls. */
225
225
  serviceTier?: "auto" | "default" | "flex" | "priority";
226
+ /** Codex endpoint only: send the Responses-Lite request shape (lite header,
227
+ * `parallel_tool_calls: false`, all-turns reasoning context). Unset follows
228
+ * the model family (on for gpt-5.6/gpt-6 models). Lite allows only one tool
229
+ * call per response, so turning it off lets the model batch calls. */
230
+ responsesLite?: boolean;
231
+ /** OpenAI only (Codex and API-key routes): send tools with strict
232
+ * (grammar-constrained) schemas. Default true. Strict calls carry every
233
+ * optional field as null, which costs output tokens and latency per call. */
234
+ strictTools?: boolean;
226
235
  /** OpenAI ChatGPT account ID (from OAuth JWT) for codex endpoint */
227
236
  accountId?: string;
228
237
  /** Stable conversation identity for Codex transport headers. This is distinct from
@@ -497,6 +506,14 @@ declare function formatError(err: unknown): FormattedError;
497
506
  */
498
507
  declare function formatErrorForDisplay(err: unknown): string;
499
508
 
509
+ /** Display meaning is separate from retry policy: a hard stop is not always a plan limit. */
510
+ type ChatErrorReason = "usage_limit" | "billing" | "quota" | "rate_limit" | "model_access" | "auth" | "network" | "capability" | "context" | "update" | "provider" | "unknown";
511
+ interface FormattedChatError extends FormattedError {
512
+ reason: ChatErrorReason;
513
+ }
514
+ /** Compact, factual desktop copy. Raw provider detail never becomes an executable action. */
515
+ declare function formatChatError(error: unknown): FormattedChatError;
516
+
500
517
  /**
501
518
  * Inspect a raw provider error message and tag it with a clearer, actionable
502
519
  * prefix so a worker orchestrator can route on intent instead of regexing JSON.
@@ -685,6 +702,8 @@ declare function toOpenAIMessages(messages: Message[], options?: {
685
702
  reasoningField?: string;
686
703
  }): OpenAI.ChatCompletionMessageParam[];
687
704
 
705
+ declare function usesResponsesLite(model: string): boolean;
706
+
688
707
  /**
689
708
  * Fire a minimal `max_tokens: 1` request that populates the Anthropic prompt
690
709
  * cache with the system prompt + tools prefix, so the first real user turn is
@@ -776,4 +795,4 @@ interface PalsuProviderConfig {
776
795
  */
777
796
  declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
778
797
 
779
- export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreparedContext, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, TOOL_CALL_NAME_RULES, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolCallNameRule, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, clampProviderContextImages, classifyProviderError, dropInvalidToolCalls, environmentSecrets, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor };
798
+ export { type AssistantMessage, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedChatError, type FormattedError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreparedContext, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, TOOL_CALL_NAME_RULES, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolCallNameRule, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, clampProviderContextImages, classifyProviderError, dropInvalidToolCalls, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
package/dist/index.d.ts CHANGED
@@ -223,6 +223,15 @@ interface StreamOptions {
223
223
  promptCacheKey?: string;
224
224
  /** OpenAI service tier for latency-sensitive requests. Only sent to first-party OpenAI API calls. */
225
225
  serviceTier?: "auto" | "default" | "flex" | "priority";
226
+ /** Codex endpoint only: send the Responses-Lite request shape (lite header,
227
+ * `parallel_tool_calls: false`, all-turns reasoning context). Unset follows
228
+ * the model family (on for gpt-5.6/gpt-6 models). Lite allows only one tool
229
+ * call per response, so turning it off lets the model batch calls. */
230
+ responsesLite?: boolean;
231
+ /** OpenAI only (Codex and API-key routes): send tools with strict
232
+ * (grammar-constrained) schemas. Default true. Strict calls carry every
233
+ * optional field as null, which costs output tokens and latency per call. */
234
+ strictTools?: boolean;
226
235
  /** OpenAI ChatGPT account ID (from OAuth JWT) for codex endpoint */
227
236
  accountId?: string;
228
237
  /** Stable conversation identity for Codex transport headers. This is distinct from
@@ -497,6 +506,14 @@ declare function formatError(err: unknown): FormattedError;
497
506
  */
498
507
  declare function formatErrorForDisplay(err: unknown): string;
499
508
 
509
+ /** Display meaning is separate from retry policy: a hard stop is not always a plan limit. */
510
+ type ChatErrorReason = "usage_limit" | "billing" | "quota" | "rate_limit" | "model_access" | "auth" | "network" | "capability" | "context" | "update" | "provider" | "unknown";
511
+ interface FormattedChatError extends FormattedError {
512
+ reason: ChatErrorReason;
513
+ }
514
+ /** Compact, factual desktop copy. Raw provider detail never becomes an executable action. */
515
+ declare function formatChatError(error: unknown): FormattedChatError;
516
+
500
517
  /**
501
518
  * Inspect a raw provider error message and tag it with a clearer, actionable
502
519
  * prefix so a worker orchestrator can route on intent instead of regexing JSON.
@@ -685,6 +702,8 @@ declare function toOpenAIMessages(messages: Message[], options?: {
685
702
  reasoningField?: string;
686
703
  }): OpenAI.ChatCompletionMessageParam[];
687
704
 
705
+ declare function usesResponsesLite(model: string): boolean;
706
+
688
707
  /**
689
708
  * Fire a minimal `max_tokens: 1` request that populates the Anthropic prompt
690
709
  * cache with the system prompt + tools prefix, so the first real user turn is
@@ -776,4 +795,4 @@ interface PalsuProviderConfig {
776
795
  */
777
796
  declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
778
797
 
779
- export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreparedContext, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, TOOL_CALL_NAME_RULES, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolCallNameRule, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, clampProviderContextImages, classifyProviderError, dropInvalidToolCalls, environmentSecrets, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor };
798
+ export { type AssistantMessage, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedChatError, type FormattedError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreparedContext, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, TOOL_CALL_NAME_RULES, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolCallNameRule, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, clampProviderContextImages, classifyProviderError, dropInvalidToolCalls, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
package/dist/index.js CHANGED
@@ -1426,6 +1426,10 @@ function toLocalReasoningEffort(level) {
1426
1426
  function toGlmReasoningEffort(level) {
1427
1427
  return level === "ultra" ? "max" : level;
1428
1428
  }
1429
+ function toCodexReasoningEffort(level, model) {
1430
+ if (level !== "ultra") return level;
1431
+ return model === "gpt-6-astra" || model === "gpt-6.1-sol" ? "xhigh" : "max";
1432
+ }
1429
1433
  function toOpenAIReasoningEffort(level, model) {
1430
1434
  const effort = level === "max" || level === "ultra" ? "xhigh" : level;
1431
1435
  if (model.startsWith("fugu") && (effort === "low" || effort === "medium")) {
@@ -2357,7 +2361,7 @@ async function* runStream2(options) {
2357
2361
  ...options.thinking && !usesThinkingParam && !isKimiK3 && !isKimiK27 && !isLocal ? { reasoning_effort: toOpenAIReasoningEffort(options.thinking, options.model) } : {},
2358
2362
  ...options.tools?.length ? {
2359
2363
  tools: toOpenAITools(options.tools, {
2360
- strict: supportsStrictToolSampling(options.provider)
2364
+ strict: supportsStrictToolSampling(options.provider) && (options.strictTools ?? true)
2361
2365
  })
2362
2366
  } : {},
2363
2367
  ...options.toolChoice && options.tools?.length ? { tool_choice: toOpenAIToolChoice(options.toolChoice) } : {},
@@ -2691,7 +2695,7 @@ function toError2(err, provider = "openai") {
2691
2695
  const cleanMessage = isRawHtmlErrorEcho(messageCandidate) ? providerHtmlErrorMessage(err.status) : bodyMessage ? bodyMessage : isRawJsonErrorEcho(err.message) ? emptyProviderErrorMessage(err.status) : err.message;
2692
2696
  let hint;
2693
2697
  if (modelName === "codex-mini-latest" || cleanMessage.includes("codex-mini-latest")) {
2694
- hint = "codex-mini-latest requires an OpenAI Pro or Max subscription. Your account currently has access to GPT-5.4 and GPT-5.4 Mini.";
2698
+ hint = "This request could not use codex-mini-latest. Check your account access or choose another available model.";
2695
2699
  }
2696
2700
  const requestId = err.request_id ?? (typeof body?.request_id === "string" ? body.request_id : void 0);
2697
2701
  const code = typeof err.code === "string" ? err.code : void 0;
@@ -2875,6 +2879,7 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
2875
2879
  const downgraded = downgradeUnsupportedVideos(downgradedImages, options.supportsVideo);
2876
2880
  const { system, input } = toCodexInput(downgraded, { supportsImages: options.supportsImages });
2877
2881
  const responsesLite = usesResponsesLite(options.model);
2882
+ const liteShape = options.responsesLite ?? responsesLite;
2878
2883
  const body = {
2879
2884
  model: options.model,
2880
2885
  store: false,
@@ -2882,11 +2887,11 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
2882
2887
  instructions: system,
2883
2888
  input,
2884
2889
  tool_choice: toCodexToolChoice(options.toolChoice, options.tools),
2885
- parallel_tool_calls: !responsesLite,
2890
+ parallel_tool_calls: !liteShape,
2886
2891
  include: ["reasoning.encrypted_content"]
2887
2892
  };
2888
2893
  if (options.tools?.length) {
2889
- body.tools = toCodexTools(options.tools);
2894
+ body.tools = toCodexTools(options.tools, options.strictTools ?? true);
2890
2895
  }
2891
2896
  body.prompt_cache_key = normalizePromptCacheKey(options.promptCacheKey ?? "ezcoder");
2892
2897
  if (options.temperature != null && !options.thinking) {
@@ -2896,9 +2901,9 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
2896
2901
  // GPT-5.6/6 require at least low; older models still support thinking off.
2897
2902
  // Apply the floor here for every caller, including one-off prompt rewrites.
2898
2903
  // `ultra` is a client orchestration preset, not a Codex API effort.
2899
- effort: options.thinking === "ultra" ? "max" : options.thinking ?? (responsesLite ? "low" : "none"),
2904
+ effort: options.thinking ? toCodexReasoningEffort(options.thinking, options.model) : responsesLite ? "low" : "none",
2900
2905
  summary: "auto",
2901
- ...responsesLite ? { context: "all_turns" } : {}
2906
+ ...liteShape ? { context: "all_turns" } : {}
2902
2907
  };
2903
2908
  if (responsesLite) {
2904
2909
  body.text = { verbosity: "low" };
@@ -2910,10 +2915,8 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
2910
2915
  "OpenAI-Beta": "responses=experimental",
2911
2916
  originator: responsesLite ? "codex_cli_rs" : "ezcoder",
2912
2917
  "User-Agent": responsesLite ? `codex_cli_rs/${CODEX_CLIENT_VERSION}` : `ezcoder (${os.platform()} ${os.release()}; ${os.arch()})`,
2913
- ...responsesLite ? {
2914
- version: CODEX_CLIENT_VERSION,
2915
- "X-OpenAI-Internal-Codex-Responses-Lite": "true"
2916
- } : {}
2918
+ ...responsesLite ? { version: CODEX_CLIENT_VERSION } : {},
2919
+ ...liteShape ? { "X-OpenAI-Internal-Codex-Responses-Lite": "true" } : {}
2917
2920
  };
2918
2921
  if (options.accountId) {
2919
2922
  headers["chatgpt-account-id"] = options.accountId;
@@ -2959,9 +2962,9 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
2959
2962
  if (usageLimit) throw usageLimit;
2960
2963
  let hint;
2961
2964
  if (response.status === 400 && message === `The '${options.model}' model is not supported when using Codex with a ChatGPT account.`) {
2962
- hint = "This model is not available through your ChatGPT account. Switch to a model listed for OpenAI via the model selector, or check your ChatGPT usage limits.";
2965
+ hint = "This model is not available through your ChatGPT account. Choose another available model using the model selector.";
2963
2966
  } else if (response.status === 404 && text.includes("does not exist")) {
2964
- hint = "This model is not in OpenAI's current catalog for your ChatGPT account. Switch to GPT-6 Astra, GPT-6.1 Sol, or GPT-6 Luna via the model selector.";
2967
+ hint = "This model is not in OpenAI's current catalog for your ChatGPT account. Choose another available model using the model selector.";
2965
2968
  }
2966
2969
  throw new ProviderError("openai", message, {
2967
2970
  statusCode: response.status,
@@ -3377,15 +3380,17 @@ function toCodexInput(messages, options) {
3377
3380
  }
3378
3381
  return { system, input };
3379
3382
  }
3380
- function toCodexTools(tools) {
3383
+ function toCodexTools(tools, strictTools) {
3381
3384
  return tools.map((tool) => {
3382
3385
  let parameters = resolveToolSchema(tool);
3383
3386
  let strict = null;
3384
- try {
3385
- parameters = makeStrictToolSchema(parameters);
3386
- strict = true;
3387
- } catch (error) {
3388
- if (!(error instanceof UnsupportedStrictSchemaError)) throw error;
3387
+ if (strictTools) {
3388
+ try {
3389
+ parameters = makeStrictToolSchema(parameters);
3390
+ strict = true;
3391
+ } catch (error) {
3392
+ if (!(error instanceof UnsupportedStrictSchemaError)) throw error;
3393
+ }
3389
3394
  }
3390
3395
  return {
3391
3396
  type: "function",
@@ -3432,6 +3437,7 @@ function codexUsageLimitError(errorObj, statusCode, requestId) {
3432
3437
  const isRateOr429 = CODEX_RATE_LIMIT_CODE.test(code) || statusCode === 429;
3433
3438
  if (!isHardUsage && !(isRateOr429 && resetsAt != null)) return null;
3434
3439
  return new ProviderError("openai", "ChatGPT usage limit reached", {
3440
+ cause: errorObj,
3435
3441
  statusCode: statusCode ?? 429,
3436
3442
  ...requestId ? { requestId } : {},
3437
3443
  ...resetsAt ? { resetsAt } : {}
@@ -3622,6 +3628,17 @@ function stripUnsupportedSchemaFields(value) {
3622
3628
  }
3623
3629
  delete value.$schema;
3624
3630
  delete value.additionalProperties;
3631
+ for (const [key, target, step] of [
3632
+ ["exclusiveMinimum", "minimum", 1],
3633
+ ["exclusiveMaximum", "maximum", -1]
3634
+ ]) {
3635
+ const bound = value[key];
3636
+ if (bound === void 0) continue;
3637
+ delete value[key];
3638
+ if (typeof bound === "number" && value[target] === void 0) {
3639
+ value[target] = value.type === "integer" ? bound + step : bound;
3640
+ }
3641
+ }
3625
3642
  for (const item of Object.values(value)) {
3626
3643
  if (isJsonObject(item) || Array.isArray(item)) {
3627
3644
  stripUnsupportedSchemaFields(item);
@@ -4351,6 +4368,157 @@ function messagesContainVideo(messages) {
4351
4368
  return false;
4352
4369
  }
4353
4370
 
4371
+ // src/chat-error.ts
4372
+ function causeCode(error) {
4373
+ if (!(error instanceof Error) || !error.cause || typeof error.cause !== "object") return "";
4374
+ const cause = error.cause;
4375
+ if ("code" in cause && typeof cause.code === "string") return cause.code;
4376
+ if ("type" in cause && typeof cause.type === "string") return cause.type;
4377
+ return "";
4378
+ }
4379
+ function formatChatError(error) {
4380
+ const base = formatError(error);
4381
+ const raw = error instanceof Error ? error.message : "";
4382
+ const code = causeCode(error);
4383
+ const text = `${code} ${raw}`.toLowerCase();
4384
+ const provider = /chatgpt/i.test(raw) ? "ChatGPT" : providerLabel(base.provider);
4385
+ const present = (reason, headline, guidance) => ({
4386
+ ...base,
4387
+ ...raw ? { message: raw } : {},
4388
+ reason,
4389
+ headline,
4390
+ guidance
4391
+ });
4392
+ if (error instanceof VideoUnsupportedError) {
4393
+ return present(
4394
+ "capability",
4395
+ "This model can\u2019t read this video",
4396
+ "Choose a model that supports video."
4397
+ );
4398
+ }
4399
+ if (base.source === "capability") {
4400
+ return present(
4401
+ "unknown",
4402
+ "This request isn\u2019t supported",
4403
+ "Open details to check the request requirements."
4404
+ );
4405
+ }
4406
+ if (/requires a newer version of codex/.test(text)) {
4407
+ return present(
4408
+ "update",
4409
+ "EZ Coder needs an update",
4410
+ "Update the app, or choose another model."
4411
+ );
4412
+ }
4413
+ if (/insufficient.*(?:balance|credits?)|(?:balance|credits?).*(?:insufficient|exhausted|depleted)|credit balance is too low|payment_required/.test(
4414
+ text
4415
+ )) {
4416
+ return present(
4417
+ "billing",
4418
+ `${provider} credits are unavailable`,
4419
+ "Check your balance and billing, or use another provider."
4420
+ );
4421
+ }
4422
+ if (/usage_not_included|does not yet include access|not supported when using codex with a chatgpt account|(?:model[^\n]*(?:not found|not available|does not exist))|model_not_found/.test(
4423
+ text
4424
+ )) {
4425
+ return present(
4426
+ "model_access",
4427
+ "This model isn\u2019t available to this account",
4428
+ "Choose another model available to your account."
4429
+ );
4430
+ }
4431
+ if (/insufficient_quota|exceeded your current quota|billing.?limit|spend.?limit|quota.?exceeded/.test(
4432
+ text
4433
+ )) {
4434
+ return present(
4435
+ "quota",
4436
+ `${provider} quota is unavailable`,
4437
+ "Check your plan or billing, or use another provider."
4438
+ );
4439
+ }
4440
+ if (/^rate_limit_exceeded$/i.test(code)) {
4441
+ return present(
4442
+ "rate_limit",
4443
+ `${provider} is limiting requests`,
4444
+ "Wait a moment before trying again."
4445
+ );
4446
+ }
4447
+ if (/usage limit reached|usage_limit_reached/.test(text)) {
4448
+ return present(
4449
+ "usage_limit",
4450
+ `${provider} usage limit reached`,
4451
+ "Wait for the reset, or use another provider."
4452
+ );
4453
+ }
4454
+ if (base.source === "network") {
4455
+ return present(
4456
+ "network",
4457
+ "Couldn\u2019t reach the provider",
4458
+ "Check your connection before trying again."
4459
+ );
4460
+ }
4461
+ if (base.source === "auth" || base.statusCode === 401) {
4462
+ return present(
4463
+ "auth",
4464
+ `${provider} sign-in needs attention`,
4465
+ "Reconnect your account in provider settings."
4466
+ );
4467
+ }
4468
+ if (base.statusCode === 413 || /context[_ ](?:length|window)|maximum context|request_too_large|prompt is too long/.test(text)) {
4469
+ return present(
4470
+ "context",
4471
+ "This conversation is too large",
4472
+ "Compact the conversation or send a smaller request."
4473
+ );
4474
+ }
4475
+ if (base.statusCode === 429 || /rate_limit|rate limit|too many requests/.test(text)) {
4476
+ return present(
4477
+ "rate_limit",
4478
+ `${provider} is limiting requests`,
4479
+ "Wait a moment before trying again."
4480
+ );
4481
+ }
4482
+ if (base.statusCode === 403) {
4483
+ return present(
4484
+ "model_access",
4485
+ "This account can\u2019t use this request",
4486
+ "Check account access or choose another model."
4487
+ );
4488
+ }
4489
+ if (error instanceof ProviderError) {
4490
+ if (base.statusCode != null && base.statusCode >= 500) {
4491
+ return present(
4492
+ "provider",
4493
+ `${provider} couldn\u2019t complete the request`,
4494
+ "Try again later. Check details if it keeps happening."
4495
+ );
4496
+ }
4497
+ return present(
4498
+ "provider",
4499
+ `${provider} didn\u2019t accept the request`,
4500
+ "Check the details before trying again."
4501
+ );
4502
+ }
4503
+ return present("unknown", "Something went wrong", "Open details to see what was reported.");
4504
+ }
4505
+ function providerLabel(provider) {
4506
+ switch (provider) {
4507
+ case "openai":
4508
+ return "OpenAI";
4509
+ case "anthropic":
4510
+ return "Anthropic";
4511
+ case "gemini":
4512
+ return "Gemini";
4513
+ case "xai":
4514
+ return "xAI";
4515
+ case "local":
4516
+ return "The local server";
4517
+ default:
4518
+ return "The provider";
4519
+ }
4520
+ }
4521
+
4354
4522
  // src/error-classification.ts
4355
4523
  var CONTEXT_OVERFLOW_PATTERNS = [
4356
4524
  /context_length_exceeded/i,
@@ -4740,6 +4908,7 @@ export {
4740
4908
  classifyProviderError,
4741
4909
  dropInvalidToolCalls,
4742
4910
  environmentSecrets,
4911
+ formatChatError,
4743
4912
  formatError,
4744
4913
  formatErrorForDisplay,
4745
4914
  hasLoneSurrogate,
@@ -4765,6 +4934,7 @@ export {
4765
4934
  toAnthropicMessages,
4766
4935
  toOpenAIMessages,
4767
4936
  toWellFormedText,
4768
- toolCallNameRuleFor
4937
+ toolCallNameRuleFor,
4938
+ usesResponsesLite
4769
4939
  };
4770
4940
  //# sourceMappingURL=index.js.map