@kenkaiiii/gg-ai 5.73.0 → 5.74.1
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 +162 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +161 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
@@ -1422,6 +1422,10 @@ function toLocalReasoningEffort(level) {
|
|
|
1422
1422
|
function toGlmReasoningEffort(level) {
|
|
1423
1423
|
return level === "ultra" ? "max" : level;
|
|
1424
1424
|
}
|
|
1425
|
+
function toCodexReasoningEffort(level, model) {
|
|
1426
|
+
if (level !== "ultra") return level;
|
|
1427
|
+
return model === "gpt-6-astra" || model === "gpt-6.1-sol" ? "xhigh" : "max";
|
|
1428
|
+
}
|
|
1425
1429
|
function toOpenAIReasoningEffort(level, model) {
|
|
1426
1430
|
const effort = level === "max" || level === "ultra" ? "xhigh" : level;
|
|
1427
1431
|
if (model.startsWith("fugu") && (effort === "low" || effort === "medium")) {
|
|
@@ -2686,7 +2690,7 @@ function toError2(err, provider = "openai") {
|
|
|
2686
2690
|
const cleanMessage = isRawHtmlErrorEcho(messageCandidate) ? providerHtmlErrorMessage(err.status) : bodyMessage ? bodyMessage : isRawJsonErrorEcho(err.message) ? emptyProviderErrorMessage(err.status) : err.message;
|
|
2687
2691
|
let hint;
|
|
2688
2692
|
if (modelName === "codex-mini-latest" || cleanMessage.includes("codex-mini-latest")) {
|
|
2689
|
-
hint = "codex-mini-latest
|
|
2693
|
+
hint = "This request could not use codex-mini-latest. Check your account access or choose another available model.";
|
|
2690
2694
|
}
|
|
2691
2695
|
const requestId = err.request_id ?? (typeof body?.request_id === "string" ? body.request_id : void 0);
|
|
2692
2696
|
const code = typeof err.code === "string" ? err.code : void 0;
|
|
@@ -2889,7 +2893,7 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
|
|
|
2889
2893
|
// GPT-5.6/6 require at least low; older models still support thinking off.
|
|
2890
2894
|
// Apply the floor here for every caller, including one-off prompt rewrites.
|
|
2891
2895
|
// `ultra` is a client orchestration preset, not a Codex API effort.
|
|
2892
|
-
effort: options.thinking
|
|
2896
|
+
effort: options.thinking ? toCodexReasoningEffort(options.thinking, options.model) : responsesLite ? "low" : "none",
|
|
2893
2897
|
summary: "auto",
|
|
2894
2898
|
...liteShape ? { context: "all_turns" } : {}
|
|
2895
2899
|
};
|
|
@@ -2950,9 +2954,9 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
|
|
|
2950
2954
|
if (usageLimit) throw usageLimit;
|
|
2951
2955
|
let hint;
|
|
2952
2956
|
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.
|
|
2957
|
+
hint = "This model is not available through your ChatGPT account. Choose another available model using the model selector.";
|
|
2954
2958
|
} 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.
|
|
2959
|
+
hint = "This model is not in OpenAI's current catalog for your ChatGPT account. Choose another available model using the model selector.";
|
|
2956
2960
|
}
|
|
2957
2961
|
throw new ProviderError("openai", message, {
|
|
2958
2962
|
statusCode: response.status,
|
|
@@ -3425,6 +3429,7 @@ function codexUsageLimitError(errorObj, statusCode, requestId) {
|
|
|
3425
3429
|
const isRateOr429 = CODEX_RATE_LIMIT_CODE.test(code) || statusCode === 429;
|
|
3426
3430
|
if (!isHardUsage && !(isRateOr429 && resetsAt != null)) return null;
|
|
3427
3431
|
return new ProviderError("openai", "ChatGPT usage limit reached", {
|
|
3432
|
+
cause: errorObj,
|
|
3428
3433
|
statusCode: statusCode ?? 429,
|
|
3429
3434
|
...requestId ? { requestId } : {},
|
|
3430
3435
|
...resetsAt ? { resetsAt } : {}
|
|
@@ -4349,6 +4354,157 @@ function messagesContainVideo(messages) {
|
|
|
4349
4354
|
return false;
|
|
4350
4355
|
}
|
|
4351
4356
|
|
|
4357
|
+
// src/chat-error.ts
|
|
4358
|
+
function causeCode(error) {
|
|
4359
|
+
if (!(error instanceof Error) || !error.cause || typeof error.cause !== "object") return "";
|
|
4360
|
+
const cause = error.cause;
|
|
4361
|
+
if ("code" in cause && typeof cause.code === "string") return cause.code;
|
|
4362
|
+
if ("type" in cause && typeof cause.type === "string") return cause.type;
|
|
4363
|
+
return "";
|
|
4364
|
+
}
|
|
4365
|
+
function formatChatError(error) {
|
|
4366
|
+
const base = formatError(error);
|
|
4367
|
+
const raw = error instanceof Error ? error.message : "";
|
|
4368
|
+
const code = causeCode(error);
|
|
4369
|
+
const text = `${code} ${raw}`.toLowerCase();
|
|
4370
|
+
const provider = /chatgpt/i.test(raw) ? "ChatGPT" : providerLabel(base.provider);
|
|
4371
|
+
const present = (reason, headline, guidance) => ({
|
|
4372
|
+
...base,
|
|
4373
|
+
...raw ? { message: raw } : {},
|
|
4374
|
+
reason,
|
|
4375
|
+
headline,
|
|
4376
|
+
guidance
|
|
4377
|
+
});
|
|
4378
|
+
if (error instanceof VideoUnsupportedError) {
|
|
4379
|
+
return present(
|
|
4380
|
+
"capability",
|
|
4381
|
+
"This model can\u2019t read this video",
|
|
4382
|
+
"Choose a model that supports video."
|
|
4383
|
+
);
|
|
4384
|
+
}
|
|
4385
|
+
if (base.source === "capability") {
|
|
4386
|
+
return present(
|
|
4387
|
+
"unknown",
|
|
4388
|
+
"This request isn\u2019t supported",
|
|
4389
|
+
"Open details to check the request requirements."
|
|
4390
|
+
);
|
|
4391
|
+
}
|
|
4392
|
+
if (/requires a newer version of codex/.test(text)) {
|
|
4393
|
+
return present(
|
|
4394
|
+
"update",
|
|
4395
|
+
"GG Coder needs an update",
|
|
4396
|
+
"Update the app, or choose another model."
|
|
4397
|
+
);
|
|
4398
|
+
}
|
|
4399
|
+
if (/insufficient.*(?:balance|credits?)|(?:balance|credits?).*(?:insufficient|exhausted|depleted)|credit balance is too low|payment_required/.test(
|
|
4400
|
+
text
|
|
4401
|
+
)) {
|
|
4402
|
+
return present(
|
|
4403
|
+
"billing",
|
|
4404
|
+
`${provider} credits are unavailable`,
|
|
4405
|
+
"Check your balance and billing, or use another provider."
|
|
4406
|
+
);
|
|
4407
|
+
}
|
|
4408
|
+
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(
|
|
4409
|
+
text
|
|
4410
|
+
)) {
|
|
4411
|
+
return present(
|
|
4412
|
+
"model_access",
|
|
4413
|
+
"This model isn\u2019t available to this account",
|
|
4414
|
+
"Choose another model available to your account."
|
|
4415
|
+
);
|
|
4416
|
+
}
|
|
4417
|
+
if (/insufficient_quota|exceeded your current quota|billing.?limit|spend.?limit|quota.?exceeded/.test(
|
|
4418
|
+
text
|
|
4419
|
+
)) {
|
|
4420
|
+
return present(
|
|
4421
|
+
"quota",
|
|
4422
|
+
`${provider} quota is unavailable`,
|
|
4423
|
+
"Check your plan or billing, or use another provider."
|
|
4424
|
+
);
|
|
4425
|
+
}
|
|
4426
|
+
if (/^rate_limit_exceeded$/i.test(code)) {
|
|
4427
|
+
return present(
|
|
4428
|
+
"rate_limit",
|
|
4429
|
+
`${provider} is limiting requests`,
|
|
4430
|
+
"Wait a moment before trying again."
|
|
4431
|
+
);
|
|
4432
|
+
}
|
|
4433
|
+
if (/usage limit reached|usage_limit_reached/.test(text)) {
|
|
4434
|
+
return present(
|
|
4435
|
+
"usage_limit",
|
|
4436
|
+
`${provider} usage limit reached`,
|
|
4437
|
+
"Wait for the reset, or use another provider."
|
|
4438
|
+
);
|
|
4439
|
+
}
|
|
4440
|
+
if (base.source === "network") {
|
|
4441
|
+
return present(
|
|
4442
|
+
"network",
|
|
4443
|
+
"Couldn\u2019t reach the provider",
|
|
4444
|
+
"Check your connection before trying again."
|
|
4445
|
+
);
|
|
4446
|
+
}
|
|
4447
|
+
if (base.source === "auth" || base.statusCode === 401) {
|
|
4448
|
+
return present(
|
|
4449
|
+
"auth",
|
|
4450
|
+
`${provider} sign-in needs attention`,
|
|
4451
|
+
"Reconnect your account in provider settings."
|
|
4452
|
+
);
|
|
4453
|
+
}
|
|
4454
|
+
if (base.statusCode === 413 || /context[_ ](?:length|window)|maximum context|request_too_large|prompt is too long/.test(text)) {
|
|
4455
|
+
return present(
|
|
4456
|
+
"context",
|
|
4457
|
+
"This conversation is too large",
|
|
4458
|
+
"Compact the conversation or send a smaller request."
|
|
4459
|
+
);
|
|
4460
|
+
}
|
|
4461
|
+
if (base.statusCode === 429 || /rate_limit|rate limit|too many requests/.test(text)) {
|
|
4462
|
+
return present(
|
|
4463
|
+
"rate_limit",
|
|
4464
|
+
`${provider} is limiting requests`,
|
|
4465
|
+
"Wait a moment before trying again."
|
|
4466
|
+
);
|
|
4467
|
+
}
|
|
4468
|
+
if (base.statusCode === 403) {
|
|
4469
|
+
return present(
|
|
4470
|
+
"model_access",
|
|
4471
|
+
"This account can\u2019t use this request",
|
|
4472
|
+
"Check account access or choose another model."
|
|
4473
|
+
);
|
|
4474
|
+
}
|
|
4475
|
+
if (error instanceof ProviderError) {
|
|
4476
|
+
if (base.statusCode != null && base.statusCode >= 500) {
|
|
4477
|
+
return present(
|
|
4478
|
+
"provider",
|
|
4479
|
+
`${provider} couldn\u2019t complete the request`,
|
|
4480
|
+
"Try again later. Check details if it keeps happening."
|
|
4481
|
+
);
|
|
4482
|
+
}
|
|
4483
|
+
return present(
|
|
4484
|
+
"provider",
|
|
4485
|
+
`${provider} didn\u2019t accept the request`,
|
|
4486
|
+
"Check the details before trying again."
|
|
4487
|
+
);
|
|
4488
|
+
}
|
|
4489
|
+
return present("unknown", "Something went wrong", "Open details to see what was reported.");
|
|
4490
|
+
}
|
|
4491
|
+
function providerLabel(provider) {
|
|
4492
|
+
switch (provider) {
|
|
4493
|
+
case "openai":
|
|
4494
|
+
return "OpenAI";
|
|
4495
|
+
case "anthropic":
|
|
4496
|
+
return "Anthropic";
|
|
4497
|
+
case "gemini":
|
|
4498
|
+
return "Gemini";
|
|
4499
|
+
case "xai":
|
|
4500
|
+
return "xAI";
|
|
4501
|
+
case "local":
|
|
4502
|
+
return "The local server";
|
|
4503
|
+
default:
|
|
4504
|
+
return "The provider";
|
|
4505
|
+
}
|
|
4506
|
+
}
|
|
4507
|
+
|
|
4352
4508
|
// src/error-classification.ts
|
|
4353
4509
|
var CONTEXT_OVERFLOW_PATTERNS = [
|
|
4354
4510
|
/context_length_exceeded/i,
|
|
@@ -4738,6 +4894,7 @@ export {
|
|
|
4738
4894
|
classifyProviderError,
|
|
4739
4895
|
dropInvalidToolCalls,
|
|
4740
4896
|
environmentSecrets,
|
|
4897
|
+
formatChatError,
|
|
4741
4898
|
formatError,
|
|
4742
4899
|
formatErrorForDisplay,
|
|
4743
4900
|
hasLoneSurrogate,
|