@prestyj/ai 5.1.1 → 5.3.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/README.md +1 -1
- package/dist/index.cjs +21 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -285,7 +285,7 @@ declare class StreamResult implements AsyncIterable<StreamEvent> {
|
|
|
285
285
|
*
|
|
286
286
|
* ```ts
|
|
287
287
|
* // Stream events
|
|
288
|
-
* for await (const event of stream({ provider: "anthropic", model: "claude-sonnet-
|
|
288
|
+
* for await (const event of stream({ provider: "anthropic", model: "claude-sonnet-5", messages })) {
|
|
289
289
|
* if (event.type === "text_delta") process.stdout.write(event.text);
|
|
290
290
|
* }
|
|
291
291
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -285,7 +285,7 @@ declare class StreamResult implements AsyncIterable<StreamEvent> {
|
|
|
285
285
|
*
|
|
286
286
|
* ```ts
|
|
287
287
|
* // Stream events
|
|
288
|
-
* for await (const event of stream({ provider: "anthropic", model: "claude-sonnet-
|
|
288
|
+
* for await (const event of stream({ provider: "anthropic", model: "claude-sonnet-5", messages })) {
|
|
289
289
|
* if (event.type === "text_delta") process.stdout.write(event.text);
|
|
290
290
|
* }
|
|
291
291
|
*
|
package/dist/index.js
CHANGED
|
@@ -89,6 +89,22 @@ function isMythosAccessError(message) {
|
|
|
89
89
|
const lower = message.toLowerCase();
|
|
90
90
|
return lower.includes("mythos") && (lower.includes("not_found") || lower.includes("not found") || lower.includes("no access"));
|
|
91
91
|
}
|
|
92
|
+
function isRawJsonErrorEcho(message) {
|
|
93
|
+
const trimmed = message.trim();
|
|
94
|
+
const jsonStart = trimmed.indexOf("{");
|
|
95
|
+
if (jsonStart === -1) return false;
|
|
96
|
+
const prefix = trimmed.slice(0, jsonStart).trim();
|
|
97
|
+
if (prefix && !/^\d+$/.test(prefix)) return false;
|
|
98
|
+
try {
|
|
99
|
+
const parsed = JSON.parse(trimmed.slice(jsonStart));
|
|
100
|
+
return typeof parsed === "object" && parsed !== null;
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function emptyProviderErrorMessage(statusCode) {
|
|
106
|
+
return statusCode ? `The provider returned an empty error response (HTTP ${statusCode}), with no further detail.` : "The provider returned an empty error response, with no further detail.";
|
|
107
|
+
}
|
|
92
108
|
function formatError(err) {
|
|
93
109
|
if (err instanceof ProviderError) {
|
|
94
110
|
const name = providerDisplayName(err.provider);
|
|
@@ -784,7 +800,7 @@ function toAnthropicToolChoice(choice) {
|
|
|
784
800
|
return { type: "tool", name: choice.name };
|
|
785
801
|
}
|
|
786
802
|
function isAdaptiveThinkingModel(model) {
|
|
787
|
-
return /opus-4[-.]8|opus-4[-.]7|opus-4[-.]6|sonnet-
|
|
803
|
+
return /opus-4[-.]8|opus-4[-.]7|opus-4[-.]6|sonnet-5|fable-5|mythos-5/.test(model);
|
|
788
804
|
}
|
|
789
805
|
function toAnthropicThinking(level, maxTokens, model) {
|
|
790
806
|
if (isAdaptiveThinkingModel(model)) {
|
|
@@ -1541,9 +1557,10 @@ function toError(err) {
|
|
|
1541
1557
|
const errorBody = err.error;
|
|
1542
1558
|
const nestedError = errorBody?.error;
|
|
1543
1559
|
const requestId = err.requestID ?? err.request_id ?? (typeof errorBody?.request_id === "string" ? errorBody.request_id : void 0) ?? (typeof nestedError?.request_id === "string" ? nestedError.request_id : void 0) ?? void 0;
|
|
1544
|
-
const bodyMessage = typeof nestedError?.message === "string" ? nestedError.message : typeof errorBody?.message === "string" ? errorBody.message : void 0;
|
|
1560
|
+
const bodyMessage = typeof nestedError?.message === "string" && nestedError.message.trim() ? nestedError.message.trim() : typeof errorBody?.message === "string" && errorBody.message.trim() ? errorBody.message.trim() : void 0;
|
|
1545
1561
|
const bodyType = typeof nestedError?.type === "string" ? nestedError.type : typeof errorBody?.type === "string" ? errorBody.type : typeof err.type === "string" ? err.type : void 0;
|
|
1546
|
-
const
|
|
1562
|
+
const fallbackMessage = isRawJsonErrorEcho(err.message) ? emptyProviderErrorMessage(err.status) : err.message;
|
|
1563
|
+
const message = bodyType && bodyMessage ? `${bodyType}: ${bodyMessage}` : bodyMessage ?? fallbackMessage;
|
|
1547
1564
|
if (err.status === 429) {
|
|
1548
1565
|
const limit = readUnifiedRateLimit(err.headers);
|
|
1549
1566
|
const farOff = limit.resetsAt != null && limit.resetsAt * 1e3 - Date.now() > 6e4;
|
|
@@ -1992,7 +2009,7 @@ function toError2(err, provider = "openai") {
|
|
|
1992
2009
|
const body = err.error;
|
|
1993
2010
|
const bodyMessage = typeof body?.message === "string" && body.message.trim() ? body.message.trim() : void 0;
|
|
1994
2011
|
const modelName = typeof body?.model === "string" ? body.model : "";
|
|
1995
|
-
const cleanMessage = bodyMessage ?? err.message;
|
|
2012
|
+
const cleanMessage = bodyMessage ?? (isRawJsonErrorEcho(err.message) ? emptyProviderErrorMessage(err.status) : err.message);
|
|
1996
2013
|
let hint;
|
|
1997
2014
|
if (modelName === "codex-mini-latest" || cleanMessage.includes("codex-mini-latest")) {
|
|
1998
2015
|
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.";
|