@kenkaiiii/gg-ai 4.3.243 → 4.4.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 +92 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -404,6 +404,19 @@ declare function formatError(err: unknown): FormattedError;
|
|
|
404
404
|
*/
|
|
405
405
|
declare function formatErrorForDisplay(err: unknown): string;
|
|
406
406
|
|
|
407
|
+
/**
|
|
408
|
+
* Inspect a raw provider error message and tag it with a clearer, actionable
|
|
409
|
+
* prefix so a worker orchestrator can route on intent instead of regexing JSON.
|
|
410
|
+
* Preserves the original message verbatim after the prefix — helpful for
|
|
411
|
+
* debugging.
|
|
412
|
+
*
|
|
413
|
+
* Order matters: context-overflow is checked first because some providers wrap
|
|
414
|
+
* overflow errors in HTTP 429 envelopes; we want the structural meaning, not
|
|
415
|
+
* the transport status. Billing comes before auth/rate-limit because "402
|
|
416
|
+
* Payment Required" must not be mis-routed as a rate-limit retry.
|
|
417
|
+
*/
|
|
418
|
+
declare function classifyProviderError(message: string): string;
|
|
419
|
+
|
|
407
420
|
/**
|
|
408
421
|
* Provider-level diagnostic hook. Mirrors the pattern used by gg-agent's
|
|
409
422
|
* setStreamDiagnostic — the host app wires a callback (typically writing to
|
|
@@ -496,4 +509,4 @@ interface PalsuProviderConfig {
|
|
|
496
509
|
*/
|
|
497
510
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
498
511
|
|
|
499
|
-
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, formatError, formatErrorForDisplay, isHardBillingMessage, isUsageLimitError, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, setProviderDiagnostic, stream, toAnthropicMessages, toOpenAIMessages };
|
|
512
|
+
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, classifyProviderError, formatError, formatErrorForDisplay, isHardBillingMessage, isUsageLimitError, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, setProviderDiagnostic, stream, toAnthropicMessages, toOpenAIMessages };
|
package/dist/index.d.ts
CHANGED
|
@@ -404,6 +404,19 @@ declare function formatError(err: unknown): FormattedError;
|
|
|
404
404
|
*/
|
|
405
405
|
declare function formatErrorForDisplay(err: unknown): string;
|
|
406
406
|
|
|
407
|
+
/**
|
|
408
|
+
* Inspect a raw provider error message and tag it with a clearer, actionable
|
|
409
|
+
* prefix so a worker orchestrator can route on intent instead of regexing JSON.
|
|
410
|
+
* Preserves the original message verbatim after the prefix — helpful for
|
|
411
|
+
* debugging.
|
|
412
|
+
*
|
|
413
|
+
* Order matters: context-overflow is checked first because some providers wrap
|
|
414
|
+
* overflow errors in HTTP 429 envelopes; we want the structural meaning, not
|
|
415
|
+
* the transport status. Billing comes before auth/rate-limit because "402
|
|
416
|
+
* Payment Required" must not be mis-routed as a rate-limit retry.
|
|
417
|
+
*/
|
|
418
|
+
declare function classifyProviderError(message: string): string;
|
|
419
|
+
|
|
407
420
|
/**
|
|
408
421
|
* Provider-level diagnostic hook. Mirrors the pattern used by gg-agent's
|
|
409
422
|
* setStreamDiagnostic — the host app wires a callback (typically writing to
|
|
@@ -496,4 +509,4 @@ interface PalsuProviderConfig {
|
|
|
496
509
|
*/
|
|
497
510
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
498
511
|
|
|
499
|
-
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, formatError, formatErrorForDisplay, isHardBillingMessage, isUsageLimitError, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, setProviderDiagnostic, stream, toAnthropicMessages, toOpenAIMessages };
|
|
512
|
+
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, classifyProviderError, formatError, formatErrorForDisplay, isHardBillingMessage, isUsageLimitError, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, setProviderDiagnostic, stream, toAnthropicMessages, toOpenAIMessages };
|
package/dist/index.js
CHANGED
|
@@ -2823,6 +2823,96 @@ function stream(options) {
|
|
|
2823
2823
|
return entry.stream(options);
|
|
2824
2824
|
}
|
|
2825
2825
|
|
|
2826
|
+
// src/error-classification.ts
|
|
2827
|
+
var CONTEXT_OVERFLOW_PATTERNS = [
|
|
2828
|
+
/context_length_exceeded/i,
|
|
2829
|
+
/context length exceeded/i,
|
|
2830
|
+
/context window/i,
|
|
2831
|
+
// OpenAI Codex / Responses
|
|
2832
|
+
/maximum context length/i,
|
|
2833
|
+
// OpenAI / OpenRouter / Mistral
|
|
2834
|
+
/prompt is too long/i,
|
|
2835
|
+
// Anthropic
|
|
2836
|
+
/request_too_large/i,
|
|
2837
|
+
// Anthropic HTTP 413
|
|
2838
|
+
/input is too long/i,
|
|
2839
|
+
// Bedrock
|
|
2840
|
+
/input token count.*exceeds the maximum/i,
|
|
2841
|
+
// Gemini
|
|
2842
|
+
/maximum prompt length/i,
|
|
2843
|
+
// xAI / Grok
|
|
2844
|
+
/reduce the length of the messages/i,
|
|
2845
|
+
// Groq
|
|
2846
|
+
/too large for model/i,
|
|
2847
|
+
// Mistral
|
|
2848
|
+
/token limit/i
|
|
2849
|
+
// generic
|
|
2850
|
+
];
|
|
2851
|
+
var RATE_LIMIT_PATTERNS = [
|
|
2852
|
+
/rate[ _-]?limit/i,
|
|
2853
|
+
/\b429\b/,
|
|
2854
|
+
/too many requests/i,
|
|
2855
|
+
/tokens per minute/i,
|
|
2856
|
+
/requests per minute/i
|
|
2857
|
+
];
|
|
2858
|
+
var PROVIDER_TRANSIENT_PATTERNS = [
|
|
2859
|
+
/\b5\d\d\b/,
|
|
2860
|
+
/api_error/i,
|
|
2861
|
+
/server_error/i,
|
|
2862
|
+
/internal server error/i,
|
|
2863
|
+
/bad gateway/i,
|
|
2864
|
+
/service unavailable/i,
|
|
2865
|
+
/gateway timeout/i,
|
|
2866
|
+
/overloaded/i,
|
|
2867
|
+
/\b529\b/
|
|
2868
|
+
];
|
|
2869
|
+
var BILLING_PATTERNS = [
|
|
2870
|
+
/payment required/i,
|
|
2871
|
+
/\b402\b/,
|
|
2872
|
+
/quota_exceeded/i,
|
|
2873
|
+
// underscore variant not in isHardBillingMessage
|
|
2874
|
+
/credit balance/i
|
|
2875
|
+
];
|
|
2876
|
+
var AUTH_PATTERNS = [
|
|
2877
|
+
/invalid[ _]api[ _]key/i,
|
|
2878
|
+
/unauthorized/i,
|
|
2879
|
+
/\b401\b/,
|
|
2880
|
+
/authentication[ _]failed/i,
|
|
2881
|
+
/please run \/login/i
|
|
2882
|
+
// Anthropic Claude Code-style hint
|
|
2883
|
+
];
|
|
2884
|
+
function matchesAny(message, patterns) {
|
|
2885
|
+
return patterns.some((p) => p.test(message));
|
|
2886
|
+
}
|
|
2887
|
+
function classifyProviderError(message) {
|
|
2888
|
+
if (matchesAny(message, CONTEXT_OVERFLOW_PATTERNS)) {
|
|
2889
|
+
return `[context_overflow] Worker context window exceeded \u2014 the conversation is too large to continue. Recovery: call reset_worker(project) to wipe history, then re-prompt with the task. Re-prompting WITHOUT reset will fail the same way.
|
|
2890
|
+
|
|
2891
|
+
Original: ${message}`;
|
|
2892
|
+
}
|
|
2893
|
+
if (isHardBillingMessage(message) || matchesAny(message, BILLING_PATTERNS)) {
|
|
2894
|
+
return `[billing] Provider billing/quota issue. Recovery: surface to the user \u2014 they need to top up or switch providers. Do NOT retry.
|
|
2895
|
+
|
|
2896
|
+
Original: ${message}`;
|
|
2897
|
+
}
|
|
2898
|
+
if (matchesAny(message, AUTH_PATTERNS)) {
|
|
2899
|
+
return `[auth] Provider authentication failed. Recovery: surface to the user \u2014 they need to re-login. Do NOT retry.
|
|
2900
|
+
|
|
2901
|
+
Original: ${message}`;
|
|
2902
|
+
}
|
|
2903
|
+
if (matchesAny(message, RATE_LIMIT_PATTERNS)) {
|
|
2904
|
+
return `[rate_limited] Provider rate limit hit. Recovery: wait ~30s, then re-prompt the same worker (no reset needed).
|
|
2905
|
+
|
|
2906
|
+
Original: ${message}`;
|
|
2907
|
+
}
|
|
2908
|
+
if (matchesAny(message, PROVIDER_TRANSIENT_PATTERNS)) {
|
|
2909
|
+
return `[provider_transient] Provider server-side/transient error. Recovery: wait briefly, then re-prompt the same worker (no reset needed). If it keeps happening, switch models/providers or check provider status.
|
|
2910
|
+
|
|
2911
|
+
Original: ${message}`;
|
|
2912
|
+
}
|
|
2913
|
+
return message;
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2826
2916
|
// src/providers/palsu.ts
|
|
2827
2917
|
function palsuText(text) {
|
|
2828
2918
|
return { role: "assistant", content: text ? [{ type: "text", text }] : [] };
|
|
@@ -2979,6 +3069,7 @@ export {
|
|
|
2979
3069
|
GGAIError,
|
|
2980
3070
|
ProviderError,
|
|
2981
3071
|
StreamResult,
|
|
3072
|
+
classifyProviderError,
|
|
2982
3073
|
formatError,
|
|
2983
3074
|
formatErrorForDisplay,
|
|
2984
3075
|
isHardBillingMessage,
|