@kenkaiiii/gg-ai 5.72.0 → 5.74.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.cjs CHANGED
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  classifyProviderError: () => classifyProviderError,
41
41
  dropInvalidToolCalls: () => dropInvalidToolCalls,
42
42
  environmentSecrets: () => environmentSecrets,
43
+ formatChatError: () => formatChatError,
43
44
  formatError: () => formatError,
44
45
  formatErrorForDisplay: () => formatErrorForDisplay,
45
46
  hasLoneSurrogate: () => hasLoneSurrogate,
@@ -2758,7 +2759,7 @@ function toError2(err, provider = "openai") {
2758
2759
  const cleanMessage = isRawHtmlErrorEcho(messageCandidate) ? providerHtmlErrorMessage(err.status) : bodyMessage ? bodyMessage : isRawJsonErrorEcho(err.message) ? emptyProviderErrorMessage(err.status) : err.message;
2759
2760
  let hint;
2760
2761
  if (modelName === "codex-mini-latest" || cleanMessage.includes("codex-mini-latest")) {
2761
- 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.";
2762
+ hint = "This request could not use codex-mini-latest. Check your account access or choose another available model.";
2762
2763
  }
2763
2764
  const requestId = err.request_id ?? (typeof body?.request_id === "string" ? body.request_id : void 0);
2764
2765
  const code = typeof err.code === "string" ? err.code : void 0;
@@ -3022,9 +3023,9 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
3022
3023
  if (usageLimit) throw usageLimit;
3023
3024
  let hint;
3024
3025
  if (response.status === 400 && message === `The '${options.model}' model is not supported when using Codex with a ChatGPT account.`) {
3025
- 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.";
3026
+ hint = "This model is not available through your ChatGPT account. Choose another available model using the model selector.";
3026
3027
  } else if (response.status === 404 && text.includes("does not exist")) {
3027
- 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.";
3028
+ hint = "This model is not in OpenAI's current catalog for your ChatGPT account. Choose another available model using the model selector.";
3028
3029
  }
3029
3030
  throw new ProviderError("openai", message, {
3030
3031
  statusCode: response.status,
@@ -3497,6 +3498,7 @@ function codexUsageLimitError(errorObj, statusCode, requestId) {
3497
3498
  const isRateOr429 = CODEX_RATE_LIMIT_CODE.test(code) || statusCode === 429;
3498
3499
  if (!isHardUsage && !(isRateOr429 && resetsAt != null)) return null;
3499
3500
  return new ProviderError("openai", "ChatGPT usage limit reached", {
3501
+ cause: errorObj,
3500
3502
  statusCode: statusCode ?? 429,
3501
3503
  ...requestId ? { requestId } : {},
3502
3504
  ...resetsAt ? { resetsAt } : {}
@@ -4421,6 +4423,157 @@ function messagesContainVideo(messages) {
4421
4423
  return false;
4422
4424
  }
4423
4425
 
4426
+ // src/chat-error.ts
4427
+ function causeCode(error) {
4428
+ if (!(error instanceof Error) || !error.cause || typeof error.cause !== "object") return "";
4429
+ const cause = error.cause;
4430
+ if ("code" in cause && typeof cause.code === "string") return cause.code;
4431
+ if ("type" in cause && typeof cause.type === "string") return cause.type;
4432
+ return "";
4433
+ }
4434
+ function formatChatError(error) {
4435
+ const base = formatError(error);
4436
+ const raw = error instanceof Error ? error.message : "";
4437
+ const code = causeCode(error);
4438
+ const text = `${code} ${raw}`.toLowerCase();
4439
+ const provider = /chatgpt/i.test(raw) ? "ChatGPT" : providerLabel(base.provider);
4440
+ const present = (reason, headline, guidance) => ({
4441
+ ...base,
4442
+ ...raw ? { message: raw } : {},
4443
+ reason,
4444
+ headline,
4445
+ guidance
4446
+ });
4447
+ if (error instanceof VideoUnsupportedError) {
4448
+ return present(
4449
+ "capability",
4450
+ "This model can\u2019t read this video",
4451
+ "Choose a model that supports video."
4452
+ );
4453
+ }
4454
+ if (base.source === "capability") {
4455
+ return present(
4456
+ "unknown",
4457
+ "This request isn\u2019t supported",
4458
+ "Open details to check the request requirements."
4459
+ );
4460
+ }
4461
+ if (/requires a newer version of codex/.test(text)) {
4462
+ return present(
4463
+ "update",
4464
+ "GG Coder needs an update",
4465
+ "Update the app, or choose another model."
4466
+ );
4467
+ }
4468
+ if (/insufficient.*(?:balance|credits?)|(?:balance|credits?).*(?:insufficient|exhausted|depleted)|credit balance is too low|payment_required/.test(
4469
+ text
4470
+ )) {
4471
+ return present(
4472
+ "billing",
4473
+ `${provider} credits are unavailable`,
4474
+ "Check your balance and billing, or use another provider."
4475
+ );
4476
+ }
4477
+ 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(
4478
+ text
4479
+ )) {
4480
+ return present(
4481
+ "model_access",
4482
+ "This model isn\u2019t available to this account",
4483
+ "Choose another model available to your account."
4484
+ );
4485
+ }
4486
+ if (/insufficient_quota|exceeded your current quota|billing.?limit|spend.?limit|quota.?exceeded/.test(
4487
+ text
4488
+ )) {
4489
+ return present(
4490
+ "quota",
4491
+ `${provider} quota is unavailable`,
4492
+ "Check your plan or billing, or use another provider."
4493
+ );
4494
+ }
4495
+ if (/^rate_limit_exceeded$/i.test(code)) {
4496
+ return present(
4497
+ "rate_limit",
4498
+ `${provider} is limiting requests`,
4499
+ "Wait a moment before trying again."
4500
+ );
4501
+ }
4502
+ if (/usage limit reached|usage_limit_reached/.test(text)) {
4503
+ return present(
4504
+ "usage_limit",
4505
+ `${provider} usage limit reached`,
4506
+ "Wait for the reset, or use another provider."
4507
+ );
4508
+ }
4509
+ if (base.source === "network") {
4510
+ return present(
4511
+ "network",
4512
+ "Couldn\u2019t reach the provider",
4513
+ "Check your connection before trying again."
4514
+ );
4515
+ }
4516
+ if (base.source === "auth" || base.statusCode === 401) {
4517
+ return present(
4518
+ "auth",
4519
+ `${provider} sign-in needs attention`,
4520
+ "Reconnect your account in provider settings."
4521
+ );
4522
+ }
4523
+ if (base.statusCode === 413 || /context[_ ](?:length|window)|maximum context|request_too_large|prompt is too long/.test(text)) {
4524
+ return present(
4525
+ "context",
4526
+ "This conversation is too large",
4527
+ "Compact the conversation or send a smaller request."
4528
+ );
4529
+ }
4530
+ if (base.statusCode === 429 || /rate_limit|rate limit|too many requests/.test(text)) {
4531
+ return present(
4532
+ "rate_limit",
4533
+ `${provider} is limiting requests`,
4534
+ "Wait a moment before trying again."
4535
+ );
4536
+ }
4537
+ if (base.statusCode === 403) {
4538
+ return present(
4539
+ "model_access",
4540
+ "This account can\u2019t use this request",
4541
+ "Check account access or choose another model."
4542
+ );
4543
+ }
4544
+ if (error instanceof ProviderError) {
4545
+ if (base.statusCode != null && base.statusCode >= 500) {
4546
+ return present(
4547
+ "provider",
4548
+ `${provider} couldn\u2019t complete the request`,
4549
+ "Try again later. Check details if it keeps happening."
4550
+ );
4551
+ }
4552
+ return present(
4553
+ "provider",
4554
+ `${provider} didn\u2019t accept the request`,
4555
+ "Check the details before trying again."
4556
+ );
4557
+ }
4558
+ return present("unknown", "Something went wrong", "Open details to see what was reported.");
4559
+ }
4560
+ function providerLabel(provider) {
4561
+ switch (provider) {
4562
+ case "openai":
4563
+ return "OpenAI";
4564
+ case "anthropic":
4565
+ return "Anthropic";
4566
+ case "gemini":
4567
+ return "Gemini";
4568
+ case "xai":
4569
+ return "xAI";
4570
+ case "local":
4571
+ return "The local server";
4572
+ default:
4573
+ return "The provider";
4574
+ }
4575
+ }
4576
+
4424
4577
  // src/error-classification.ts
4425
4578
  var CONTEXT_OVERFLOW_PATTERNS = [
4426
4579
  /context_length_exceeded/i,
@@ -4811,6 +4964,7 @@ function registerPalsuProvider(config) {
4811
4964
  classifyProviderError,
4812
4965
  dropInvalidToolCalls,
4813
4966
  environmentSecrets,
4967
+ formatChatError,
4814
4968
  formatError,
4815
4969
  formatErrorForDisplay,
4816
4970
  hasLoneSurrogate,