@flutchai/flutch-sdk 0.7.9 → 0.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +39 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +39 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7625,6 +7625,22 @@ function buildReasoningRequestFields(effort, thinking) {
|
|
|
7625
7625
|
};
|
|
7626
7626
|
}
|
|
7627
7627
|
__name(buildReasoningRequestFields, "buildReasoningRequestFields");
|
|
7628
|
+
var isPlainObject = /* @__PURE__ */ __name((v) => typeof v === "object" && v !== null && !Array.isArray(v), "isPlainObject");
|
|
7629
|
+
function mergeRequestFields(base, extra) {
|
|
7630
|
+
if (!extra || Object.keys(extra).length === 0) return base;
|
|
7631
|
+
if (!base) return {
|
|
7632
|
+
...extra
|
|
7633
|
+
};
|
|
7634
|
+
const merged = {
|
|
7635
|
+
...base
|
|
7636
|
+
};
|
|
7637
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
7638
|
+
const current = merged[key];
|
|
7639
|
+
merged[key] = isPlainObject(current) && isPlainObject(value) ? mergeRequestFields(current, value) : value;
|
|
7640
|
+
}
|
|
7641
|
+
return merged;
|
|
7642
|
+
}
|
|
7643
|
+
__name(mergeRequestFields, "mergeRequestFields");
|
|
7628
7644
|
function resolveSamplingParams(modelIdentifiers, requested, supportsSamplingParams) {
|
|
7629
7645
|
const accepted = supportsSamplingParams ?? modelIdentifiers.every((id) => modelAcceptsSamplingParams(id));
|
|
7630
7646
|
if (accepted) {
|
|
@@ -7973,12 +7989,14 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7973
7989
|
const withCache = config.promptCache === void 0 && config.promptCacheTtl === void 0 ? withSampling : `${withSampling}:pc:${config.promptCache ?? "auto"}:${config.promptCacheTtl ?? "default"}`;
|
|
7974
7990
|
const withEffort = config.effort === void 0 ? withCache : `${withCache}:eff:${config.effort}`;
|
|
7975
7991
|
const withThinking = config.thinking === void 0 ? withEffort : `${withEffort}:th:${config.thinking}`;
|
|
7976
|
-
|
|
7992
|
+
const withFields = config.requestFields ? `${withThinking}:rf:${JSON.stringify(config.requestFields)}` : withThinking;
|
|
7993
|
+
return config.toolSearch?.enabled ? `${withFields}:ts:${JSON.stringify(config.toolSearch)}` : withFields;
|
|
7977
7994
|
}
|
|
7978
7995
|
// Chat model creators
|
|
7979
7996
|
chatModelCreators = {
|
|
7980
|
-
[ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultEffort }) => {
|
|
7997
|
+
[ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultEffort, requestFields }) => {
|
|
7981
7998
|
const config = buildOpenAIModelConfig(modelName, defaultTemperature, defaultMaxTokens, apiToken || this.resolveApiKey(ModelProvider.OPENAI) || "", defaultEffort);
|
|
7999
|
+
if (requestFields) config.modelKwargs = requestFields;
|
|
7982
8000
|
const routerURL = resolveRouterURL(baseURL);
|
|
7983
8001
|
if (routerURL) {
|
|
7984
8002
|
config.configuration = {
|
|
@@ -7988,8 +8006,13 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7988
8006
|
}
|
|
7989
8007
|
return new openai.ChatOpenAI(config);
|
|
7990
8008
|
},
|
|
7991
|
-
[ModelProvider.ANTHROPIC]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultThinking }, promptCacheControl) => {
|
|
8009
|
+
[ModelProvider.ANTHROPIC]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultThinking, requestFields }, promptCacheControl) => {
|
|
7992
8010
|
const routerURL = resolveRouterURL(baseURL);
|
|
8011
|
+
const { thinking, output_config: outputConfig, ...invocationKwargs } = mergeRequestFields(defaultThinking && {
|
|
8012
|
+
thinking: {
|
|
8013
|
+
type: defaultThinking
|
|
8014
|
+
}
|
|
8015
|
+
}, requestFields) ?? {};
|
|
7993
8016
|
return new anthropic.ChatAnthropic({
|
|
7994
8017
|
modelName,
|
|
7995
8018
|
// Claude Opus 4.7+ / Claude 5 reject `temperature` outright — the key
|
|
@@ -8006,10 +8029,14 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8006
8029
|
cache_control: promptCacheControl
|
|
8007
8030
|
},
|
|
8008
8031
|
// The thinking mode as the API's own parameter; absent when unset.
|
|
8009
|
-
...
|
|
8010
|
-
thinking
|
|
8011
|
-
|
|
8012
|
-
|
|
8032
|
+
...thinking !== void 0 && {
|
|
8033
|
+
thinking
|
|
8034
|
+
},
|
|
8035
|
+
...outputConfig !== void 0 && {
|
|
8036
|
+
outputConfig
|
|
8037
|
+
},
|
|
8038
|
+
...Object.keys(invocationKwargs).length > 0 && {
|
|
8039
|
+
invocationKwargs
|
|
8013
8040
|
},
|
|
8014
8041
|
anthropicApiKey: apiToken || this.resolveApiKey(ModelProvider.ANTHROPIC),
|
|
8015
8042
|
...routerURL && {
|
|
@@ -8218,7 +8245,8 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8218
8245
|
defaultMaxTokens: toOptionalNumber(config.maxTokens) ?? toOptionalNumber(modelConfig.defaultMaxTokens),
|
|
8219
8246
|
baseURL: config.baseURL ?? modelConfig.baseURL,
|
|
8220
8247
|
defaultEffort: config.effort ?? modelConfig.defaultEffort,
|
|
8221
|
-
defaultThinking: config.thinking ?? modelConfig.defaultThinking
|
|
8248
|
+
defaultThinking: config.thinking ?? modelConfig.defaultThinking,
|
|
8249
|
+
requestFields: config.requestFields
|
|
8222
8250
|
};
|
|
8223
8251
|
const promptCacheControl = resolvePromptCacheControl([
|
|
8224
8252
|
finalConfig.bedrockModelId,
|
|
@@ -8230,7 +8258,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8230
8258
|
this.logger.debug(`Creating new chat model instance: ${cacheKey}`);
|
|
8231
8259
|
let model;
|
|
8232
8260
|
if (finalConfig.useBedrock && finalConfig.bedrockModelId) {
|
|
8233
|
-
const effortFields = buildReasoningRequestFields(config.effort ?? modelConfig.defaultEffort, config.thinking ?? modelConfig.defaultThinking);
|
|
8261
|
+
const effortFields = mergeRequestFields(buildReasoningRequestFields(config.effort ?? modelConfig.defaultEffort, config.thinking ?? modelConfig.defaultThinking), config.requestFields);
|
|
8234
8262
|
model = new FlutchChatBedrockConverse({
|
|
8235
8263
|
model: finalConfig.bedrockModelId,
|
|
8236
8264
|
region: this.resolveBedrockRegion(),
|
|
@@ -8239,6 +8267,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8239
8267
|
temperature: finalConfig.defaultTemperature
|
|
8240
8268
|
},
|
|
8241
8269
|
...effortFields && {
|
|
8270
|
+
// Plain JSON: what Converse's DocumentType describes.
|
|
8242
8271
|
additionalModelRequestFields: effortFields
|
|
8243
8272
|
},
|
|
8244
8273
|
maxTokens: finalConfig.defaultMaxTokens,
|
|
@@ -9273,6 +9302,7 @@ exports.isToolSearchCall = isToolSearchCall;
|
|
|
9273
9302
|
exports.joinTextSteps = joinTextSteps;
|
|
9274
9303
|
exports.loadOAuthProviders = loadOAuthProviders;
|
|
9275
9304
|
exports.loadedToolNames = loadedToolNames;
|
|
9305
|
+
exports.mergeRequestFields = mergeRequestFields;
|
|
9276
9306
|
exports.modelAcceptsSamplingParams = modelAcceptsSamplingParams;
|
|
9277
9307
|
exports.modelSupportsPromptCache = modelSupportsPromptCache;
|
|
9278
9308
|
exports.normalizeToolConfigs = normalizeToolConfigs;
|