@kenkaiiii/gg-ai 5.89.0 → 5.91.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 +107 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +105 -34
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -467,6 +467,10 @@ declare function localWireModelId(id: string): string;
|
|
|
467
467
|
*/
|
|
468
468
|
declare function stream(requested: StreamOptions): StreamResult;
|
|
469
469
|
|
|
470
|
+
declare const LOCAL_NO_API_KEY = "local";
|
|
471
|
+
/** The key to send to a local endpoint, or undefined when it has none. */
|
|
472
|
+
declare function localBearerKey(apiKey: string | undefined): string | undefined;
|
|
473
|
+
|
|
470
474
|
/**
|
|
471
475
|
* Fast-mode model ids: `<base model id>` + this suffix selects the same model
|
|
472
476
|
* at its provider's faster speed tier. The suffixed id is a registry/UI concept
|
|
@@ -1165,4 +1169,4 @@ declare function palsuEmbedding(text: string, dimensions?: number): number[];
|
|
|
1165
1169
|
/** Deterministic fake relevance: the share of distinct query words found in the document (0–1). */
|
|
1166
1170
|
declare function palsuRerankScore(query: string, document: string): number;
|
|
1167
1171
|
|
|
1168
|
-
export { type AssistantMessage, CLAUDE_CODE_FALLBACK_VERSION, CODEX_CLIENT_VERSION, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type EmbedInputType, type EmbedOptions, type EmbedResult, type EmbedUsage, type ErrorEvent, type ErrorSource, EventStream, FAST_MODE_SUFFIX, type FastModeRejection, type FastModeResolution, type FormattedChatError, type FormattedError, GGAIError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type OpenRouterProviderPreferences, PRECONNECT_INTERVAL_MS, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreconnectOptions, type PreparedContext, type Provider, type ProviderCapability, type ProviderDiagnosticFn, type ProviderEmbedFn, type ProviderEmbedRequest, type ProviderEmbedResponse, type ProviderEntry, ProviderError, type ProviderOptions, type ProviderRerankFn, type ProviderRerankRequest, type ProviderRerankResponse, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type RerankOptions, type RerankResponse, type RerankResult, type RerankUsage, ResponseStalledError, 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, continuesTurn, describeFastModeRejection, dropInvalidToolCalls, embed, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, getClaudeCliUserAgent, getClaudeCodeVersion, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, opensTurn, palsuAssistantMessage, palsuEmbedding, palsuRerankScore, palsuText, palsuThinking, palsuToolCall, parseFastModeRejection, pendingClaudeCodeVersionRefresh, preconnectOrigin, preconnectProvider, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, rerank, resolveFastModeModel, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
|
|
1172
|
+
export { type AssistantMessage, CLAUDE_CODE_FALLBACK_VERSION, CODEX_CLIENT_VERSION, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type EmbedInputType, type EmbedOptions, type EmbedResult, type EmbedUsage, type ErrorEvent, type ErrorSource, EventStream, FAST_MODE_SUFFIX, type FastModeRejection, type FastModeResolution, type FormattedChatError, type FormattedError, GGAIError, type ImageContent, LOCAL_NO_API_KEY, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type OpenRouterProviderPreferences, PRECONNECT_INTERVAL_MS, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreconnectOptions, type PreparedContext, type Provider, type ProviderCapability, type ProviderDiagnosticFn, type ProviderEmbedFn, type ProviderEmbedRequest, type ProviderEmbedResponse, type ProviderEntry, ProviderError, type ProviderOptions, type ProviderRerankFn, type ProviderRerankRequest, type ProviderRerankResponse, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type RerankOptions, type RerankResponse, type RerankResult, type RerankUsage, ResponseStalledError, 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, continuesTurn, describeFastModeRejection, dropInvalidToolCalls, embed, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, getClaudeCliUserAgent, getClaudeCodeVersion, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localBearerKey, localWireModelId, opensTurn, palsuAssistantMessage, palsuEmbedding, palsuRerankScore, palsuText, palsuThinking, palsuToolCall, parseFastModeRejection, pendingClaudeCodeVersionRefresh, preconnectOrigin, preconnectProvider, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, rerank, resolveFastModeModel, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
|
package/dist/index.d.ts
CHANGED
|
@@ -467,6 +467,10 @@ declare function localWireModelId(id: string): string;
|
|
|
467
467
|
*/
|
|
468
468
|
declare function stream(requested: StreamOptions): StreamResult;
|
|
469
469
|
|
|
470
|
+
declare const LOCAL_NO_API_KEY = "local";
|
|
471
|
+
/** The key to send to a local endpoint, or undefined when it has none. */
|
|
472
|
+
declare function localBearerKey(apiKey: string | undefined): string | undefined;
|
|
473
|
+
|
|
470
474
|
/**
|
|
471
475
|
* Fast-mode model ids: `<base model id>` + this suffix selects the same model
|
|
472
476
|
* at its provider's faster speed tier. The suffixed id is a registry/UI concept
|
|
@@ -1165,4 +1169,4 @@ declare function palsuEmbedding(text: string, dimensions?: number): number[];
|
|
|
1165
1169
|
/** Deterministic fake relevance: the share of distinct query words found in the document (0–1). */
|
|
1166
1170
|
declare function palsuRerankScore(query: string, document: string): number;
|
|
1167
1171
|
|
|
1168
|
-
export { type AssistantMessage, CLAUDE_CODE_FALLBACK_VERSION, CODEX_CLIENT_VERSION, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type EmbedInputType, type EmbedOptions, type EmbedResult, type EmbedUsage, type ErrorEvent, type ErrorSource, EventStream, FAST_MODE_SUFFIX, type FastModeRejection, type FastModeResolution, type FormattedChatError, type FormattedError, GGAIError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type OpenRouterProviderPreferences, PRECONNECT_INTERVAL_MS, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreconnectOptions, type PreparedContext, type Provider, type ProviderCapability, type ProviderDiagnosticFn, type ProviderEmbedFn, type ProviderEmbedRequest, type ProviderEmbedResponse, type ProviderEntry, ProviderError, type ProviderOptions, type ProviderRerankFn, type ProviderRerankRequest, type ProviderRerankResponse, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type RerankOptions, type RerankResponse, type RerankResult, type RerankUsage, ResponseStalledError, 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, continuesTurn, describeFastModeRejection, dropInvalidToolCalls, embed, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, getClaudeCliUserAgent, getClaudeCodeVersion, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, opensTurn, palsuAssistantMessage, palsuEmbedding, palsuRerankScore, palsuText, palsuThinking, palsuToolCall, parseFastModeRejection, pendingClaudeCodeVersionRefresh, preconnectOrigin, preconnectProvider, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, rerank, resolveFastModeModel, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
|
|
1172
|
+
export { type AssistantMessage, CLAUDE_CODE_FALLBACK_VERSION, CODEX_CLIENT_VERSION, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type EmbedInputType, type EmbedOptions, type EmbedResult, type EmbedUsage, type ErrorEvent, type ErrorSource, EventStream, FAST_MODE_SUFFIX, type FastModeRejection, type FastModeResolution, type FormattedChatError, type FormattedError, GGAIError, type ImageContent, LOCAL_NO_API_KEY, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type OpenRouterProviderPreferences, PRECONNECT_INTERVAL_MS, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreconnectOptions, type PreparedContext, type Provider, type ProviderCapability, type ProviderDiagnosticFn, type ProviderEmbedFn, type ProviderEmbedRequest, type ProviderEmbedResponse, type ProviderEntry, ProviderError, type ProviderOptions, type ProviderRerankFn, type ProviderRerankRequest, type ProviderRerankResponse, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type RerankOptions, type RerankResponse, type RerankResult, type RerankUsage, ResponseStalledError, 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, continuesTurn, describeFastModeRejection, dropInvalidToolCalls, embed, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, getClaudeCliUserAgent, getClaudeCodeVersion, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localBearerKey, localWireModelId, opensTurn, palsuAssistantMessage, palsuEmbedding, palsuRerankScore, palsuText, palsuThinking, palsuToolCall, parseFastModeRejection, pendingClaudeCodeVersionRefresh, preconnectOrigin, preconnectProvider, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, rerank, resolveFastModeModel, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
|
package/dist/index.js
CHANGED
|
@@ -241,6 +241,8 @@ function formatError(err) {
|
|
|
241
241
|
guidance: fastRejection.guidance
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
+
const miniMax = err.provider === "minimax" ? formatMiniMaxError(err, cleanMessage) : void 0;
|
|
245
|
+
if (miniMax) return miniMax;
|
|
244
246
|
if (isUsageLimitError(err)) {
|
|
245
247
|
const resetClause = err.resetsAt ? ` It resets at ${formatResetTime(err.resetsAt)}.` : "";
|
|
246
248
|
return {
|
|
@@ -347,6 +349,38 @@ function inferSource(err) {
|
|
|
347
349
|
}
|
|
348
350
|
return "ggcoder";
|
|
349
351
|
}
|
|
352
|
+
function formatMiniMaxError(err, cleanMessage) {
|
|
353
|
+
const code = /\((\d{4,5})\)/.exec(err.message)?.[1];
|
|
354
|
+
const base = {
|
|
355
|
+
source: "provider",
|
|
356
|
+
message: cleanMessage,
|
|
357
|
+
provider: err.provider,
|
|
358
|
+
statusCode: err.statusCode,
|
|
359
|
+
...err.requestId ? { requestId: err.requestId } : {}
|
|
360
|
+
};
|
|
361
|
+
if (code === "2049" || code === "1004") {
|
|
362
|
+
return {
|
|
363
|
+
...base,
|
|
364
|
+
headline: "MiniMax didn't accept this API key.",
|
|
365
|
+
guidance: "A MiniMax key only works in the region that issued it (Global: platform.minimax.io, Mainland China: platform.minimaxi.com). Connect MiniMax again with the key so GG Coder can detect its region, and check the key is active."
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
if (code === "2061") {
|
|
369
|
+
return {
|
|
370
|
+
...base,
|
|
371
|
+
headline: "Your MiniMax plan doesn't include this model.",
|
|
372
|
+
guidance: "Switch to MiniMax M3.1 Flash in the model selector \u2014 it's the model M Plan and Token Plan cover. MiniMax M3 needs a pay-as-you-go key."
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
if (code === "1008") {
|
|
376
|
+
return {
|
|
377
|
+
...base,
|
|
378
|
+
headline: "MiniMax has no balance for this request.",
|
|
379
|
+
guidance: "Check this key's plan is active, or its pay-as-you-go balance, at platform.minimax.io (platform.minimaxi.com for Mainland China keys). Plan keys only cover MiniMax M3.1 Flash. Not a GG Coder issue."
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
return void 0;
|
|
383
|
+
}
|
|
350
384
|
function providerGuidance(provider, message, statusCode) {
|
|
351
385
|
const name = provider ? providerDisplayName(provider) : "the provider";
|
|
352
386
|
const status = provider ? PROVIDER_STATUS_URL[provider] : void 0;
|
|
@@ -1564,10 +1598,22 @@ function toAnthropicMessages(messages, cacheControl, options) {
|
|
|
1564
1598
|
(name) => toolReferences.has(name) && !referencedTools.has(name)
|
|
1565
1599
|
) : [];
|
|
1566
1600
|
if (refs.length === 0) {
|
|
1601
|
+
const content = toAnthropicToolResultContent(result.content);
|
|
1602
|
+
if (result.isError && typeof content !== "string" && content.some((part) => part.type !== "text")) {
|
|
1603
|
+
const text = content.filter((part) => part.type === "text" && part.text !== "");
|
|
1604
|
+
trailing.push({ type: "text", text: `Attachments from tool call ${toolUseId}:` });
|
|
1605
|
+
for (const part of content) if (part.type !== "text") trailing.push(part);
|
|
1606
|
+
return {
|
|
1607
|
+
type: "tool_result",
|
|
1608
|
+
tool_use_id: toolUseId,
|
|
1609
|
+
content: text.length > 0 ? text : "Tool call failed; its attachments follow.",
|
|
1610
|
+
is_error: true
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1567
1613
|
return {
|
|
1568
1614
|
type: "tool_result",
|
|
1569
1615
|
tool_use_id: toolUseId,
|
|
1570
|
-
content
|
|
1616
|
+
content,
|
|
1571
1617
|
is_error: result.isError
|
|
1572
1618
|
};
|
|
1573
1619
|
}
|
|
@@ -1586,7 +1632,8 @@ ${part.text}` } : part
|
|
|
1586
1632
|
type: "tool_result",
|
|
1587
1633
|
tool_use_id: toolUseId,
|
|
1588
1634
|
content: refs.map((name) => ({ type: "tool_reference", tool_name: name })),
|
|
1589
|
-
is_error
|
|
1635
|
+
// tool_reference isn't text, so is_error would 400; the error text trails.
|
|
1636
|
+
is_error: void 0
|
|
1590
1637
|
};
|
|
1591
1638
|
});
|
|
1592
1639
|
out.push({
|
|
@@ -1609,8 +1656,8 @@ ${part.text}` } : part
|
|
|
1609
1656
|
markAnthropicCacheBreakpoint(out, tail, cacheControl);
|
|
1610
1657
|
} else {
|
|
1611
1658
|
if (anchor !== void 0) markAnthropicCacheBreakpoint(out, anchor, cacheControl);
|
|
1612
|
-
const
|
|
1613
|
-
markAnthropicCacheBreakpoint(out, tail,
|
|
1659
|
+
const blocking = calledBlockingTool(messages, trajectoryStartIdx);
|
|
1660
|
+
markAnthropicCacheBreakpoint(out, tail, blocking ? cacheControl : { type: "ephemeral" });
|
|
1614
1661
|
}
|
|
1615
1662
|
} else {
|
|
1616
1663
|
markAnthropicCacheBreakpoint(out, tail, cacheControl);
|
|
@@ -1646,19 +1693,13 @@ var BLOCKING_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
1646
1693
|
"subagent",
|
|
1647
1694
|
"ask_user"
|
|
1648
1695
|
]);
|
|
1649
|
-
|
|
1650
|
-
function isLongToolRun(messages, trajectoryStartIdx) {
|
|
1651
|
-
let rounds = 0;
|
|
1696
|
+
function calledBlockingTool(messages, trajectoryStartIdx) {
|
|
1652
1697
|
for (let i = Math.max(0, trajectoryStartIdx + 1); i < messages.length; i++) {
|
|
1653
1698
|
const m = messages[i];
|
|
1654
1699
|
if (m?.role !== "assistant" || typeof m.content === "string") continue;
|
|
1655
|
-
let called = false;
|
|
1656
1700
|
for (const part of m.content) {
|
|
1657
|
-
if (part.type
|
|
1658
|
-
called = true;
|
|
1659
|
-
if (BLOCKING_TOOL_NAMES.has(part.name)) return true;
|
|
1701
|
+
if (part.type === "tool_call" && BLOCKING_TOOL_NAMES.has(part.name)) return true;
|
|
1660
1702
|
}
|
|
1661
|
-
if (called && ++rounds >= LONG_RUN_ROUNDS) return true;
|
|
1662
1703
|
}
|
|
1663
1704
|
return false;
|
|
1664
1705
|
}
|
|
@@ -1717,6 +1758,13 @@ function isAdaptiveThinkingModel(model) {
|
|
|
1717
1758
|
return /opus-5|opus-4[-.]8|opus-4[-.]7|opus-4[-.]6|sonnet-5|haiku-5|fable-5|mythos-5/.test(model);
|
|
1718
1759
|
}
|
|
1719
1760
|
function toAnthropicThinking(level, maxTokens, model) {
|
|
1761
|
+
if (model.startsWith("MiniMax-M3.1")) {
|
|
1762
|
+
return {
|
|
1763
|
+
thinking: { type: "adaptive" },
|
|
1764
|
+
maxTokens,
|
|
1765
|
+
outputConfig: { effort: level === "ultra" ? "max" : level }
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1720
1768
|
if (isAdaptiveThinkingModel(model)) {
|
|
1721
1769
|
let effort = level;
|
|
1722
1770
|
if (effort === "xhigh" && !/fable-5|mythos-5|opus-5|opus-4-8|opus-4-7|sonnet-5[-.]5|haiku-5[-.]5/.test(model)) {
|
|
@@ -2238,8 +2286,7 @@ async function* runStream(options) {
|
|
|
2238
2286
|
...system ? { system } : {},
|
|
2239
2287
|
...thinking ? { thinking } : {},
|
|
2240
2288
|
...outputConfig ? { output_config: outputConfig } : {},
|
|
2241
|
-
|
|
2242
|
-
...options.topP != null ? { top_p: options.topP } : {},
|
|
2289
|
+
// API version 2026-10-21 (SDK 1.x) rejects temperature/top_p/top_k with a 400.
|
|
2243
2290
|
...options.stop ? { stop_sequences: options.stop } : {},
|
|
2244
2291
|
...(deferredPlan?.live ?? options.tools)?.length || options.serverTools?.length || options.webSearch ? (() => {
|
|
2245
2292
|
const reservedServerNames = /* @__PURE__ */ new Set();
|
|
@@ -2340,7 +2387,7 @@ async function* runStream(options) {
|
|
|
2340
2387
|
yield* synthesizeEventsFromMessage(message);
|
|
2341
2388
|
return messageToResponse(message);
|
|
2342
2389
|
} catch (err) {
|
|
2343
|
-
throw toError(err, { fastMode: useFastMode });
|
|
2390
|
+
throw toError(err, { fastMode: useFastMode, provider: options.provider });
|
|
2344
2391
|
}
|
|
2345
2392
|
}
|
|
2346
2393
|
const contentParts = [];
|
|
@@ -2456,7 +2503,7 @@ async function* runStream(options) {
|
|
|
2456
2503
|
const rawPartial = accum.argsJson;
|
|
2457
2504
|
const snippet = rawPartial.length > 200 ? `${rawPartial.slice(0, 200)}\u2026` : rawPartial;
|
|
2458
2505
|
throw new ProviderError(
|
|
2459
|
-
|
|
2506
|
+
options.provider,
|
|
2460
2507
|
`Tool "${accum.toolName}" input JSON was truncated in the stream (${rawPartial.length} bytes): ${snippet}; ${parseErr.message}`,
|
|
2461
2508
|
{ cause: parseErr }
|
|
2462
2509
|
);
|
|
@@ -2559,15 +2606,15 @@ async function* runStream(options) {
|
|
|
2559
2606
|
}
|
|
2560
2607
|
}
|
|
2561
2608
|
} catch (err) {
|
|
2562
|
-
throw toError(err, { fastMode: useFastMode });
|
|
2609
|
+
throw toError(err, { fastMode: useFastMode, provider: options.provider });
|
|
2563
2610
|
}
|
|
2564
2611
|
if (!receivedAnyEvent) {
|
|
2565
|
-
throw new ProviderError(
|
|
2612
|
+
throw new ProviderError(options.provider, "Stream ended without producing any events.", {
|
|
2566
2613
|
statusCode: 504
|
|
2567
2614
|
});
|
|
2568
2615
|
}
|
|
2569
2616
|
if (stopReason === null) {
|
|
2570
|
-
throw new ProviderError(
|
|
2617
|
+
throw new ProviderError(options.provider, "Stream ended before completion (no stop_reason).", {
|
|
2571
2618
|
statusCode: 504,
|
|
2572
2619
|
cause: { partialContent: contentParts, outputTokens }
|
|
2573
2620
|
});
|
|
@@ -2709,6 +2756,7 @@ function readUnifiedRateLimit(headers) {
|
|
|
2709
2756
|
return { rejected: status === "rejected", ...resetsAt ? { resetsAt } : {} };
|
|
2710
2757
|
}
|
|
2711
2758
|
function toError(err, context) {
|
|
2759
|
+
const provider = context?.provider ?? "anthropic";
|
|
2712
2760
|
if (err instanceof ProviderError) return err;
|
|
2713
2761
|
if (err instanceof Anthropic.APIError) {
|
|
2714
2762
|
const errorBody = err.error;
|
|
@@ -2742,22 +2790,22 @@ function toError(err, context) {
|
|
|
2742
2790
|
}
|
|
2743
2791
|
if (isHardBillingMessage(message)) {
|
|
2744
2792
|
const usageMessage = /usage limit reached/i.test(message) ? message : `usage limit reached: ${message}`;
|
|
2745
|
-
return new ProviderError(
|
|
2793
|
+
return new ProviderError(provider, usageMessage, {
|
|
2746
2794
|
statusCode: err.status,
|
|
2747
2795
|
...requestId ? { requestId } : {},
|
|
2748
2796
|
cause: err
|
|
2749
2797
|
});
|
|
2750
2798
|
}
|
|
2751
|
-
return new ProviderError(
|
|
2799
|
+
return new ProviderError(provider, message, {
|
|
2752
2800
|
statusCode: err.status,
|
|
2753
2801
|
...requestId ? { requestId } : {},
|
|
2754
2802
|
cause: err
|
|
2755
2803
|
});
|
|
2756
2804
|
}
|
|
2757
2805
|
if (err instanceof Error) {
|
|
2758
|
-
return new ProviderError(
|
|
2806
|
+
return new ProviderError(provider, err.message, { cause: err });
|
|
2759
2807
|
}
|
|
2760
|
-
return new ProviderError(
|
|
2808
|
+
return new ProviderError(provider, String(err));
|
|
2761
2809
|
}
|
|
2762
2810
|
|
|
2763
2811
|
// src/providers/openai.ts
|
|
@@ -2845,6 +2893,12 @@ function getEnvironment() {
|
|
|
2845
2893
|
return globalThis.process?.env;
|
|
2846
2894
|
}
|
|
2847
2895
|
|
|
2896
|
+
// src/local-api-key.ts
|
|
2897
|
+
var LOCAL_NO_API_KEY = "local";
|
|
2898
|
+
function localBearerKey(apiKey) {
|
|
2899
|
+
return apiKey && apiKey !== LOCAL_NO_API_KEY ? apiKey : void 0;
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2848
2902
|
// src/providers/openai.ts
|
|
2849
2903
|
function toKimiK3Effort(level) {
|
|
2850
2904
|
switch (level) {
|
|
@@ -2889,6 +2943,8 @@ function createClient2(options) {
|
|
|
2889
2943
|
const cached = openaiClientCache.get(cacheKey);
|
|
2890
2944
|
if (cached) return cached;
|
|
2891
2945
|
}
|
|
2946
|
+
const omitAuth = options.provider === "local" && localBearerKey(options.apiKey) === void 0;
|
|
2947
|
+
const defaultHeaders = omitAuth ? { ...options.defaultHeaders, Authorization: null } : options.defaultHeaders;
|
|
2892
2948
|
const client = new OpenAI({
|
|
2893
2949
|
apiKey: options.apiKey,
|
|
2894
2950
|
...options.baseUrl ? { baseURL: options.baseUrl } : {},
|
|
@@ -2898,7 +2954,7 @@ function createClient2(options) {
|
|
|
2898
2954
|
// events). The SDK default of 2 silent retries stacked under it: one 5xx
|
|
2899
2955
|
// cost up to 3 hidden requests plus SDK sleeps before the loop even saw it.
|
|
2900
2956
|
maxRetries: 0,
|
|
2901
|
-
...
|
|
2957
|
+
...defaultHeaders ? { defaultHeaders } : {}
|
|
2902
2958
|
});
|
|
2903
2959
|
if (!options.fetch) {
|
|
2904
2960
|
if (openaiClientCache.size >= 8) {
|
|
@@ -5655,19 +5711,25 @@ providerRegistry.register("local", {
|
|
|
5655
5711
|
}),
|
|
5656
5712
|
// Every supported local server exposes OpenAI-compatible `/v1/embeddings`
|
|
5657
5713
|
// (the model must be an embedding model). None has an input-type parameter.
|
|
5658
|
-
embed: (request) => embedOpenAICompatible(
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5714
|
+
embed: (request) => embedOpenAICompatible(
|
|
5715
|
+
{ ...request, apiKey: localBearerKey(request.apiKey) },
|
|
5716
|
+
{
|
|
5717
|
+
provider: "local",
|
|
5718
|
+
baseUrl: requireLocalBaseUrl(request.baseUrl),
|
|
5719
|
+
wireModel: localWireModelId(request.model)
|
|
5720
|
+
}
|
|
5721
|
+
),
|
|
5663
5722
|
embedBatchSize: LOCAL_EMBED_BATCH_SIZE,
|
|
5664
5723
|
// llama.cpp (`llama-server --rerank`) and vLLM serve `/v1/rerank`; Ollama and
|
|
5665
5724
|
// LM Studio don't, and answer with a 404 ProviderError.
|
|
5666
|
-
rerank: (request) => rerankCohereCompatible(
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5725
|
+
rerank: (request) => rerankCohereCompatible(
|
|
5726
|
+
{ ...request, apiKey: localBearerKey(request.apiKey) },
|
|
5727
|
+
{
|
|
5728
|
+
provider: "local",
|
|
5729
|
+
baseUrl: requireLocalBaseUrl(request.baseUrl),
|
|
5730
|
+
wireModel: localWireModelId(request.model)
|
|
5731
|
+
}
|
|
5732
|
+
)
|
|
5671
5733
|
});
|
|
5672
5734
|
function requireLocalBaseUrl(baseUrl) {
|
|
5673
5735
|
if (!baseUrl) {
|
|
@@ -6041,6 +6103,13 @@ function formatChatError(error) {
|
|
|
6041
6103
|
"Check your connection before trying again."
|
|
6042
6104
|
);
|
|
6043
6105
|
}
|
|
6106
|
+
if (base.provider === "local" && (base.source === "auth" || base.statusCode === 401)) {
|
|
6107
|
+
return present(
|
|
6108
|
+
"auth",
|
|
6109
|
+
"The local server rejected its key",
|
|
6110
|
+
"Check the endpoint's key under Local models in AI Providers settings."
|
|
6111
|
+
);
|
|
6112
|
+
}
|
|
6044
6113
|
if (base.source === "auth" || base.statusCode === 401) {
|
|
6045
6114
|
return present(
|
|
6046
6115
|
"auth",
|
|
@@ -6413,6 +6482,7 @@ export {
|
|
|
6413
6482
|
EventStream,
|
|
6414
6483
|
FAST_MODE_SUFFIX,
|
|
6415
6484
|
GGAIError,
|
|
6485
|
+
LOCAL_NO_API_KEY,
|
|
6416
6486
|
PRECONNECT_INTERVAL_MS,
|
|
6417
6487
|
ProviderError,
|
|
6418
6488
|
REDACTED as REDACTION_MARKER,
|
|
@@ -6435,6 +6505,7 @@ export {
|
|
|
6435
6505
|
isHardBillingMessage,
|
|
6436
6506
|
isUsageLimitError,
|
|
6437
6507
|
isValidToolCallName,
|
|
6508
|
+
localBearerKey,
|
|
6438
6509
|
localWireModelId,
|
|
6439
6510
|
opensTurn,
|
|
6440
6511
|
palsuAssistantMessage,
|