@juspay/neurolink 9.64.0 → 9.65.1
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/CHANGELOG.md +12 -0
- package/README.md +18 -17
- package/dist/adapters/providerImageAdapter.js +29 -1
- package/dist/adapters/replicate/auth.d.ts +19 -0
- package/dist/adapters/replicate/auth.js +32 -0
- package/dist/adapters/replicate/predictionLifecycle.d.ts +46 -0
- package/dist/adapters/replicate/predictionLifecycle.js +283 -0
- package/dist/adapters/video/klingVideoHandler.d.ts +37 -0
- package/dist/adapters/video/klingVideoHandler.js +305 -0
- package/dist/adapters/video/replicateVideoHandler.d.ts +29 -0
- package/dist/adapters/video/replicateVideoHandler.js +157 -0
- package/dist/adapters/video/runwayVideoHandler.d.ts +32 -0
- package/dist/adapters/video/runwayVideoHandler.js +316 -0
- package/dist/adapters/video/vertexVideoHandler.d.ts +19 -1
- package/dist/adapters/video/vertexVideoHandler.js +33 -9
- package/dist/agent/directTools.js +11 -3
- package/dist/autoresearch/runner.js +8 -2
- package/dist/avatar/index.d.ts +13 -0
- package/dist/avatar/index.js +13 -0
- package/dist/avatar/providers/DIDAvatar.d.ts +49 -0
- package/dist/avatar/providers/DIDAvatar.js +501 -0
- package/dist/avatar/providers/HeyGenAvatar.d.ts +30 -0
- package/dist/avatar/providers/HeyGenAvatar.js +337 -0
- package/dist/avatar/providers/ReplicateAvatar.d.ts +36 -0
- package/dist/avatar/providers/ReplicateAvatar.js +267 -0
- package/dist/browser/neurolink.min.js +624 -601
- package/dist/cli/commands/mcp.js +29 -0
- package/dist/cli/commands/proxy.js +24 -5
- package/dist/cli/factories/commandFactory.d.ts +11 -1
- package/dist/cli/factories/commandFactory.js +291 -38
- package/dist/constants/contextWindows.js +101 -0
- package/dist/constants/enums.d.ts +273 -2
- package/dist/constants/enums.js +290 -1
- package/dist/constants/videoErrors.d.ts +4 -0
- package/dist/constants/videoErrors.js +4 -0
- package/dist/core/baseProvider.d.ts +22 -2
- package/dist/core/baseProvider.js +217 -11
- package/dist/core/constants.d.ts +12 -0
- package/dist/core/constants.js +72 -1
- package/dist/evaluation/index.d.ts +2 -0
- package/dist/evaluation/index.js +4 -0
- package/dist/factories/providerFactory.js +7 -1
- package/dist/factories/providerRegistry.js +202 -5
- package/dist/features/ppt/contentPlanner.js +42 -14
- package/dist/index.d.ts +9 -1
- package/dist/index.js +16 -1
- package/dist/lib/adapters/providerImageAdapter.js +29 -1
- package/dist/lib/adapters/replicate/auth.d.ts +19 -0
- package/dist/lib/adapters/replicate/auth.js +33 -0
- package/dist/lib/adapters/replicate/predictionLifecycle.d.ts +46 -0
- package/dist/lib/adapters/replicate/predictionLifecycle.js +284 -0
- package/dist/lib/adapters/video/klingVideoHandler.d.ts +37 -0
- package/dist/lib/adapters/video/klingVideoHandler.js +306 -0
- package/dist/lib/adapters/video/replicateVideoHandler.d.ts +29 -0
- package/dist/lib/adapters/video/replicateVideoHandler.js +158 -0
- package/dist/lib/adapters/video/runwayVideoHandler.d.ts +32 -0
- package/dist/lib/adapters/video/runwayVideoHandler.js +317 -0
- package/dist/lib/adapters/video/vertexVideoHandler.d.ts +19 -1
- package/dist/lib/adapters/video/vertexVideoHandler.js +33 -9
- package/dist/lib/agent/directTools.js +11 -3
- package/dist/lib/autoresearch/runner.js +8 -2
- package/dist/lib/avatar/index.d.ts +13 -0
- package/dist/lib/avatar/index.js +14 -0
- package/dist/lib/avatar/providers/DIDAvatar.d.ts +49 -0
- package/dist/lib/avatar/providers/DIDAvatar.js +502 -0
- package/dist/lib/avatar/providers/HeyGenAvatar.d.ts +30 -0
- package/dist/lib/avatar/providers/HeyGenAvatar.js +338 -0
- package/dist/lib/avatar/providers/ReplicateAvatar.d.ts +36 -0
- package/dist/lib/avatar/providers/ReplicateAvatar.js +268 -0
- package/dist/lib/constants/contextWindows.js +101 -0
- package/dist/lib/constants/enums.d.ts +273 -2
- package/dist/lib/constants/enums.js +290 -1
- package/dist/lib/constants/videoErrors.d.ts +4 -0
- package/dist/lib/constants/videoErrors.js +4 -0
- package/dist/lib/core/baseProvider.d.ts +22 -2
- package/dist/lib/core/baseProvider.js +217 -11
- package/dist/lib/core/constants.d.ts +12 -0
- package/dist/lib/core/constants.js +72 -1
- package/dist/lib/evaluation/index.d.ts +2 -0
- package/dist/lib/evaluation/index.js +4 -0
- package/dist/lib/factories/providerFactory.js +7 -1
- package/dist/lib/factories/providerRegistry.js +202 -5
- package/dist/lib/features/ppt/contentPlanner.js +42 -14
- package/dist/lib/index.d.ts +9 -1
- package/dist/lib/index.js +16 -1
- package/dist/lib/middleware/builtin/lifecycle.js +39 -9
- package/dist/lib/music/index.d.ts +13 -0
- package/dist/lib/music/index.js +14 -0
- package/dist/lib/music/providers/BeatovenMusic.d.ts +31 -0
- package/dist/lib/music/providers/BeatovenMusic.js +334 -0
- package/dist/lib/music/providers/ElevenLabsMusic.d.ts +30 -0
- package/dist/lib/music/providers/ElevenLabsMusic.js +169 -0
- package/dist/lib/music/providers/LyriaMusic.d.ts +29 -0
- package/dist/lib/music/providers/LyriaMusic.js +173 -0
- package/dist/lib/music/providers/ReplicateMusic.d.ts +31 -0
- package/dist/lib/music/providers/ReplicateMusic.js +262 -0
- package/dist/lib/neurolink.d.ts +30 -0
- package/dist/lib/neurolink.js +323 -77
- package/dist/lib/providers/amazonBedrock.d.ts +10 -0
- package/dist/lib/providers/amazonBedrock.js +94 -39
- package/dist/lib/providers/anthropic.js +55 -7
- package/dist/lib/providers/anthropicBaseProvider.js +1 -1
- package/dist/lib/providers/azureOpenai.js +66 -17
- package/dist/lib/providers/cloudflare.d.ts +35 -0
- package/dist/lib/providers/cloudflare.js +174 -0
- package/dist/lib/providers/cohere.d.ts +52 -0
- package/dist/lib/providers/cohere.js +253 -0
- package/dist/lib/providers/deepseek.js +72 -17
- package/dist/lib/providers/fireworks.d.ts +33 -0
- package/dist/lib/providers/fireworks.js +164 -0
- package/dist/lib/providers/googleAiStudio.js +126 -10
- package/dist/lib/providers/googleNativeGemini3.d.ts +26 -6
- package/dist/lib/providers/googleNativeGemini3.js +276 -29
- package/dist/lib/providers/googleVertex.js +639 -181
- package/dist/lib/providers/groq.d.ts +33 -0
- package/dist/lib/providers/groq.js +181 -0
- package/dist/lib/providers/huggingFace.js +9 -8
- package/dist/lib/providers/ideogram.d.ts +34 -0
- package/dist/lib/providers/ideogram.js +184 -0
- package/dist/lib/providers/index.d.ts +13 -0
- package/dist/lib/providers/index.js +13 -0
- package/dist/lib/providers/jina.d.ts +59 -0
- package/dist/lib/providers/jina.js +218 -0
- package/dist/lib/providers/llamaCpp.js +14 -46
- package/dist/lib/providers/lmStudio.js +14 -47
- package/dist/lib/providers/mistral.js +7 -7
- package/dist/lib/providers/nvidiaNim.js +160 -19
- package/dist/lib/providers/ollama.js +7 -7
- package/dist/lib/providers/openAI.d.ts +22 -1
- package/dist/lib/providers/openAI.js +181 -0
- package/dist/lib/providers/openRouter.js +35 -23
- package/dist/lib/providers/openaiCompatible.js +9 -8
- package/dist/lib/providers/perplexity.d.ts +33 -0
- package/dist/lib/providers/perplexity.js +179 -0
- package/dist/lib/providers/recraft.d.ts +34 -0
- package/dist/lib/providers/recraft.js +197 -0
- package/dist/lib/providers/replicate.d.ts +75 -0
- package/dist/lib/providers/replicate.js +403 -0
- package/dist/lib/providers/stability.d.ts +37 -0
- package/dist/lib/providers/stability.js +191 -0
- package/dist/lib/providers/togetherAi.d.ts +33 -0
- package/dist/lib/providers/togetherAi.js +176 -0
- package/dist/lib/providers/voyage.d.ts +47 -0
- package/dist/lib/providers/voyage.js +177 -0
- package/dist/lib/providers/xai.d.ts +33 -0
- package/dist/lib/providers/xai.js +172 -0
- package/dist/lib/telemetry/index.d.ts +1 -1
- package/dist/lib/telemetry/index.js +1 -1
- package/dist/lib/telemetry/tracers.d.ts +19 -0
- package/dist/lib/telemetry/tracers.js +19 -0
- package/dist/lib/telemetry/withSpan.d.ts +35 -0
- package/dist/lib/telemetry/withSpan.js +103 -0
- package/dist/lib/types/avatar.d.ts +143 -0
- package/dist/lib/types/avatar.js +20 -0
- package/dist/lib/types/cli.d.ts +6 -0
- package/dist/lib/types/conversation.d.ts +16 -0
- package/dist/lib/types/generate.d.ts +62 -5
- package/dist/lib/types/index.d.ts +5 -0
- package/dist/lib/types/index.js +7 -0
- package/dist/lib/types/middleware.d.ts +27 -0
- package/dist/lib/types/multimodal.d.ts +35 -2
- package/dist/lib/types/music.d.ts +165 -0
- package/dist/lib/types/music.js +21 -0
- package/dist/lib/types/providers.d.ts +144 -1
- package/dist/lib/types/replicate.d.ts +67 -0
- package/dist/lib/types/replicate.js +10 -0
- package/dist/lib/types/safeFetch.d.ts +15 -0
- package/dist/lib/types/safeFetch.js +7 -0
- package/dist/lib/types/stream.d.ts +2 -1
- package/dist/lib/types/tools.d.ts +13 -0
- package/dist/lib/types/video.d.ts +89 -0
- package/dist/lib/types/video.js +15 -0
- package/dist/lib/utils/avatarProcessor.d.ts +68 -0
- package/dist/lib/utils/avatarProcessor.js +172 -0
- package/dist/lib/utils/cloneOptions.d.ts +36 -0
- package/dist/lib/utils/cloneOptions.js +62 -0
- package/dist/lib/utils/lifecycleCallbacks.d.ts +51 -8
- package/dist/lib/utils/lifecycleCallbacks.js +82 -26
- package/dist/lib/utils/lifecycleTimeout.d.ts +25 -0
- package/dist/lib/utils/lifecycleTimeout.js +39 -0
- package/dist/lib/utils/logSanitize.d.ts +49 -0
- package/dist/lib/utils/logSanitize.js +170 -0
- package/dist/lib/utils/loggingFetch.d.ts +29 -0
- package/dist/lib/utils/loggingFetch.js +60 -0
- package/dist/lib/utils/messageBuilder.js +43 -25
- package/dist/lib/utils/modelChoices.js +236 -3
- package/dist/lib/utils/musicProcessor.d.ts +67 -0
- package/dist/lib/utils/musicProcessor.js +189 -0
- package/dist/lib/utils/optionsConversion.js +3 -2
- package/dist/lib/utils/parameterValidation.js +14 -4
- package/dist/lib/utils/pricing.js +193 -0
- package/dist/lib/utils/providerConfig.d.ts +55 -0
- package/dist/lib/utils/providerConfig.js +224 -0
- package/dist/lib/utils/safeFetch.d.ts +26 -0
- package/dist/lib/utils/safeFetch.js +83 -0
- package/dist/lib/utils/sizeGuard.d.ts +34 -0
- package/dist/lib/utils/sizeGuard.js +45 -0
- package/dist/lib/utils/ssrfGuard.d.ts +52 -0
- package/dist/lib/utils/ssrfGuard.js +411 -0
- package/dist/lib/utils/videoProcessor.d.ts +60 -0
- package/dist/lib/utils/videoProcessor.js +201 -0
- package/dist/lib/voice/providers/FishAudioTTS.d.ts +27 -0
- package/dist/lib/voice/providers/FishAudioTTS.js +183 -0
- package/dist/lib/workflow/core/ensembleExecutor.js +26 -9
- package/dist/middleware/builtin/lifecycle.js +39 -9
- package/dist/music/index.d.ts +13 -0
- package/dist/music/index.js +13 -0
- package/dist/music/providers/BeatovenMusic.d.ts +31 -0
- package/dist/music/providers/BeatovenMusic.js +333 -0
- package/dist/music/providers/ElevenLabsMusic.d.ts +30 -0
- package/dist/music/providers/ElevenLabsMusic.js +168 -0
- package/dist/music/providers/LyriaMusic.d.ts +29 -0
- package/dist/music/providers/LyriaMusic.js +172 -0
- package/dist/music/providers/ReplicateMusic.d.ts +31 -0
- package/dist/music/providers/ReplicateMusic.js +261 -0
- package/dist/neurolink.d.ts +30 -0
- package/dist/neurolink.js +323 -77
- package/dist/providers/amazonBedrock.d.ts +10 -0
- package/dist/providers/amazonBedrock.js +94 -39
- package/dist/providers/anthropic.js +55 -7
- package/dist/providers/anthropicBaseProvider.js +1 -1
- package/dist/providers/azureOpenai.js +66 -17
- package/dist/providers/cloudflare.d.ts +35 -0
- package/dist/providers/cloudflare.js +173 -0
- package/dist/providers/cohere.d.ts +52 -0
- package/dist/providers/cohere.js +252 -0
- package/dist/providers/deepseek.js +72 -17
- package/dist/providers/fireworks.d.ts +33 -0
- package/dist/providers/fireworks.js +163 -0
- package/dist/providers/googleAiStudio.js +126 -10
- package/dist/providers/googleNativeGemini3.d.ts +26 -6
- package/dist/providers/googleNativeGemini3.js +276 -29
- package/dist/providers/googleVertex.js +639 -181
- package/dist/providers/groq.d.ts +33 -0
- package/dist/providers/groq.js +180 -0
- package/dist/providers/huggingFace.js +9 -8
- package/dist/providers/ideogram.d.ts +34 -0
- package/dist/providers/ideogram.js +183 -0
- package/dist/providers/index.d.ts +13 -0
- package/dist/providers/index.js +13 -0
- package/dist/providers/jina.d.ts +59 -0
- package/dist/providers/jina.js +217 -0
- package/dist/providers/llamaCpp.js +14 -46
- package/dist/providers/lmStudio.js +14 -47
- package/dist/providers/mistral.js +7 -7
- package/dist/providers/nvidiaNim.js +160 -19
- package/dist/providers/ollama.js +7 -7
- package/dist/providers/openAI.d.ts +22 -1
- package/dist/providers/openAI.js +181 -0
- package/dist/providers/openRouter.js +35 -23
- package/dist/providers/openaiCompatible.js +9 -8
- package/dist/providers/perplexity.d.ts +33 -0
- package/dist/providers/perplexity.js +178 -0
- package/dist/providers/recraft.d.ts +34 -0
- package/dist/providers/recraft.js +196 -0
- package/dist/providers/replicate.d.ts +75 -0
- package/dist/providers/replicate.js +402 -0
- package/dist/providers/stability.d.ts +37 -0
- package/dist/providers/stability.js +190 -0
- package/dist/providers/togetherAi.d.ts +33 -0
- package/dist/providers/togetherAi.js +175 -0
- package/dist/providers/voyage.d.ts +47 -0
- package/dist/providers/voyage.js +176 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.js +171 -0
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/tracers.d.ts +19 -0
- package/dist/telemetry/tracers.js +19 -0
- package/dist/telemetry/withSpan.d.ts +35 -0
- package/dist/telemetry/withSpan.js +103 -0
- package/dist/types/avatar.d.ts +143 -0
- package/dist/types/avatar.js +19 -0
- package/dist/types/cli.d.ts +6 -0
- package/dist/types/conversation.d.ts +16 -0
- package/dist/types/generate.d.ts +62 -5
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +7 -0
- package/dist/types/middleware.d.ts +27 -0
- package/dist/types/multimodal.d.ts +35 -2
- package/dist/types/music.d.ts +165 -0
- package/dist/types/music.js +20 -0
- package/dist/types/providers.d.ts +144 -1
- package/dist/types/replicate.d.ts +67 -0
- package/dist/types/replicate.js +9 -0
- package/dist/types/safeFetch.d.ts +15 -0
- package/dist/types/safeFetch.js +6 -0
- package/dist/types/stream.d.ts +2 -1
- package/dist/types/tools.d.ts +13 -0
- package/dist/types/video.d.ts +89 -0
- package/dist/types/video.js +14 -0
- package/dist/utils/avatarProcessor.d.ts +68 -0
- package/dist/utils/avatarProcessor.js +171 -0
- package/dist/utils/cloneOptions.d.ts +36 -0
- package/dist/utils/cloneOptions.js +61 -0
- package/dist/utils/lifecycleCallbacks.d.ts +51 -8
- package/dist/utils/lifecycleCallbacks.js +82 -26
- package/dist/utils/lifecycleTimeout.d.ts +25 -0
- package/dist/utils/lifecycleTimeout.js +38 -0
- package/dist/utils/logSanitize.d.ts +49 -0
- package/dist/utils/logSanitize.js +169 -0
- package/dist/utils/loggingFetch.d.ts +29 -0
- package/dist/utils/loggingFetch.js +59 -0
- package/dist/utils/messageBuilder.js +43 -25
- package/dist/utils/modelChoices.js +236 -3
- package/dist/utils/musicProcessor.d.ts +67 -0
- package/dist/utils/musicProcessor.js +188 -0
- package/dist/utils/optionsConversion.js +3 -2
- package/dist/utils/parameterValidation.js +14 -4
- package/dist/utils/pricing.js +193 -0
- package/dist/utils/providerConfig.d.ts +55 -0
- package/dist/utils/providerConfig.js +224 -0
- package/dist/utils/safeFetch.d.ts +26 -0
- package/dist/utils/safeFetch.js +82 -0
- package/dist/utils/sizeGuard.d.ts +34 -0
- package/dist/utils/sizeGuard.js +44 -0
- package/dist/utils/ssrfGuard.d.ts +52 -0
- package/dist/utils/ssrfGuard.js +410 -0
- package/dist/utils/videoProcessor.d.ts +60 -0
- package/dist/utils/videoProcessor.js +200 -0
- package/dist/voice/providers/FishAudioTTS.d.ts +27 -0
- package/dist/voice/providers/FishAudioTTS.js +182 -0
- package/dist/workflow/core/ensembleExecutor.js +26 -9
- package/package.json +32 -5
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
2
|
+
import { stepCountIs, streamText } from "ai";
|
|
3
|
+
import { FireworksModels } from "../constants/enums.js";
|
|
4
|
+
import { BaseProvider } from "../core/baseProvider.js";
|
|
5
|
+
import { DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
6
|
+
import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
|
|
7
|
+
import { isNeuroLink } from "../neurolink.js";
|
|
8
|
+
import { createLoggingFetch } from "../utils/loggingFetch.js";
|
|
9
|
+
import { tracers, ATTR, withClientStreamSpan } from "../telemetry/index.js";
|
|
10
|
+
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "../types/index.js";
|
|
11
|
+
import { logger } from "../utils/logger.js";
|
|
12
|
+
import { createFireworksConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
|
|
13
|
+
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
14
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
15
|
+
import { resolveToolChoice } from "../utils/toolChoice.js";
|
|
16
|
+
import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
|
|
17
|
+
const FIREWORKS_DEFAULT_BASE_URL = "https://api.fireworks.ai/inference/v1";
|
|
18
|
+
const getFireworksApiKey = () => validateApiKey(createFireworksConfig());
|
|
19
|
+
const getDefaultFireworksModel = () => getProviderModel("FIREWORKS_MODEL", FireworksModels.DEEPSEEK_V4_PRO);
|
|
20
|
+
/**
|
|
21
|
+
* Fireworks AI Provider
|
|
22
|
+
*
|
|
23
|
+
* Hosted open-model serving at api.fireworks.ai/inference/v1
|
|
24
|
+
* (OpenAI-compatible). Best for low-latency at scale on Llama / Mixtral /
|
|
25
|
+
* Qwen / DeepSeek.
|
|
26
|
+
*
|
|
27
|
+
* @see https://docs.fireworks.ai/api-reference/introduction
|
|
28
|
+
*/
|
|
29
|
+
export class FireworksProvider extends BaseProvider {
|
|
30
|
+
model;
|
|
31
|
+
apiKey;
|
|
32
|
+
baseURL;
|
|
33
|
+
constructor(modelName, sdk, _region, credentials) {
|
|
34
|
+
const validatedNeurolink = isNeuroLink(sdk) ? sdk : undefined;
|
|
35
|
+
super(modelName, "fireworks", validatedNeurolink);
|
|
36
|
+
const overrideApiKey = credentials?.apiKey?.trim();
|
|
37
|
+
this.apiKey =
|
|
38
|
+
overrideApiKey && overrideApiKey.length > 0
|
|
39
|
+
? overrideApiKey
|
|
40
|
+
: getFireworksApiKey();
|
|
41
|
+
this.baseURL =
|
|
42
|
+
credentials?.baseURL ??
|
|
43
|
+
process.env.FIREWORKS_BASE_URL ??
|
|
44
|
+
FIREWORKS_DEFAULT_BASE_URL;
|
|
45
|
+
const fireworks = createOpenAI({
|
|
46
|
+
apiKey: this.apiKey,
|
|
47
|
+
baseURL: this.baseURL,
|
|
48
|
+
fetch: createLoggingFetch("fireworks"),
|
|
49
|
+
});
|
|
50
|
+
this.model = fireworks.chat(this.modelName);
|
|
51
|
+
logger.debug("Fireworks Provider initialized", {
|
|
52
|
+
modelName: this.modelName,
|
|
53
|
+
providerName: this.providerName,
|
|
54
|
+
baseURL: this.baseURL,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async executeStream(options, _analysisSchema) {
|
|
58
|
+
return withClientStreamSpan({
|
|
59
|
+
name: "neurolink.provider.stream",
|
|
60
|
+
tracer: tracers.provider,
|
|
61
|
+
attributes: {
|
|
62
|
+
[ATTR.GEN_AI_SYSTEM]: "fireworks",
|
|
63
|
+
[ATTR.GEN_AI_MODEL]: this.modelName,
|
|
64
|
+
[ATTR.GEN_AI_OPERATION]: "stream",
|
|
65
|
+
[ATTR.NL_STREAM_MODE]: true,
|
|
66
|
+
},
|
|
67
|
+
}, async () => this.executeStreamInner(options), (r) => r.stream, (r, wrapped) => ({ ...r, stream: wrapped }));
|
|
68
|
+
}
|
|
69
|
+
async executeStreamInner(options) {
|
|
70
|
+
this.validateStreamOptions(options);
|
|
71
|
+
const startTime = Date.now();
|
|
72
|
+
const timeout = this.getTimeout(options);
|
|
73
|
+
const timeoutController = createTimeoutController(timeout, this.providerName, "stream");
|
|
74
|
+
try {
|
|
75
|
+
const shouldUseTools = !options.disableTools && this.supportsTools();
|
|
76
|
+
const tools = shouldUseTools
|
|
77
|
+
? options.tools || (await this.getAllTools())
|
|
78
|
+
: {};
|
|
79
|
+
const messages = await this.buildMessagesForStream(options);
|
|
80
|
+
const model = await this.getAISDKModelWithMiddleware(options);
|
|
81
|
+
const result = await streamText({
|
|
82
|
+
model,
|
|
83
|
+
messages,
|
|
84
|
+
temperature: options.temperature,
|
|
85
|
+
maxOutputTokens: options.maxTokens,
|
|
86
|
+
tools,
|
|
87
|
+
stopWhen: stepCountIs(options.maxSteps || DEFAULT_MAX_STEPS),
|
|
88
|
+
toolChoice: resolveToolChoice(options, tools, shouldUseTools),
|
|
89
|
+
abortSignal: composeAbortSignals(options.abortSignal, timeoutController?.controller.signal),
|
|
90
|
+
experimental_telemetry: this.telemetryHandler.getTelemetryConfig(options),
|
|
91
|
+
experimental_repairToolCall: this.getToolCallRepairFn(options),
|
|
92
|
+
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
93
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResults);
|
|
94
|
+
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
95
|
+
logger.warn("[FireworksProvider] Failed to store tool executions", {
|
|
96
|
+
provider: this.providerName,
|
|
97
|
+
error: error instanceof Error ? error.message : String(error),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
timeoutController?.cleanup();
|
|
103
|
+
const transformedStream = this.createTextStream(result);
|
|
104
|
+
const analyticsPromise = streamAnalyticsCollector.createAnalytics(this.providerName, this.modelName, toAnalyticsStreamResult(result), Date.now() - startTime, {
|
|
105
|
+
requestId: `fireworks-stream-${Date.now()}`,
|
|
106
|
+
streamingMode: true,
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
stream: transformedStream,
|
|
110
|
+
provider: this.providerName,
|
|
111
|
+
model: this.modelName,
|
|
112
|
+
analytics: analyticsPromise,
|
|
113
|
+
metadata: { startTime, streamId: `fireworks-${Date.now()}` },
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
timeoutController?.cleanup();
|
|
118
|
+
throw this.handleProviderError(error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
getProviderName() {
|
|
122
|
+
return this.providerName;
|
|
123
|
+
}
|
|
124
|
+
getDefaultModel() {
|
|
125
|
+
return getDefaultFireworksModel();
|
|
126
|
+
}
|
|
127
|
+
getAISDKModel() {
|
|
128
|
+
return this.model;
|
|
129
|
+
}
|
|
130
|
+
formatProviderError(error) {
|
|
131
|
+
if (error instanceof TimeoutError) {
|
|
132
|
+
return new NetworkError(`Request timed out: ${error.message}`, "fireworks");
|
|
133
|
+
}
|
|
134
|
+
const errorRecord = error;
|
|
135
|
+
const message = typeof errorRecord?.message === "string"
|
|
136
|
+
? errorRecord.message
|
|
137
|
+
: "Unknown error";
|
|
138
|
+
if (message.includes("Invalid API key") ||
|
|
139
|
+
message.includes("Authentication") ||
|
|
140
|
+
message.includes("401")) {
|
|
141
|
+
return new AuthenticationError("Invalid Fireworks API key. Get one at https://fireworks.ai/account/api-keys", "fireworks");
|
|
142
|
+
}
|
|
143
|
+
if (message.includes("rate limit") || message.includes("429")) {
|
|
144
|
+
return new RateLimitError("Fireworks rate limit exceeded. Back off and retry.", "fireworks");
|
|
145
|
+
}
|
|
146
|
+
if (message.includes("model_not_found") || message.includes("404")) {
|
|
147
|
+
return new InvalidModelError(`Fireworks model '${this.modelName}' not found. Browse https://fireworks.ai/models`, "fireworks");
|
|
148
|
+
}
|
|
149
|
+
return new ProviderError(`Fireworks error: ${message}`, "fireworks");
|
|
150
|
+
}
|
|
151
|
+
async validateConfiguration() {
|
|
152
|
+
return typeof this.apiKey === "string" && this.apiKey.trim().length > 0;
|
|
153
|
+
}
|
|
154
|
+
getConfiguration() {
|
|
155
|
+
return {
|
|
156
|
+
provider: this.providerName,
|
|
157
|
+
model: this.modelName,
|
|
158
|
+
defaultModel: getDefaultFireworksModel(),
|
|
159
|
+
baseURL: this.baseURL,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export default FireworksProvider;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ErrorCategory, ErrorSeverity, GoogleAIModels, } from "../constants/enums.js";
|
|
2
2
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
3
|
-
import { IMAGE_GENERATION_MODELS } from "../core/constants.js";
|
|
3
|
+
import { IMAGE_GENERATION_MODELS, TOOL_STORAGE_TIMEOUT_MS, } from "../core/constants.js";
|
|
4
4
|
import { processUnifiedFilesArray } from "../utils/messageBuilder.js";
|
|
5
|
-
import { ATTR, tracers, withClientSpan } from "../telemetry/index.js";
|
|
5
|
+
import { ATTR, tracers, withClientSpan, withClientStreamSpan, withSpan, } from "../telemetry/index.js";
|
|
6
6
|
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "../types/index.js";
|
|
7
7
|
import { ERROR_CODES, NeuroLinkError } from "../utils/errorHandling.js";
|
|
8
8
|
import { logger } from "../utils/logger.js";
|
|
9
9
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
10
|
+
import { withTimeout } from "../utils/async/index.js";
|
|
10
11
|
import { estimateTokens } from "../utils/tokenEstimation.js";
|
|
11
|
-
import {
|
|
12
|
+
import { transformToolExecutions } from "../utils/transformationUtils.js";
|
|
13
|
+
import { buildGeminiResponseSchema, buildNativeConfig, buildNativeToolDeclarations, collectStreamChunks, collectStreamChunksIncremental, computeMaxSteps, createTextChannel, buildUserPartsWithMultimodal, executeNativeToolCalls, extractTextFromParts, extractThoughtSignature, handleMaxStepsTermination, prependConversationMessages, pushModelResponseToHistory, } from "./googleNativeGemini3.js";
|
|
12
14
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
13
15
|
// Google AI Live API types now imported from ../types/providerSpecific.js
|
|
14
16
|
// Import proper types for multimodal message handling
|
|
@@ -480,7 +482,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
480
482
|
*/
|
|
481
483
|
async executeNativeGemini3Stream(options) {
|
|
482
484
|
const modelName = options.model || this.modelName;
|
|
483
|
-
return
|
|
485
|
+
return withClientStreamSpan({
|
|
484
486
|
name: "neurolink.provider.stream",
|
|
485
487
|
tracer: tracers.provider,
|
|
486
488
|
attributes: {
|
|
@@ -520,12 +522,14 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
520
522
|
// Convert tools
|
|
521
523
|
let toolsConfig;
|
|
522
524
|
let executeMap = new Map();
|
|
525
|
+
let originalNameMap = new Map();
|
|
523
526
|
if (options.tools &&
|
|
524
527
|
Object.keys(options.tools).length > 0 &&
|
|
525
528
|
!options.disableTools) {
|
|
526
529
|
const result = buildNativeToolDeclarations(options.tools);
|
|
527
530
|
toolsConfig = result.toolsConfig;
|
|
528
531
|
executeMap = result.executeMap;
|
|
532
|
+
originalNameMap = result.originalNameMap;
|
|
529
533
|
logger.debug("[GoogleAIStudio] Converted tools for native SDK", {
|
|
530
534
|
toolCount: toolsConfig[0].functionDeclarations.length,
|
|
531
535
|
toolNames: toolsConfig[0].functionDeclarations.map((t) => t.name),
|
|
@@ -554,6 +558,10 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
554
558
|
const channel = createTextChannel();
|
|
555
559
|
// Shared mutable state updated by the background agentic loop.
|
|
556
560
|
const allToolCalls = [];
|
|
561
|
+
// Mirror the Vertex Gemini stream path: track tool executions so
|
|
562
|
+
// the storage hook can persist real outputs and StreamResult can
|
|
563
|
+
// surface toolsUsed/toolExecutions for tool-bearing turns.
|
|
564
|
+
const toolExecutions = [];
|
|
557
565
|
// analyticsResolvers lets the background loop settle the analytics
|
|
558
566
|
// promise once token counts are known (after the loop completes).
|
|
559
567
|
let analyticsResolve;
|
|
@@ -624,7 +632,40 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
624
632
|
logger.debug(`[GoogleAIStudio] Executing ${chunkResult.stepFunctionCalls.length} function calls`);
|
|
625
633
|
// Add model response with ALL parts (including thoughtSignature) to history
|
|
626
634
|
pushModelResponseToHistory(currentContents, chunkResult.rawResponseParts, chunkResult.stepFunctionCalls);
|
|
627
|
-
const
|
|
635
|
+
const toolCallsBefore = allToolCalls.length;
|
|
636
|
+
const toolExecsBefore = toolExecutions.length;
|
|
637
|
+
const functionResponses = await executeNativeToolCalls("[GoogleAIStudio]", chunkResult.stepFunctionCalls, executeMap, failedTools, allToolCalls, {
|
|
638
|
+
abortSignal: composedSignal,
|
|
639
|
+
originalNameMap,
|
|
640
|
+
toolExecutions,
|
|
641
|
+
});
|
|
642
|
+
// Persist this step's tool calls/results into conversation
|
|
643
|
+
// memory. Without this, tool_call / tool_result rows never
|
|
644
|
+
// reach Redis and the chat-history UI loses every tool
|
|
645
|
+
// invocation.
|
|
646
|
+
const stepToolCalls = allToolCalls.slice(toolCallsBefore);
|
|
647
|
+
const stepToolExecs = toolExecutions.slice(toolExecsBefore);
|
|
648
|
+
if (stepToolCalls.length > 0 || stepToolExecs.length > 0) {
|
|
649
|
+
const stepThoughtSig = extractThoughtSignature(chunkResult.rawResponseParts);
|
|
650
|
+
withTimeout(this.handleToolExecutionStorage(stepToolCalls.map((tc, i) => ({
|
|
651
|
+
toolName: tc.toolName,
|
|
652
|
+
args: tc.args,
|
|
653
|
+
...(i === 0 && stepThoughtSig
|
|
654
|
+
? { thoughtSignature: stepThoughtSig }
|
|
655
|
+
: {}),
|
|
656
|
+
stepIndex: step,
|
|
657
|
+
})), stepToolExecs.map((te) => ({
|
|
658
|
+
toolName: te.name,
|
|
659
|
+
output: te.output,
|
|
660
|
+
stepIndex: step,
|
|
661
|
+
})), options, new Date()), TOOL_STORAGE_TIMEOUT_MS, "tool storage write timed out").catch((error) => {
|
|
662
|
+
logger.warn("[GoogleAIStudio] Failed to store native tool executions", {
|
|
663
|
+
error: error instanceof Error
|
|
664
|
+
? error.message
|
|
665
|
+
: String(error),
|
|
666
|
+
});
|
|
667
|
+
});
|
|
668
|
+
}
|
|
628
669
|
// Add function responses to history — the @google/genai SDK
|
|
629
670
|
// only accepts "user" and "model" as valid roles in contents.
|
|
630
671
|
// Function/tool responses must use role: "user" (matching the
|
|
@@ -681,7 +722,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
681
722
|
// Suppress unhandled-rejection warnings on loopPromise — errors are
|
|
682
723
|
// forwarded to the channel and will surface when the caller iterates.
|
|
683
724
|
loopPromise.catch(() => undefined);
|
|
684
|
-
|
|
725
|
+
const result = {
|
|
685
726
|
stream: channel.iterable,
|
|
686
727
|
provider: this.providerName,
|
|
687
728
|
model: modelName,
|
|
@@ -689,11 +730,25 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
689
730
|
analytics: analyticsPromise,
|
|
690
731
|
metadata,
|
|
691
732
|
};
|
|
733
|
+
// Surface tools-used + executions via getters so they resolve at
|
|
734
|
+
// access time, after the background loop has populated the live
|
|
735
|
+
// arrays. Same lazy pattern used for `structuredOutput` elsewhere.
|
|
736
|
+
Object.defineProperty(result, "toolsUsed", {
|
|
737
|
+
enumerable: true,
|
|
738
|
+
configurable: true,
|
|
739
|
+
get: () => allToolCalls.map((tc) => tc.toolName),
|
|
740
|
+
});
|
|
741
|
+
Object.defineProperty(result, "toolExecutions", {
|
|
742
|
+
enumerable: true,
|
|
743
|
+
configurable: true,
|
|
744
|
+
get: () => transformToolExecutions(toolExecutions),
|
|
745
|
+
});
|
|
746
|
+
return result;
|
|
692
747
|
}
|
|
693
748
|
finally {
|
|
694
749
|
// Timeout controller cleanup is managed inside the background loop
|
|
695
750
|
}
|
|
696
|
-
});
|
|
751
|
+
}, (r) => r.stream, (r, wrapped) => ({ ...r, stream: wrapped }));
|
|
697
752
|
}
|
|
698
753
|
/**
|
|
699
754
|
* Execute generate using native @google/genai SDK for Gemini 3 models
|
|
@@ -742,6 +797,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
742
797
|
// Convert tools (a0269210: trust options.tools — already merged + filtered upstream)
|
|
743
798
|
let toolsConfig;
|
|
744
799
|
let executeMap = new Map();
|
|
800
|
+
let originalNameMap = new Map();
|
|
745
801
|
const shouldUseTools = !options.disableTools;
|
|
746
802
|
if (shouldUseTools) {
|
|
747
803
|
const tools = options.tools || {};
|
|
@@ -749,6 +805,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
749
805
|
const result = buildNativeToolDeclarations(tools);
|
|
750
806
|
toolsConfig = result.toolsConfig;
|
|
751
807
|
executeMap = result.executeMap;
|
|
808
|
+
originalNameMap = result.originalNameMap;
|
|
752
809
|
logger.debug("[GoogleAIStudio] Converted tools for native SDK generate", {
|
|
753
810
|
toolCount: toolsConfig[0].functionDeclarations.length,
|
|
754
811
|
toolNames: toolsConfig[0].functionDeclarations.map((t) => t.name),
|
|
@@ -817,7 +874,35 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
817
874
|
// Add model response with ALL parts (including thoughtSignature) to history
|
|
818
875
|
// This is critical for Gemini 3 - it requires thought signatures in subsequent turns
|
|
819
876
|
pushModelResponseToHistory(currentContents, chunkResult.rawResponseParts, chunkResult.stepFunctionCalls);
|
|
820
|
-
const
|
|
877
|
+
const toolCallsBefore = allToolCalls.length;
|
|
878
|
+
const toolExecsBefore = toolExecutions.length;
|
|
879
|
+
const functionResponses = await executeNativeToolCalls("[GoogleAIStudio]", chunkResult.stepFunctionCalls, executeMap, failedTools, allToolCalls, {
|
|
880
|
+
toolExecutions,
|
|
881
|
+
abortSignal: composedSignal,
|
|
882
|
+
originalNameMap,
|
|
883
|
+
});
|
|
884
|
+
// Persist this step's tool calls/results into conversation memory.
|
|
885
|
+
const stepToolCalls = allToolCalls.slice(toolCallsBefore);
|
|
886
|
+
const stepToolExecs = toolExecutions.slice(toolExecsBefore);
|
|
887
|
+
if (stepToolCalls.length > 0 || stepToolExecs.length > 0) {
|
|
888
|
+
const stepThoughtSig = extractThoughtSignature(chunkResult.rawResponseParts);
|
|
889
|
+
withTimeout(this.handleToolExecutionStorage(stepToolCalls.map((tc, i) => ({
|
|
890
|
+
toolName: tc.toolName,
|
|
891
|
+
args: tc.args,
|
|
892
|
+
...(i === 0 && stepThoughtSig
|
|
893
|
+
? { thoughtSignature: stepThoughtSig }
|
|
894
|
+
: {}),
|
|
895
|
+
stepIndex: step,
|
|
896
|
+
})), stepToolExecs.map((te) => ({
|
|
897
|
+
toolName: te.name,
|
|
898
|
+
output: te.output,
|
|
899
|
+
stepIndex: step,
|
|
900
|
+
})), options, new Date()), TOOL_STORAGE_TIMEOUT_MS, "tool storage write timed out").catch((error) => {
|
|
901
|
+
logger.warn("[GoogleAIStudio] Failed to store native generate tool executions", {
|
|
902
|
+
error: error instanceof Error ? error.message : String(error),
|
|
903
|
+
});
|
|
904
|
+
});
|
|
905
|
+
}
|
|
821
906
|
// Add function responses to history — the @google/genai SDK
|
|
822
907
|
// only accepts "user" and "model" as valid roles in contents.
|
|
823
908
|
// Function/tool responses must use role: "user" (matching the
|
|
@@ -853,7 +938,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
853
938
|
},
|
|
854
939
|
responseTime,
|
|
855
940
|
toolsUsed: allToolCalls.map((tc) => tc.toolName),
|
|
856
|
-
toolExecutions: toolExecutions,
|
|
941
|
+
toolExecutions: transformToolExecutions(toolExecutions),
|
|
857
942
|
enhancedWithTools: allToolCalls.length > 0,
|
|
858
943
|
};
|
|
859
944
|
return this.enhanceResult(baseResult, options, startTime);
|
|
@@ -885,6 +970,13 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
885
970
|
logger.info("[GoogleAIStudio] Routing image generation model to executeImageGeneration", { model: modelName });
|
|
886
971
|
return this.executeImageGeneration(options);
|
|
887
972
|
}
|
|
973
|
+
// TTS direct-synthesis mode: synthesise the input text directly (no LLM
|
|
974
|
+
// call). BaseProvider.runGenerateInActiveContext does the same dispatch
|
|
975
|
+
// — replicated here because AI Studio's override bypasses that path.
|
|
976
|
+
if (options.tts?.enabled && !options.tts?.useAiResponse) {
|
|
977
|
+
logger.info("[GoogleAIStudio] Routing TTS direct-synthesis to handleDirectTTSSynthesis", { model: modelName });
|
|
978
|
+
return this.handleDirectTTSSynthesis(options, Date.now());
|
|
979
|
+
}
|
|
888
980
|
// Process the unified `input.files` array before routing to the
|
|
889
981
|
// native SDK. BaseProvider.generate() runs this preprocessing via
|
|
890
982
|
// buildMultimodalMessagesArray, but AI Studio's override skips it,
|
|
@@ -939,7 +1031,23 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
939
1031
|
mergedOptions.prompt ||
|
|
940
1032
|
"";
|
|
941
1033
|
try {
|
|
942
|
-
|
|
1034
|
+
// Wrap in `neurolink.executeGeneration` so the observability span
|
|
1035
|
+
// chain (Test: Generate Span Chain) sees a third inner span on the
|
|
1036
|
+
// native @google/genai path — Pipeline A providers get this from
|
|
1037
|
+
// GenerationHandler.executeGeneration; the native path bypasses
|
|
1038
|
+
// GenerationHandler so we add the span here.
|
|
1039
|
+
let result = await withSpan({
|
|
1040
|
+
name: "neurolink.executeGeneration",
|
|
1041
|
+
tracer: tracers.provider,
|
|
1042
|
+
attributes: {
|
|
1043
|
+
[ATTR.GEN_AI_SYSTEM]: this.providerName,
|
|
1044
|
+
[ATTR.GEN_AI_MODEL]: modelName,
|
|
1045
|
+
"neurolink.path": "native.google-genai",
|
|
1046
|
+
},
|
|
1047
|
+
}, async () => this.executeNativeGemini3Generate(mergedOptions));
|
|
1048
|
+
// Pipe through TTS-of-AI-response when caller asks for it. No-op when
|
|
1049
|
+
// tts is disabled or useAiResponse is false.
|
|
1050
|
+
result = await this.synthesizeAIResponseIfNeeded(result, options);
|
|
943
1051
|
this.emitPipelineBGenerationEvent(modelName, result, generateStartTime, true, undefined, inputPrompt);
|
|
944
1052
|
return result;
|
|
945
1053
|
}
|
|
@@ -962,6 +1070,14 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
962
1070
|
const usage = result?.usage && typeof result.usage === "object"
|
|
963
1071
|
? result.usage
|
|
964
1072
|
: { input: 0, output: 0, total: 0 };
|
|
1073
|
+
// Mark on the result so the SDK-level runStandardGenerateRequest knows
|
|
1074
|
+
// this provider already emitted `generation:end` itself and skips its
|
|
1075
|
+
// own duplicate emission. Without this flag the public event listener
|
|
1076
|
+
// (and the observability test) would see two events per generate call.
|
|
1077
|
+
if (result && typeof result === "object") {
|
|
1078
|
+
result._generationEndEmitted =
|
|
1079
|
+
true;
|
|
1080
|
+
}
|
|
965
1081
|
emitter.emit("generation:end", {
|
|
966
1082
|
provider: this.providerName,
|
|
967
1083
|
responseTime: Date.now() - startTime,
|
|
@@ -9,7 +9,20 @@
|
|
|
9
9
|
* providers so they can share a single implementation.
|
|
10
10
|
*/
|
|
11
11
|
import { type Tool } from "ai";
|
|
12
|
-
import type { ThinkingConfig, CollectedChunkResult, NativeFunctionCall, NativeFunctionResponse, NativeToolDeclarationsResult, NativeToolsConfig, TextChannel, VertexNativePart, GeminiMultimodalInput } from "../types/index.js";
|
|
12
|
+
import type { ThinkingConfig, ChatMessage, CollectedChunkResult, MinimalChatMessage, NativeFunctionCall, NativeFunctionResponse, NativeToolDeclarationsResult, NativeToolsConfig, TextChannel, VertexNativePart, GeminiMultimodalInput } from "../types/index.js";
|
|
13
|
+
export declare function sanitizeForGoogleFunctionName(name: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve a sanitized Gemini tool name to one that is both unique within
|
|
16
|
+
* the current request and at most 128 characters. When the candidate
|
|
17
|
+
* collides with an already-used name we append `_2`, `_3`, … — but
|
|
18
|
+
* reserve room for the suffix by truncating the base first so the
|
|
19
|
+
* resolved name never exceeds Google's `function_declarations[].name`
|
|
20
|
+
* limit.
|
|
21
|
+
*
|
|
22
|
+
* @param base The already-sanitized candidate name.
|
|
23
|
+
* @param isTaken Predicate that returns true if `name` is already used.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveUniqueGoogleFunctionName(base: string, isTaken: (name: string) => boolean): string;
|
|
13
26
|
/**
|
|
14
27
|
* Sanitize a JSON Schema for Gemini's proto-based API.
|
|
15
28
|
*
|
|
@@ -35,6 +48,12 @@ export declare function sanitizeSchemaForGemini(schema: Record<string, unknown>)
|
|
|
35
48
|
export declare function sanitizeToolsForGemini(tools: Record<string, Tool>): {
|
|
36
49
|
tools: Record<string, Tool>;
|
|
37
50
|
dropped: string[];
|
|
51
|
+
/**
|
|
52
|
+
* Reverse map: Google-safe sanitized name → original consumer-supplied
|
|
53
|
+
* name. Lets the calling layer translate tool-call results back so the
|
|
54
|
+
* sanitization stays transport-only (see CodeRabbit thread, PR #1006).
|
|
55
|
+
*/
|
|
56
|
+
originalNameMap: Map<string, string>;
|
|
38
57
|
};
|
|
39
58
|
export declare function normalizeToolsForJsonSchemaProvider(tools: Record<string, Tool>): {
|
|
40
59
|
tools: Record<string, Tool>;
|
|
@@ -128,7 +147,10 @@ export declare function extractTextFromParts(rawResponseParts: unknown[]): strin
|
|
|
128
147
|
* @param executeMap - Map of tool name to execute function
|
|
129
148
|
* @param failedTools - Mutable map tracking per-tool failure counts
|
|
130
149
|
* @param allToolCalls - Mutable array accumulating all tool call records
|
|
131
|
-
* @param options - Optional settings for execution tracking and cancellation
|
|
150
|
+
* @param options - Optional settings for execution tracking and cancellation,
|
|
151
|
+
* plus an `originalNameMap` (Google-safe → consumer-supplied
|
|
152
|
+
* identifier) so the sanitization stays transport-only and
|
|
153
|
+
* consumers see the names they registered.
|
|
132
154
|
* @returns Array of function responses for conversation history
|
|
133
155
|
*/
|
|
134
156
|
export declare function executeNativeToolCalls(logLabel: string, stepFunctionCalls: NativeFunctionCall[], executeMap: Map<string, Tool["execute"]>, failedTools: Map<string, {
|
|
@@ -144,6 +166,7 @@ export declare function executeNativeToolCalls(logLabel: string, stepFunctionCal
|
|
|
144
166
|
output: unknown;
|
|
145
167
|
}>;
|
|
146
168
|
abortSignal?: AbortSignal;
|
|
169
|
+
originalNameMap?: Map<string, string>;
|
|
147
170
|
}): Promise<NativeFunctionResponse[]>;
|
|
148
171
|
/**
|
|
149
172
|
* Handle maxSteps termination by producing a final text when the model
|
|
@@ -195,10 +218,7 @@ export declare function buildGeminiResponseSchema(schema: unknown): Record<strin
|
|
|
195
218
|
export declare function prependConversationMessages(contents: Array<{
|
|
196
219
|
role: string;
|
|
197
220
|
parts: unknown[];
|
|
198
|
-
}>, conversationMessages?: Array<
|
|
199
|
-
role: string;
|
|
200
|
-
content: string;
|
|
201
|
-
}>): void;
|
|
221
|
+
}>, conversationMessages?: Array<ChatMessage | MinimalChatMessage>): void;
|
|
202
222
|
/**
|
|
203
223
|
* Build the `parts` array for the current user turn of a Gemini native
|
|
204
224
|
* `generateContent` request, including inline image + PDF blobs.
|