@stackfactor/agent-utils 1.4.0 → 1.4.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AA4GA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACtD,CAAC;
|
|
1
|
+
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AA4GA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACtD,CAAC;AAmrBF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,eAAO,MAAM,WAAW,GACtB,WAAW,MAAM,EACjB,QAAQ,GAAG,EACX,SAAQ,GAAU,KACjB,GAoHF,CAAC;;0CAj0B2C,GAAG,KAAG,IAAI;wBAo1B/C,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,iBACG,YAAY,GAAG,IAAI,KAChC,GAAG;sBAoCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,iBACb,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;oCAkYF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;sDA2tBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;sDAmTF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;0CA7zC8B,GAAG,KAAG,MAAM;+CAh0B9C,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,kBACD,MAAM,UACd,GAAG,KACV,IAAI;mCAg1BU,MAAM,mBACJ,MAAM,EAAE,KACxB,MAAM;;AAg2CT,wBAUE"}
|
package/dist/cjs/langChain.js
CHANGED
|
@@ -643,6 +643,46 @@ const resolveTemperatureSetting = (modelName, config) => {
|
|
|
643
643
|
}
|
|
644
644
|
return { temperature: clamped };
|
|
645
645
|
};
|
|
646
|
+
/**
|
|
647
|
+
* Gemini's ceiling on `maxOutputTokens`. The API validates the field and
|
|
648
|
+
* rejects the request outright rather than clamping it:
|
|
649
|
+
* "Unable to submit request because it has a maxOutputTokens value of N but the
|
|
650
|
+
* supported range is from 1 (inclusive) to 65537 (exclusive)" (HTTP 400,
|
|
651
|
+
* INVALID_ARGUMENT).
|
|
652
|
+
*
|
|
653
|
+
* Set to 64000 rather than that 65536 validation ceiling: the Pro models report
|
|
654
|
+
* a generation capacity of 64000, so 64000 is the value every model across the
|
|
655
|
+
* Gemini 3 line (3.1 Pro, 3.5/3.7/3.8 Flash) can both accept and actually
|
|
656
|
+
* produce. One safe constant beats a per-model table that would need editing
|
|
657
|
+
* every time Google ships a model — and the 1536 tokens of headroom given up on
|
|
658
|
+
* Flash are far beyond what any caller asks for.
|
|
659
|
+
*
|
|
660
|
+
* Deliberately Gemini-only. Anthropic and OpenAI take the caller's `maxTokens`
|
|
661
|
+
* unchanged, since neither rejects the values configured today.
|
|
662
|
+
*/
|
|
663
|
+
const GEMINI_MAX_OUTPUT_TOKENS = 64000;
|
|
664
|
+
/**
|
|
665
|
+
* Resolves `maxOutputTokens` for a Gemini model. Callers share one `maxTokens`
|
|
666
|
+
* setting across every provider, and the other providers tolerate values far
|
|
667
|
+
* above what Gemini accepts, so anything above Gemini's ceiling is clamped here
|
|
668
|
+
* (with a warning) instead of being sent through to a guaranteed HTTP 400. With
|
|
669
|
+
* no caller value the ceiling itself is used, which is what the previous
|
|
670
|
+
* 200000 default was reaching for.
|
|
671
|
+
* @param modelName - The Gemini model identifier being routed
|
|
672
|
+
* @param config - Configuration object; only `maxTokens` is consulted
|
|
673
|
+
* @returns A token count within Gemini's supported range
|
|
674
|
+
*/
|
|
675
|
+
const resolveGeminiMaxOutputTokens = (modelName, config) => {
|
|
676
|
+
const maxTokens = config?.maxTokens;
|
|
677
|
+
if (typeof maxTokens !== "number" || !Number.isFinite(maxTokens)) {
|
|
678
|
+
return GEMINI_MAX_OUTPUT_TOKENS;
|
|
679
|
+
}
|
|
680
|
+
if (maxTokens > GEMINI_MAX_OUTPUT_TOKENS) {
|
|
681
|
+
logger_js_1.default.log(null, logger_js_1.default.levels.warn, `maxTokens ${maxTokens} exceeds the ${GEMINI_MAX_OUTPUT_TOKENS}-token output ceiling of "${modelName}"; clamping to ${GEMINI_MAX_OUTPUT_TOKENS}.`);
|
|
682
|
+
return GEMINI_MAX_OUTPUT_TOKENS;
|
|
683
|
+
}
|
|
684
|
+
return maxTokens;
|
|
685
|
+
};
|
|
646
686
|
/**
|
|
647
687
|
* Flattens LangChain message content into plain text. Content is a string for
|
|
648
688
|
* ordinary completions, but providers switch to an array of blocks whenever the
|
|
@@ -734,7 +774,7 @@ const getLLMModel = (modelName, config, schema = null) => {
|
|
|
734
774
|
else if (modelName.startsWith("gemini-")) {
|
|
735
775
|
const model = new google_genai_1.ChatGoogleGenerativeAI({
|
|
736
776
|
apiKey: config.googleAPIKey,
|
|
737
|
-
maxOutputTokens: config
|
|
777
|
+
maxOutputTokens: resolveGeminiMaxOutputTokens(modelName, config),
|
|
738
778
|
model: modelName,
|
|
739
779
|
// `json: true` forces responseMimeType=application/json, guaranteeing the
|
|
740
780
|
// model returns valid JSON text (never prose) for the parse pipeline.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AA4GA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACtD,CAAC;
|
|
1
|
+
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AA4GA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACtD,CAAC;AAmrBF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,eAAO,MAAM,WAAW,GACtB,WAAW,MAAM,EACjB,QAAQ,GAAG,EACX,SAAQ,GAAU,KACjB,GAoHF,CAAC;;0CAj0B2C,GAAG,KAAG,IAAI;wBAo1B/C,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,iBACG,YAAY,GAAG,IAAI,KAChC,GAAG;sBAoCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,iBACb,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;oCAkYF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;sDA2tBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;sDAmTF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;0CA7zC8B,GAAG,KAAG,MAAM;+CAh0B9C,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,kBACD,MAAM,UACd,GAAG,KACV,IAAI;mCAg1BU,MAAM,mBACJ,MAAM,EAAE,KACxB,MAAM;;AAg2CT,wBAUE"}
|
package/dist/esm/langChain.js
CHANGED
|
@@ -637,6 +637,46 @@ const resolveTemperatureSetting = (modelName, config) => {
|
|
|
637
637
|
}
|
|
638
638
|
return { temperature: clamped };
|
|
639
639
|
};
|
|
640
|
+
/**
|
|
641
|
+
* Gemini's ceiling on `maxOutputTokens`. The API validates the field and
|
|
642
|
+
* rejects the request outright rather than clamping it:
|
|
643
|
+
* "Unable to submit request because it has a maxOutputTokens value of N but the
|
|
644
|
+
* supported range is from 1 (inclusive) to 65537 (exclusive)" (HTTP 400,
|
|
645
|
+
* INVALID_ARGUMENT).
|
|
646
|
+
*
|
|
647
|
+
* Set to 64000 rather than that 65536 validation ceiling: the Pro models report
|
|
648
|
+
* a generation capacity of 64000, so 64000 is the value every model across the
|
|
649
|
+
* Gemini 3 line (3.1 Pro, 3.5/3.7/3.8 Flash) can both accept and actually
|
|
650
|
+
* produce. One safe constant beats a per-model table that would need editing
|
|
651
|
+
* every time Google ships a model — and the 1536 tokens of headroom given up on
|
|
652
|
+
* Flash are far beyond what any caller asks for.
|
|
653
|
+
*
|
|
654
|
+
* Deliberately Gemini-only. Anthropic and OpenAI take the caller's `maxTokens`
|
|
655
|
+
* unchanged, since neither rejects the values configured today.
|
|
656
|
+
*/
|
|
657
|
+
const GEMINI_MAX_OUTPUT_TOKENS = 64000;
|
|
658
|
+
/**
|
|
659
|
+
* Resolves `maxOutputTokens` for a Gemini model. Callers share one `maxTokens`
|
|
660
|
+
* setting across every provider, and the other providers tolerate values far
|
|
661
|
+
* above what Gemini accepts, so anything above Gemini's ceiling is clamped here
|
|
662
|
+
* (with a warning) instead of being sent through to a guaranteed HTTP 400. With
|
|
663
|
+
* no caller value the ceiling itself is used, which is what the previous
|
|
664
|
+
* 200000 default was reaching for.
|
|
665
|
+
* @param modelName - The Gemini model identifier being routed
|
|
666
|
+
* @param config - Configuration object; only `maxTokens` is consulted
|
|
667
|
+
* @returns A token count within Gemini's supported range
|
|
668
|
+
*/
|
|
669
|
+
const resolveGeminiMaxOutputTokens = (modelName, config) => {
|
|
670
|
+
const maxTokens = config?.maxTokens;
|
|
671
|
+
if (typeof maxTokens !== "number" || !Number.isFinite(maxTokens)) {
|
|
672
|
+
return GEMINI_MAX_OUTPUT_TOKENS;
|
|
673
|
+
}
|
|
674
|
+
if (maxTokens > GEMINI_MAX_OUTPUT_TOKENS) {
|
|
675
|
+
logger.log(null, logger.levels.warn, `maxTokens ${maxTokens} exceeds the ${GEMINI_MAX_OUTPUT_TOKENS}-token output ceiling of "${modelName}"; clamping to ${GEMINI_MAX_OUTPUT_TOKENS}.`);
|
|
676
|
+
return GEMINI_MAX_OUTPUT_TOKENS;
|
|
677
|
+
}
|
|
678
|
+
return maxTokens;
|
|
679
|
+
};
|
|
640
680
|
/**
|
|
641
681
|
* Flattens LangChain message content into plain text. Content is a string for
|
|
642
682
|
* ordinary completions, but providers switch to an array of blocks whenever the
|
|
@@ -728,7 +768,7 @@ export const getLLMModel = (modelName, config, schema = null) => {
|
|
|
728
768
|
else if (modelName.startsWith("gemini-")) {
|
|
729
769
|
const model = new ChatGoogleGenerativeAI({
|
|
730
770
|
apiKey: config.googleAPIKey,
|
|
731
|
-
maxOutputTokens: config
|
|
771
|
+
maxOutputTokens: resolveGeminiMaxOutputTokens(modelName, config),
|
|
732
772
|
model: modelName,
|
|
733
773
|
// `json: true` forces responseMimeType=application/json, guaranteeing the
|
|
734
774
|
// model returns valid JSON text (never prose) for the parse pipeline.
|