@prestyj/ai 5.11.0 → 5.12.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 +57 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +57 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1226,7 +1226,7 @@ function parseToolArguments(argsJson) {
|
|
|
1226
1226
|
var NON_STREAMING_TIMEOUT_MS = 60 * 60 * 1e3;
|
|
1227
1227
|
var anthropicClientCache = /* @__PURE__ */ new Map();
|
|
1228
1228
|
function fineGrainedToolStreamingEnabled() {
|
|
1229
|
-
const raw = process.env.
|
|
1229
|
+
const raw = process.env.EZ_FINE_GRAINED_TOOL_STREAMING ?? process.env.CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING;
|
|
1230
1230
|
if (!raw) return false;
|
|
1231
1231
|
const v = raw.trim().toLowerCase();
|
|
1232
1232
|
return v === "1" || v === "true" || v === "yes" || v === "on";
|
|
@@ -2091,7 +2091,15 @@ async function* runStream2(options) {
|
|
|
2091
2091
|
if (chunk.usage) {
|
|
2092
2092
|
({ inputTokens, outputTokens, cacheRead, cacheWrite } = extractOpenAIUsage(chunk.usage));
|
|
2093
2093
|
}
|
|
2094
|
-
if (!choice)
|
|
2094
|
+
if (!choice) {
|
|
2095
|
+
const gatewayError = classifyChoicelessFrame(chunk);
|
|
2096
|
+
if (gatewayError) {
|
|
2097
|
+
throw new ProviderError(providerName, gatewayError.message, {
|
|
2098
|
+
statusCode: gatewayError.statusCode
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
continue;
|
|
2102
|
+
}
|
|
2095
2103
|
if (choice.finish_reason) {
|
|
2096
2104
|
finishReason = choice.finish_reason;
|
|
2097
2105
|
}
|
|
@@ -2275,6 +2283,31 @@ function completionToResponse(completion, endpointKey) {
|
|
|
2275
2283
|
}
|
|
2276
2284
|
};
|
|
2277
2285
|
}
|
|
2286
|
+
function classifyChoicelessFrame(frame) {
|
|
2287
|
+
if (!frame || typeof frame !== "object" || Array.isArray(frame)) return null;
|
|
2288
|
+
const rec = frame;
|
|
2289
|
+
if (Array.isArray(rec.choices)) return null;
|
|
2290
|
+
const statusOf = (value) => {
|
|
2291
|
+
const n = typeof value === "string" ? Number(value) : value;
|
|
2292
|
+
return typeof n === "number" && Number.isFinite(n) && n >= 400 && n <= 599 ? n : void 0;
|
|
2293
|
+
};
|
|
2294
|
+
const statusCode = statusOf(rec.status) ?? statusOf(rec.statusCode) ?? statusOf(rec.code);
|
|
2295
|
+
const typeIsError = typeof rec.type === "string" && rec.type.toLowerCase() === "error";
|
|
2296
|
+
let detailText;
|
|
2297
|
+
const detail = rec.detail;
|
|
2298
|
+
if (typeof detail === "string" && detail.trim()) {
|
|
2299
|
+
detailText = detail.trim();
|
|
2300
|
+
} else if (Array.isArray(detail)) {
|
|
2301
|
+
const parts = detail.map(
|
|
2302
|
+
(d) => d && typeof d === "object" && typeof d.msg === "string" ? d.msg : typeof d === "string" ? d : ""
|
|
2303
|
+
).filter(Boolean);
|
|
2304
|
+
if (parts.length) detailText = parts.join("; ");
|
|
2305
|
+
}
|
|
2306
|
+
if (statusCode === void 0 && !typeIsError && !detailText) return null;
|
|
2307
|
+
const rawMessage = (typeof rec.message === "string" && rec.message.trim() ? rec.message.trim() : void 0) ?? detailText ?? (typeof rec.error === "string" && rec.error.trim() ? rec.error.trim() : void 0) ?? (statusCode !== void 0 ? `Gateway returned status ${statusCode}.` : "Gateway error.");
|
|
2308
|
+
const message = rawMessage.slice(0, 500);
|
|
2309
|
+
return { message, statusCode };
|
|
2310
|
+
}
|
|
2278
2311
|
function classifyOpenAICompatLimit(args) {
|
|
2279
2312
|
const { status, code, type, message } = args;
|
|
2280
2313
|
const codeType = `${code ?? ""} ${type ?? ""}`.toLowerCase();
|
|
@@ -2286,6 +2319,7 @@ function classifyOpenAICompatLimit(args) {
|
|
|
2286
2319
|
return null;
|
|
2287
2320
|
}
|
|
2288
2321
|
function toError2(err, provider = "openai") {
|
|
2322
|
+
if (err instanceof ProviderError) return err;
|
|
2289
2323
|
if (err instanceof import_openai.default.APIError) {
|
|
2290
2324
|
const body = err.error;
|
|
2291
2325
|
const bodyMessage = typeof body?.message === "string" && body.message.trim() ? body.message.trim() : void 0;
|
|
@@ -3646,6 +3680,8 @@ function sanitizeMessagesForWire(messages) {
|
|
|
3646
3680
|
// src/stream.ts
|
|
3647
3681
|
var GLM_CODING_BASE_URL = "https://api.z.ai/api/coding/paas/v4";
|
|
3648
3682
|
var KIMI_CODE_USER_AGENT = `kimi-code-cli/${process.env.KIMI_CODE_VERSION ?? "1.0.11"}`;
|
|
3683
|
+
var GROK_CLI_PROXY_HOST = "cli-chat-proxy.grok.com";
|
|
3684
|
+
var GROK_CLI_VERSION = process.env.GROK_CLI_VERSION ?? "0.2.101";
|
|
3649
3685
|
providerRegistry.register("anthropic", {
|
|
3650
3686
|
stream: (options) => streamAnthropic(options)
|
|
3651
3687
|
});
|
|
@@ -3712,13 +3748,25 @@ providerRegistry.register("xai", {
|
|
|
3712
3748
|
// xAI's public API (console.x.ai key) is OpenAI-compatible — ride the Chat
|
|
3713
3749
|
// Completions transport like Moonshot/DeepSeek. Grok reasoning models take
|
|
3714
3750
|
// top-level `reasoning_effort` (low/medium/high), which the shared thinking
|
|
3715
|
-
// path already sends.
|
|
3716
|
-
//
|
|
3717
|
-
//
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3751
|
+
// path already sends.
|
|
3752
|
+
//
|
|
3753
|
+
// Subscription OAuth (SuperGrok / X Premium) routes to the Grok CLI chat proxy
|
|
3754
|
+
// instead, which speaks the same Chat Completions wire but gates on Grok-CLI
|
|
3755
|
+
// client identity. Inject those headers centrally here — exactly as the Kimi
|
|
3756
|
+
// endpoint above — so EVERY stream (agent loop, compaction, title-gen,
|
|
3757
|
+
// sub-agents) is accepted rather than depending on each call site to thread
|
|
3758
|
+
// headers. Caller-provided headers still win on collision.
|
|
3759
|
+
stream: (options) => {
|
|
3760
|
+
const baseUrl = options.baseUrl ?? "https://api.x.ai/v1";
|
|
3761
|
+
const defaultHeaders = baseUrl.includes(GROK_CLI_PROXY_HOST) ? {
|
|
3762
|
+
"X-XAI-Token-Auth": "xai-grok-cli",
|
|
3763
|
+
"x-grok-client-version": GROK_CLI_VERSION,
|
|
3764
|
+
"x-grok-client-identifier": "ezcoder",
|
|
3765
|
+
"x-grok-model-override": options.model,
|
|
3766
|
+
...options.defaultHeaders
|
|
3767
|
+
} : options.defaultHeaders;
|
|
3768
|
+
return streamOpenAI({ ...options, baseUrl, defaultHeaders });
|
|
3769
|
+
}
|
|
3722
3770
|
});
|
|
3723
3771
|
providerRegistry.register("minimax", {
|
|
3724
3772
|
stream: (options) => streamAnthropic({
|