@kenkaiiii/gg-ai 5.89.0 → 5.90.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.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
@@ -1564,10 +1564,22 @@ function toAnthropicMessages(messages, cacheControl, options) {
1564
1564
  (name) => toolReferences.has(name) && !referencedTools.has(name)
1565
1565
  ) : [];
1566
1566
  if (refs.length === 0) {
1567
+ const content = toAnthropicToolResultContent(result.content);
1568
+ if (result.isError && typeof content !== "string" && content.some((part) => part.type !== "text")) {
1569
+ const text = content.filter((part) => part.type === "text" && part.text !== "");
1570
+ trailing.push({ type: "text", text: `Attachments from tool call ${toolUseId}:` });
1571
+ for (const part of content) if (part.type !== "text") trailing.push(part);
1572
+ return {
1573
+ type: "tool_result",
1574
+ tool_use_id: toolUseId,
1575
+ content: text.length > 0 ? text : "Tool call failed; its attachments follow.",
1576
+ is_error: true
1577
+ };
1578
+ }
1567
1579
  return {
1568
1580
  type: "tool_result",
1569
1581
  tool_use_id: toolUseId,
1570
- content: toAnthropicToolResultContent(result.content),
1582
+ content,
1571
1583
  is_error: result.isError
1572
1584
  };
1573
1585
  }
@@ -1586,7 +1598,8 @@ ${part.text}` } : part
1586
1598
  type: "tool_result",
1587
1599
  tool_use_id: toolUseId,
1588
1600
  content: refs.map((name) => ({ type: "tool_reference", tool_name: name })),
1589
- is_error: result.isError
1601
+ // tool_reference isn't text, so is_error would 400; the error text trails.
1602
+ is_error: void 0
1590
1603
  };
1591
1604
  });
1592
1605
  out.push({
@@ -1609,8 +1622,8 @@ ${part.text}` } : part
1609
1622
  markAnthropicCacheBreakpoint(out, tail, cacheControl);
1610
1623
  } else {
1611
1624
  if (anchor !== void 0) markAnthropicCacheBreakpoint(out, anchor, cacheControl);
1612
- const longRun = isLongToolRun(messages, trajectoryStartIdx);
1613
- markAnthropicCacheBreakpoint(out, tail, longRun ? cacheControl : { type: "ephemeral" });
1625
+ const blocking = calledBlockingTool(messages, trajectoryStartIdx);
1626
+ markAnthropicCacheBreakpoint(out, tail, blocking ? cacheControl : { type: "ephemeral" });
1614
1627
  }
