@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,164 @@
|
|
|
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;
|
|
164
|
+
//# sourceMappingURL=fireworks.js.map
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import {} from "ai";
|
|
2
2
|
import { ErrorCategory, ErrorSeverity, GoogleAIModels, } from "../constants/enums.js";
|
|
3
3
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
|
-
import { IMAGE_GENERATION_MODELS } from "../core/constants.js";
|
|
4
|
+
import { IMAGE_GENERATION_MODELS, TOOL_STORAGE_TIMEOUT_MS, } from "../core/constants.js";
|
|
5
5
|
import { processUnifiedFilesArray } from "../utils/messageBuilder.js";
|
|
6
|
-
import { ATTR, tracers, withClientSpan } from "../telemetry/index.js";
|
|
6
|
+
import { ATTR, tracers, withClientSpan, withClientStreamSpan, withSpan, } from "../telemetry/index.js";
|
|
7
7
|
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "../types/index.js";
|
|
8
8
|
import { ERROR_CODES, NeuroLinkError } from "../utils/errorHandling.js";
|
|
9
9
|
import { logger } from "../utils/logger.js";
|
|
10
10
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
11
|
+
import { withTimeout } from "../utils/async/index.js";
|
|
11
12
|
import { estimateTokens } from "../utils/tokenEstimation.js";
|
|
12
|
-
import {
|
|
13
|
+
import { transformToolExecutions } from "../utils/transformationUtils.js";
|
|
14
|
+
import { buildGeminiResponseSchema, buildNativeConfig, buildNativeToolDeclarations, collectStreamChunks, collectStreamChunksIncremental, computeMaxSteps, createTextChannel, buildUserPartsWithMultimodal, executeNativeToolCalls, extractTextFromParts, extractThoughtSignature, handleMaxStepsTermination, prependConversationMessages, pushModelResponseToHistory, } from "./googleNativeGemini3.js";
|
|
13
15
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
14
16
|
// Google AI Live API types now imported from ../types/providerSpecific.js
|
|
15
17
|
// Import proper types for multimodal message handling
|
|
@@ -481,7 +483,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
481
483
|
*/
|
|
482
484
|
async executeNativeGemini3Stream(options) {
|
|
483
485
|
const modelName = options.model || this.modelName;
|
|
484
|
-
return
|
|
486
|
+
return withClientStreamSpan({
|
|
485
487
|
name: "neurolink.provider.stream",
|
|
486
488
|
tracer: tracers.provider,
|
|
487
489
|
attributes: {
|
|
@@ -521,12 +523,14 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
521
523
|
// Convert tools
|
|
522
524
|
let toolsConfig;
|
|
523
525
|
let executeMap = new Map();
|
|
526
|
+
let originalNameMap = new Map();
|
|
524
527
|
if (options.tools &&
|
|
525
528
|
Object.keys(options.tools).length > 0 &&
|
|
526
529
|
!options.disableTools) {
|
|
527
530
|
const result = buildNativeToolDeclarations(options.tools);
|
|
528
531
|
toolsConfig = result.toolsConfig;
|
|
529
532
|
executeMap = result.executeMap;
|
|
533
|
+
originalNameMap = result.originalNameMap;
|
|
530
534
|
logger.debug("[GoogleAIStudio] Converted tools for native SDK", {
|
|
531
535
|
toolCount: toolsConfig[0].functionDeclarations.length,
|
|
532
536
|
toolNames: toolsConfig[0].functionDeclarations.map((t) => t.name),
|
|
@@ -555,6 +559,10 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
555
559
|
const channel = createTextChannel();
|
|
556
560
|
// Shared mutable state updated by the background agentic loop.
|
|
557
561
|
const allToolCalls = [];
|
|
562
|
+
// Mirror the Vertex Gemini stream path: track tool executions so
|
|
563
|
+
// the storage hook can persist real outputs and StreamResult can
|
|
564
|
+
// surface toolsUsed/toolExecutions for tool-bearing turns.
|
|
565
|
+
const toolExecutions = [];
|
|
558
566
|
// analyticsResolvers lets the background loop settle the analytics
|
|
559
567
|
// promise once token counts are known (after the loop completes).
|
|
560
568
|
let analyticsResolve;
|
|
@@ -625,7 +633,40 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
625
633
|
logger.debug(`[GoogleAIStudio] Executing ${chunkResult.stepFunctionCalls.length} function calls`);
|
|
626
634
|
// Add model response with ALL parts (including thoughtSignature) to history
|
|
627
635
|
pushModelResponseToHistory(currentContents, chunkResult.rawResponseParts, chunkResult.stepFunctionCalls);
|
|
628
|
-
const
|
|
636
|
+
const toolCallsBefore = allToolCalls.length;
|
|
637
|
+
const toolExecsBefore = toolExecutions.length;
|
|
638
|
+
const functionResponses = await executeNativeToolCalls("[GoogleAIStudio]", chunkResult.stepFunctionCalls, executeMap, failedTools, allToolCalls, {
|
|
639
|
+
abortSignal: composedSignal,
|
|
640
|
+
originalNameMap,
|
|
641
|
+
toolExecutions,
|
|
642
|
+
});
|
|
643
|
+
// Persist this step's tool calls/results into conversation
|
|
644
|
+
// memory. Without this, tool_call / tool_result rows never
|
|
645
|
+
// reach Redis and the chat-history UI loses every tool
|
|
646
|
+
// invocation.
|
|
647
|
+
const stepToolCalls = allToolCalls.slice(toolCallsBefore);
|
|
648
|
+
const stepToolExecs = toolExecutions.slice(toolExecsBefore);
|
|
649
|
+
if (stepToolCalls.length > 0 || stepToolExecs.length > 0) {
|
|
650
|
+
const stepThoughtSig = extractThoughtSignature(chunkResult.rawResponseParts);
|
|
651
|
+
withTimeout(this.handleToolExecutionStorage(stepToolCalls.map((tc, i) => ({
|
|
652
|
+
toolName: tc.toolName,
|
|
653
|
+
args: tc.args,
|
|
654
|
+
...(i === 0 && stepThoughtSig
|
|
655
|
+
? { thoughtSignature: stepThoughtSig }
|
|
656
|
+
: {}),
|
|
657
|
+
stepIndex: step,
|
|
658
|
+
})), stepToolExecs.map((te) => ({
|
|
659
|
+
toolName: te.name,
|
|
660
|
+
output: te.output,
|
|
661
|
+
stepIndex: step,
|
|
662
|
+
})), options, new Date()), TOOL_STORAGE_TIMEOUT_MS, "tool storage write timed out").catch((error) => {
|
|
663
|
+
logger.warn("[GoogleAIStudio] Failed to store native tool executions", {
|
|
664
|
+
error: error instanceof Error
|
|
665
|
+
? error.message
|
|
666
|
+
: String(error),
|
|
667
|
+
});
|
|
668
|
+
});
|
|
669
|
+
}
|
|
629
670
|
// Add function responses to history — the @google/genai SDK
|
|
630
671
|
// only accepts "user" and "model" as valid roles in contents.
|
|
631
672
|
// Function/tool responses must use role: "user" (matching the
|
|
@@ -682,7 +723,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
682
723
|
// Suppress unhandled-rejection warnings on loopPromise — errors are
|
|
683
724
|
// forwarded to the channel and will surface when the caller iterates.
|
|
684
725
|
loopPromise.catch(() => undefined);
|
|
685
|
-
|
|
726
|
+
const result = {
|
|
686
727
|
stream: channel.iterable,
|
|
687
728
|
provider: this.providerName,
|
|
688
729
|
model: modelName,
|
|
@@ -690,11 +731,25 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
690
731
|
analytics: analyticsPromise,
|
|
691
732
|
metadata,
|
|
692
733
|
};
|
|
734
|
+
// Surface tools-used + executions via getters so they resolve at
|
|
735
|
+
// access time, after the background loop has populated the live
|
|
736
|
+
// arrays. Same lazy pattern used for `structuredOutput` elsewhere.
|
|
737
|
+
Object.defineProperty(result, "toolsUsed", {
|
|
738
|
+
enumerable: true,
|
|
739
|
+
configurable: true,
|
|
740
|
+
get: () => allToolCalls.map((tc) => tc.toolName),
|
|
741
|
+
});
|
|
742
|
+
Object.defineProperty(result, "toolExecutions", {
|
|
743
|
+
enumerable: true,
|
|
744
|
+
configurable: true,
|
|
745
|
+
get: () => transformToolExecutions(toolExecutions),
|
|
746
|
+
});
|
|
747
|
+
return result;
|
|
693
748
|
}
|
|
694
749
|
finally {
|
|
695
750
|
// Timeout controller cleanup is managed inside the background loop
|
|
696
751
|
}
|
|
697
|
-
});
|
|
752
|
+
}, (r) => r.stream, (r, wrapped) => ({ ...r, stream: wrapped }));
|
|
698
753
|
}
|
|
699
754
|
/**
|
|
700
755
|
* Execute generate using native @google/genai SDK for Gemini 3 models
|
|
@@ -743,6 +798,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
743
798
|
// Convert tools (a0269210: trust options.tools — already merged + filtered upstream)
|
|
744
799
|
let toolsConfig;
|
|
745
800
|
let executeMap = new Map();
|
|
801
|
+
let originalNameMap = new Map();
|
|
746
802
|
const shouldUseTools = !options.disableTools;
|
|
747
803
|
if (shouldUseTools) {
|
|
748
804
|
const tools = options.tools || {};
|
|
@@ -750,6 +806,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
750
806
|
const result = buildNativeToolDeclarations(tools);
|
|
751
807
|
toolsConfig = result.toolsConfig;
|
|
752
808
|
executeMap = result.executeMap;
|
|
809
|
+
originalNameMap = result.originalNameMap;
|
|
753
810
|
logger.debug("[GoogleAIStudio] Converted tools for native SDK generate", {
|
|
754
811
|
toolCount: toolsConfig[0].functionDeclarations.length,
|
|
755
812
|
toolNames: toolsConfig[0].functionDeclarations.map((t) => t.name),
|
|
@@ -818,7 +875,35 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
818
875
|
// Add model response with ALL parts (including thoughtSignature) to history
|
|
819
876
|
// This is critical for Gemini 3 - it requires thought signatures in subsequent turns
|
|
820
877
|
pushModelResponseToHistory(currentContents, chunkResult.rawResponseParts, chunkResult.stepFunctionCalls);
|
|
821
|
-
const
|
|
878
|
+
const toolCallsBefore = allToolCalls.length;
|
|
879
|
+
const toolExecsBefore = toolExecutions.length;
|
|
880
|
+
const functionResponses = await executeNativeToolCalls("[GoogleAIStudio]", chunkResult.stepFunctionCalls, executeMap, failedTools, allToolCalls, {
|
|
881
|
+
toolExecutions,
|
|
882
|
+
abortSignal: composedSignal,
|
|
883
|
+
originalNameMap,
|
|
884
|
+
});
|
|
885
|
+
// Persist this step's tool calls/results into conversation memory.
|
|
886
|
+
const stepToolCalls = allToolCalls.slice(toolCallsBefore);
|
|
887
|
+
const stepToolExecs = toolExecutions.slice(toolExecsBefore);
|
|
888
|
+
if (stepToolCalls.length > 0 || stepToolExecs.length > 0) {
|
|
889
|
+
const stepThoughtSig = extractThoughtSignature(chunkResult.rawResponseParts);
|
|
890
|
+
withTimeout(this.handleToolExecutionStorage(stepToolCalls.map((tc, i) => ({
|
|
891
|
+
toolName: tc.toolName,
|
|
892
|
+
args: tc.args,
|
|
893
|
+
...(i === 0 && stepThoughtSig
|
|
894
|
+
? { thoughtSignature: stepThoughtSig }
|
|
895
|
+
: {}),
|
|
896
|
+
stepIndex: step,
|
|
897
|
+
})), stepToolExecs.map((te) => ({
|
|
898
|
+
toolName: te.name,
|
|
899
|
+
output: te.output,
|
|
900
|
+
stepIndex: step,
|
|
901
|
+
})), options, new Date()), TOOL_STORAGE_TIMEOUT_MS, "tool storage write timed out").catch((error) => {
|
|
902
|
+
logger.warn("[GoogleAIStudio] Failed to store native generate tool executions", {
|
|
903
|
+
error: error instanceof Error ? error.message : String(error),
|
|
904
|
+
});
|
|
905
|
+
});
|
|
906
|
+
}
|
|
822
907
|
// Add function responses to history — the @google/genai SDK
|
|
823
908
|
// only accepts "user" and "model" as valid roles in contents.
|
|
824
909
|
// Function/tool responses must use role: "user" (matching the
|
|
@@ -854,7 +939,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
854
939
|
},
|
|
855
940
|
responseTime,
|
|
856
941
|
toolsUsed: allToolCalls.map((tc) => tc.toolName),
|
|
857
|
-
toolExecutions: toolExecutions,
|
|
942
|
+
toolExecutions: transformToolExecutions(toolExecutions),
|
|
858
943
|
enhancedWithTools: allToolCalls.length > 0,
|
|
859
944
|
};
|
|
860
945
|
return this.enhanceResult(baseResult, options, startTime);
|
|
@@ -886,6 +971,13 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
886
971
|
logger.info("[GoogleAIStudio] Routing image generation model to executeImageGeneration", { model: modelName });
|
|
887
972
|
return this.executeImageGeneration(options);
|
|
888
973
|
}
|
|
974
|
+
// TTS direct-synthesis mode: synthesise the input text directly (no LLM
|
|
975
|
+
// call). BaseProvider.runGenerateInActiveContext does the same dispatch
|
|
976
|
+
// — replicated here because AI Studio's override bypasses that path.
|
|
977
|
+
if (options.tts?.enabled && !options.tts?.useAiResponse) {
|
|
978
|
+
logger.info("[GoogleAIStudio] Routing TTS direct-synthesis to handleDirectTTSSynthesis", { model: modelName });
|
|
979
|
+
return this.handleDirectTTSSynthesis(options, Date.now());
|
|
980
|
+
}
|
|
889
981
|
// Process the unified `input.files` array before routing to the
|
|
890
982
|
// native SDK. BaseProvider.generate() runs this preprocessing via
|
|
891
983
|
// buildMultimodalMessagesArray, but AI Studio's override skips it,
|
|
@@ -940,7 +1032,23 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
940
1032
|
mergedOptions.prompt ||
|
|
941
1033
|
"";
|
|
942
1034
|
try {
|
|
943
|
-
|
|
1035
|
+
// Wrap in `neurolink.executeGeneration` so the observability span
|
|
1036
|
+
// chain (Test: Generate Span Chain) sees a third inner span on the
|
|
1037
|
+
// native @google/genai path — Pipeline A providers get this from
|
|
1038
|
+
// GenerationHandler.executeGeneration; the native path bypasses
|
|
1039
|
+
// GenerationHandler so we add the span here.
|
|
1040
|
+
let result = await withSpan({
|
|
1041
|
+
name: "neurolink.executeGeneration",
|
|
1042
|
+
tracer: tracers.provider,
|
|
1043
|
+
attributes: {
|
|
1044
|
+
[ATTR.GEN_AI_SYSTEM]: this.providerName,
|
|
1045
|
+
[ATTR.GEN_AI_MODEL]: modelName,
|
|
1046
|
+
"neurolink.path": "native.google-genai",
|
|
1047
|
+
},
|
|
1048
|
+
}, async () => this.executeNativeGemini3Generate(mergedOptions));
|
|
1049
|
+
// Pipe through TTS-of-AI-response when caller asks for it. No-op when
|
|
1050
|
+
// tts is disabled or useAiResponse is false.
|
|
1051
|
+
result = await this.synthesizeAIResponseIfNeeded(result, options);
|
|
944
1052
|
this.emitPipelineBGenerationEvent(modelName, result, generateStartTime, true, undefined, inputPrompt);
|
|
945
1053
|
return result;
|
|
946
1054
|
}
|
|
@@ -963,6 +1071,14 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
963
1071
|
const usage = result?.usage && typeof result.usage === "object"
|
|
964
1072
|
? result.usage
|
|
965
1073
|
: { input: 0, output: 0, total: 0 };
|
|
1074
|
+
// Mark on the result so the SDK-level runStandardGenerateRequest knows
|
|
1075
|
+
// this provider already emitted `generation:end` itself and skips its
|
|
1076
|
+
// own duplicate emission. Without this flag the public event listener
|
|
1077
|
+
// (and the observability test) would see two events per generate call.
|
|
1078
|
+
if (result && typeof result === "object") {
|
|
1079
|
+
result._generationEndEmitted =
|
|
1080
|
+
true;
|
|
1081
|
+
}
|
|
966
1082
|
emitter.emit("generation:end", {
|
|
967
1083
|
provider: this.providerName,
|
|
968
1084
|
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.
|