@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.d.cts CHANGED
@@ -506,6 +506,14 @@ declare function formatError(err: unknown): FormattedError;
506
506
  */
507
507
  declare function formatErrorForDisplay(err: unknown): string;
508
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
+
509
517
  /**
510
518
  * Inspect a raw provider error message and tag it with a clearer, actionable
511
519
  * prefix so a worker orchestrator can route on intent instead of regexing JSON.
@@ -787,4 +795,4 @@ interface PalsuProviderConfig {
787
795
  */
788
796
  declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
789
797
 
790
- export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, 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, usesResponsesLite };
798
+ export { type AssistantMessage, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedChatError, type FormattedError, GGAIError, 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
@@ -506,6 +506,14 @@ declare function formatError(err: unknown): FormattedError;
506
506
  */
507
507
  declare function formatErrorForDisplay(err: unknown): string;
508
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
+
509
517
  /**
510
518
  * Inspect a raw provider error message and tag it with a clearer, actionable
511
519
  * prefix so a worker orchestrator can route on intent instead of regexing JSON.
@@ -787,4 +795,4 @@ interface PalsuProviderConfig {
787
795
  */
788
796
  declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
789
797
 
790
- export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, 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, usesResponsesLite };
798
+ export { type AssistantMessage, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedChatError, type FormattedError, GGAIError, 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
@@ -2686,7 +2686,7 @@ function toError2(err, provider = "openai") {
2686
2686
  const cleanMessage = isRawHtmlErrorEcho(messageCandidate) ? providerHtmlErrorMessage(err.status) : bodyMessage ? bodyMessage : isRawJsonErrorEcho(err.message) ? emptyProviderErrorMessage(err.status) : err.message;
2687
2687
  let hint;
2688
2688
  if (modelName === "codex-mini-latest" || cleanMessage.includes("codex-mini-latest")) {
2689
- 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.";
2689
+ hint = "This request could not use codex-mini-latest. Check your account access or choose another available model.";
2690
2690
  }
2691
2691
  const requestId = err.request_id ?? (typeof body?.request_id === "string" ? body.request_id : void 0);
2692
2692
  const code = typeof err.code === "string" ? err.code : void 0;
@@ -2950,9 +2950,9 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
2950
2950
  if (usageLimit) throw usageLimit;
2951
2951
  let hint;
2952
2952
  if (response.status === 400 && message === `The '${options.model}' model is not supported when using Codex with a ChatGPT account.`) {
2953
- 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.";
2953
+ hint = "This model is not available through your ChatGPT account. Choose another available model using the model selector.";
2954
2954
  } else if (response.status === 404 && text.includes("does not exist")) {
2955
- 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.";
2955
+ hint = "This model is not in OpenAI's current catalog for your ChatGPT account. Choose another available model using the model selector.";
2956
2956
  }
2957
2957
  throw new ProviderError("openai", message, {
2958
2958
  statusCode: response.status,
@@ -3425,6 +3425,7 @@ function codexUsageLimitError(errorObj, statusCode, requestId) {
3425
3425
  const isRateOr429 = CODEX_RATE_LIMIT_CODE.test(code) || statusCode === 429;
3426
3426
  if (!isHardUsage && !(isRateOr429 && resetsAt != null)) return null;
3427
3427
  return new ProviderError("openai", "ChatGPT usage limit reached", {
3428
+ cause: errorObj,
3428
3429
  statusCode: statusCode ?? 429,
3429
3430
  ...requestId ? { requestId } : {},
3430
3431
  ...resetsAt ? { resetsAt } : {}
@@ -4349,6 +4350,157 @@ function messagesContainVideo(messages) {
4349
4350
  return false;
4350
4351
  }
4351
4352
 
4353
+ // src/chat-error.ts
4354
+ function causeCode(error) {
4355
+ if (!(error instanceof Error) || !error.cause || typeof error.cause !== "object") return "";
4356
+ const cause = error.cause;
4357
+ if ("code" in cause && typeof cause.code === "string") return cause.code;
4358
+ if ("type" in cause && typeof cause.type === "string") return cause.type;
4359
+ return "";
4360
+ }
4361
+ function formatChatError(error) {
4362
+ const base = formatError(error);
4363
+ const raw = error instanceof Error ? error.message : "";
4364
+ const code = causeCode(error);
4365
+ const text = `${code} ${raw}`.toLowerCase();
4366
+ const provider = /chatgpt/i.test(raw) ? "ChatGPT" : providerLabel(base.provider);
4367
+ const present = (reason, headline, guidance) => ({
4368
+ ...base,
4369
+ ...raw ? { message: raw } : {},
4370
+ reason,
4371
+ headline,
4372
+ guidance
4373
+ });
4374
+ if (error instanceof VideoUnsupportedError) {
4375
+ return present(
4376
+ "capability",
4377
+ "This model can\u2019t read this video",
4378
+ "Choose a model that supports video."
4379
+ );
4380
+ }
4381
+ if (base.source === "capability") {
4382
+ return present(
4383
+ "unknown",
4384
+ "This request isn\u2019t supported",
4385
+ "Open details to check the request requirements."
4386
+ );
4387
+ }
4388
+ if (/requires a newer version of codex/.test(text)) {
4389
+ return present(
4390
+ "update",
4391
+ "GG Coder needs an update",
4392
+ "Update the app, or choose another model."
4393
+ );
4394
+ }
4395
+ if (/insufficient.*(?:balance|credits?)|(?:balance|credits?).*(?:insufficient|exhausted|depleted)|credit balance is too low|payment_required/.test(
4396
+ text
4397
+ )) {
4398
+ return present(
4399
+ "billing",
4400
+ `${provider} credits are unavailable`,
4401
+ "Check your balance and billing, or use another provider."
4402
+ );
4403
+ }
4404
+ 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(
4405
+ text
4406
+ )) {
4407
+ return present(
4408
+ "model_access",
4409
+ "This model isn\u2019t available to this account",
4410
+ "Choose another model available to your account."
4411
+ );
4412
+ }
4413
+ if (/insufficient_quota|exceeded your current quota|billing.?limit|spend.?limit|quota.?exceeded/.test(
4414
+ text
4415
+ )) {
4416
+ return present(
4417
+ "quota",
4418
+ `${provider} quota is unavailable`,
4419
+ "Check your plan or billing, or use another provider."
4420
+ );
4421
+ }
4422
+ if (/^rate_limit_exceeded$/i.test(code)) {
4423
+ return present(
4424
+ "rate_limit",
4425
+ `${provider} is limiting requests`,
4426
+ "Wait a moment before trying again."
4427
+ );
4428
+ }
4429
+ if (/usage limit reached|usage_limit_reached/.test(text)) {
4430
+ return present(
4431
+ "usage_limit",
4432
+ `${provider} usage limit reached`,
4433
+ "Wait for the reset, or use another provider."
4434
+ );
4435
+ }
4436
+ if (base.source === "network") {
4437
+ return present(
4438
+ "network",
4439
+ "Couldn\u2019t reach the provider",
4440
+ "Check your connection before trying again."
4441
+ );
4442
+ }
4443
+ if (base.source === "auth" || base.statusCode === 401) {
4444
+ return present(
4445
+ "auth",
4446
+ `${provider} sign-in needs attention`,
4447
+ "Reconnect your account in provider settings."
4448
+ );
4449
+ }
4450
+ if (base.statusCode === 413 || /context[_ ](?:length|window)|maximum context|request_too_large|prompt is too long/.test(text)) {
4451
+ return present(
4452
+ "context",
4453
+ "This conversation is too large",
4454
+ "Compact the conversation or send a smaller request."
4455
+ );
4456
+ }
4457
+ if (base.statusCode === 429 || /rate_limit|rate limit|too many requests/.test(text)) {
4458
+ return present(
4459
+ "rate_limit",
4460
+ `${provider} is limiting requests`,
4461
+ "Wait a moment before trying again."
4462
+ );
4463
+ }
4464
+ if (base.statusCode === 403) {
4465
+ return present(
4466
+ "model_access",
4467
+ "This account can\u2019t use this request",
4468
+ "Check account access or choose another model."
4469
+ );
4470
+ }
4471
+ if (error instanceof ProviderError) {
4472
+ if (base.statusCode != null && base.statusCode >= 500) {
4473
+ return present(
4474
+ "provider",
4475
+ `${provider} couldn\u2019t complete the request`,
4476
+ "Try again later. Check details if it keeps happening."
4477
+ );
4478
+ }
4479
+ return present(
4480
+ "provider",
4481
+ `${provider} didn\u2019t accept the request`,
4482
+ "Check the details before trying again."
4483
+ );
4484
+ }
4485
+ return present("unknown", "Something went wrong", "Open details to see what was reported.");
4486
+ }
4487
+ function providerLabel(provider) {
4488
+ switch (provider) {
4489
+ case "openai":
4490
+ return "OpenAI";
4491
+ case "anthropic":
4492
+ return "Anthropic";
4493
+ case "gemini":
4494
+ return "Gemini";
4495
+ case "xai":
4496
+ return "xAI";
4497
+ case "local":
4498
+ return "The local server";
4499
+ default:
4500
+ return "The provider";
4501
+ }
4502
+ }
4503
+
4352
4504
  // src/error-classification.ts
4353
4505
  var CONTEXT_OVERFLOW_PATTERNS = [
4354
4506
  /context_length_exceeded/i,
@@ -4738,6 +4890,7 @@ export {
4738
4890
  classifyProviderError,
4739
4891
  dropInvalidToolCalls,
4740
4892
  environmentSecrets,
4893
+ formatChatError,
4741
4894
  formatError,
4742
4895
  formatErrorForDisplay,
4743
4896
  hasLoneSurrogate,