1615
1628
  } else {
1616
1629
  markAnthropicCacheBreakpoint(out, tail, cacheControl);
@@ -1646,19 +1659,13 @@ var BLOCKING_TOOL_NAMES = /* @__PURE__ */ new Set([
1646
1659
  "subagent",
1647
1660
  "ask_user"
1648
1661
  ]);
1649
- var LONG_RUN_ROUNDS = 6;
1650
- function isLongToolRun(messages, trajectoryStartIdx) {
1651
- let rounds = 0;
1662
+ function calledBlockingTool(messages, trajectoryStartIdx) {
1652
1663
  for (let i = Math.max(0, trajectoryStartIdx + 1); i < messages.length; i++) {
1653
1664
  const m = messages[i];
1654
1665
  if (m?.role !== "assistant" || typeof m.content === "string") continue;
1655
- let called = false;
1656
1666
  for (const part of m.content) {
1657
- if (part.type !== "tool_call") continue;
1658
- called = true;
1659
- if (BLOCKING_TOOL_NAMES.has(part.name)) return true;
1667
+ if (part.type === "tool_call" && BLOCKING_TOOL_NAMES.has(part.name)) return true;
1660
1668
  }
1661
- if (called && ++rounds >= LONG_RUN_ROUNDS) return true;
1662
1669
  }
1663
1670
  return false;
1664
1671
  }
@@ -2845,6 +2852,12 @@ function getEnvironment() {
2845
2852
  return globalThis.process?.env;
2846
2853
  }
2847
2854
 
2855
+ // src/local-api-key.ts
2856
+ var LOCAL_NO_API_KEY = "local";
2857
+ function localBearerKey(apiKey) {
2858
+ return apiKey && apiKey !== LOCAL_NO_API_KEY ? apiKey : void 0;
2859
+ }
2860
+
2848
2861
  // src/providers/openai.ts
2849
2862
  function toKimiK3Effort(level) {
2850
2863
  switch (level) {
@@ -2889,6 +2902,8 @@ function createClient2(options) {
2889
2902
  const cached = openaiClientCache.get(cacheKey);
2890
2903
  if (cached) return cached;
2891
2904
  }
2905
+ const omitAuth = options.provider === "local" && localBearerKey(options.apiKey) === void 0;
2906
+ const defaultHeaders = omitAuth ? { ...options.defaultHeaders, Authorization: null } : options.defaultHeaders;
2892
2907
  const client = new OpenAI({
2893
2908
  apiKey: options.apiKey,
2894
2909
  ...options.baseUrl ? { baseURL: options.baseUrl } : {},
@@ -2898,7 +2913,7 @@ function createClient2(options) {
2898
2913
  // events). The SDK default of 2 silent retries stacked under it: one 5xx
2899
2914
  // cost up to 3 hidden requests plus SDK sleeps before the loop even saw it.
2900
2915
  maxRetries: 0,
2901
- ...options.defaultHeaders ? { defaultHeaders: options.defaultHeaders } : {}
2916
+ ...defaultHeaders ? { defaultHeaders } : {}
2902
2917
  });
2903
2918
  if (!options.fetch) {
2904
2919
  if (openaiClientCache.size >= 8) {
@@ -5655,19 +5670,25 @@ providerRegistry.register("local", {
5655
5670
  }),
5656
5671
  // Every supported local server exposes OpenAI-compatible `/v1/embeddings`
5657
5672
  // (the model must be an embedding model). None has an input-type parameter.
5658
- embed: (request) => embedOpenAICompatible(request, {
5659
- provider: "local",
5660
- baseUrl: requireLocalBaseUrl(request.baseUrl),
5661
- wireModel: localWireModelId(request.model)
5662
- }),
5673
+ embed: (request) => embedOpenAICompatible(
5674
+ { ...request, apiKey: localBearerKey(request.apiKey) },
5675
+ {
5676
+ provider: "local",
5677
+ baseUrl: requireLocalBaseUrl(request.baseUrl),
5678
+ wireModel: localWireModelId(request.model)
5679
+ }
5680
+ ),
5663
5681
  embedBatchSize: LOCAL_EMBED_BATCH_SIZE,
5664
5682
  // llama.cpp (`llama-server --rerank`) and vLLM serve `/v1/rerank`; Ollama and
5665
5683
  // LM Studio don't, and answer with a 404 ProviderError.
5666
- rerank: (request) => rerankCohereCompatible(request, {
5667
- provider: "local",
5668
- baseUrl: requireLocalBaseUrl(request.baseUrl),
5669
- wireModel: localWireModelId(request.model)
5670
- })
5684
+ rerank: (request) => rerankCohereCompatible(
5685
+ { ...request, apiKey: localBearerKey(request.apiKey) },
5686
+ {
5687
+ provider: "local",
5688
+ baseUrl: requireLocalBaseUrl(request.baseUrl),
5689
+ wireModel: localWireModelId(request.model)
5690
+ }
5691
+ )
5671
5692
  });
5672
5693
  function requireLocalBaseUrl(baseUrl) {
5673
5694
  if (!baseUrl) {
@@ -6041,6 +6062,13 @@ function formatChatError(error) {
6041
6062
  "Check your connection before trying again."
6042
6063
  );
6043
6064
  }
6065
+ if (base.provider === "local" && (base.source === "auth" || base.statusCode === 401)) {
6066
+ return present(
6067
+ "auth",
6068
+ "The local server rejected its key",
6069
+ "Check the endpoint's key under Local models in AI Providers settings."
6070
+ );
6071
+ }
6044
6072
  if (base.source === "auth" || base.statusCode === 401) {
6045
6073
  return present(
6046
6074
  "auth",
@@ -6413,6 +6441,7 @@ export {
6413
6441
  EventStream,
6414
6442
  FAST_MODE_SUFFIX,
6415
6443
  GGAIError,
6444
+ LOCAL_NO_API_KEY,
6416
6445
  PRECONNECT_INTERVAL_MS,
6417
6446
  ProviderError,
6418
6447
  REDACTED as REDACTION_MARKER,
@@ -6435,6 +6464,7 @@ export {
6435
6464
  isHardBillingMessage,
6436
6465
  isUsageLimitError,
6437
6466
  isValidToolCallName,
6467
+ localBearerKey,
6438
6468
  localWireModelId,
6439
6469
  opensTurn,
6440
6470
  palsuAssistantMessage,