@prestyj/ai 5.29.1 → 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.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, 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, usesResponsesLite };
|
|
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
|
@@ -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, 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, usesResponsesLite };
|
|
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")) {
|
|
@@ -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
|
|
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;
|
|
@@ -2897,7 +2901,7 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
|
|
|
2897
2901
|
// GPT-5.6/6 require at least low; older models still support thinking off.
|
|
2898
2902
|
// Apply the floor here for every caller, including one-off prompt rewrites.
|
|
2899
2903
|
// `ultra` is a client orchestration preset, not a Codex API effort.
|
|
2900
|
-
effort: options.thinking
|
|
2904
|
+
effort: options.thinking ? toCodexReasoningEffort(options.thinking, options.model) : responsesLite ? "low" : "none",
|
|
2901
2905
|
summary: "auto",
|
|
2902
2906
|
...liteShape ? { context: "all_turns" } : {}
|
|
2903
2907
|
};
|
|
@@ -2958,9 +2962,9 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
|
|
|
2958
2962
|
if (usageLimit) throw usageLimit;
|
|
2959
2963
|
let hint;
|
|
2960
2964
|
if (response.status === 400 && message === `The '${options.model}' model is not supported when using Codex with a ChatGPT account.`) {
|
|
2961
|
-
hint = "This model is not available through your ChatGPT account.
|
|
2965
|
+
hint = "This model is not available through your ChatGPT account. Choose another available model using the model selector.";
|
|
2962
2966
|
} else if (response.status === 404 && text.includes("does not exist")) {
|
|
2963
|
-
hint = "This model is not in OpenAI's current catalog for your ChatGPT account.
|
|
2967
|
+
hint = "This model is not in OpenAI's current catalog for your ChatGPT account. Choose another available model using the model selector.";
|
|
2964
2968
|
}
|
|
2965
2969
|
throw new ProviderError("openai", message, {
|
|
2966
2970
|
statusCode: response.status,
|
|
@@ -3433,6 +3437,7 @@ function codexUsageLimitError(errorObj, statusCode, requestId) {
|
|
|
3433
3437
|
const isRateOr429 = CODEX_RATE_LIMIT_CODE.test(code) || statusCode === 429;
|
|
3434
3438
|
if (!isHardUsage && !(isRateOr429 && resetsAt != null)) return null;
|
|
3435
3439
|
return new ProviderError("openai", "ChatGPT usage limit reached", {
|
|
3440
|
+
cause: errorObj,
|
|
3436
3441
|
statusCode: statusCode ?? 429,
|
|
3437
3442
|
...requestId ? { requestId } : {},
|
|
3438
3443
|
...resetsAt ? { resetsAt } : {}
|
|
@@ -4363,6 +4368,157 @@ function messagesContainVideo(messages) {
|
|
|
4363
4368
|
return false;
|
|
4364
4369
|
}
|
|
4365
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
|
+
|
|
4366
4522
|
// src/error-classification.ts
|
|
4367
4523
|
var CONTEXT_OVERFLOW_PATTERNS = [
|
|
4368
4524
|
/context_length_exceeded/i,
|
|
@@ -4752,6 +4908,7 @@ export {
|
|
|
4752
4908
|
classifyProviderError,
|
|
4753
4909
|
dropInvalidToolCalls,
|
|
4754
4910
|
environmentSecrets,
|
|
4911
|
+
formatChatError,
|
|
4755
4912
|
formatError,
|
|
4756
4913
|
formatErrorForDisplay,
|
|
4757
4914
|
hasLoneSurrogate,
|