@flutchai/flutch-sdk 0.7.8 → 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 +60 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +59 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7609,6 +7609,38 @@ function buildEffortRequestFields(effort) {
|
|
|
7609
7609
|
} : void 0;
|
|
7610
7610
|
}
|
|
7611
7611
|
__name(buildEffortRequestFields, "buildEffortRequestFields");
|
|
7612
|
+
function buildReasoningRequestFields(effort, thinking) {
|
|
7613
|
+
if (!effort && !thinking) return void 0;
|
|
7614
|
+
return {
|
|
7615
|
+
...effort && {
|
|
7616
|
+
output_config: {
|
|
7617
|
+
effort
|
|
7618
|
+
}
|
|
7619
|
+
},
|
|
7620
|
+
...thinking && {
|
|
7621
|
+
thinking: {
|
|
7622
|
+
type: thinking
|
|
7623
|
+
}
|
|
7624
|
+
}
|
|
7625
|
+
};
|
|
7626
|
+
}
|
|
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");
|
|
7612
7644
|
function resolveSamplingParams(modelIdentifiers, requested, supportsSamplingParams) {
|
|
7613
7645
|
const accepted = supportsSamplingParams ?? modelIdentifiers.every((id) => modelAcceptsSamplingParams(id));
|
|
7614
7646
|
if (accepted) {
|
|
@@ -7956,12 +7988,15 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7956
7988
|
const withSampling = config.supportsSamplingParams === void 0 ? withMcp : `${withMcp}:sp:${config.supportsSamplingParams}`;
|
|
7957
7989
|
const withCache = config.promptCache === void 0 && config.promptCacheTtl === void 0 ? withSampling : `${withSampling}:pc:${config.promptCache ?? "auto"}:${config.promptCacheTtl ?? "default"}`;
|
|
7958
7990
|
const withEffort = config.effort === void 0 ? withCache : `${withCache}:eff:${config.effort}`;
|
|
7959
|
-
|
|
7991
|
+
const withThinking = config.thinking === void 0 ? withEffort : `${withEffort}:th:${config.thinking}`;
|
|
7992
|
+
const withFields = config.requestFields ? `${withThinking}:rf:${JSON.stringify(config.requestFields)}` : withThinking;
|
|
7993
|
+
return config.toolSearch?.enabled ? `${withFields}:ts:${JSON.stringify(config.toolSearch)}` : withFields;
|
|
7960
7994
|
}
|
|
7961
7995
|
// Chat model creators
|
|
7962
7996
|
chatModelCreators = {
|
|
7963
|
-
[ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultEffort }) => {
|
|
7997
|
+
[ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultEffort, requestFields }) => {
|
|
7964
7998
|
const config = buildOpenAIModelConfig(modelName, defaultTemperature, defaultMaxTokens, apiToken || this.resolveApiKey(ModelProvider.OPENAI) || "", defaultEffort);
|
|
7999
|
+
if (requestFields) config.modelKwargs = requestFields;
|
|
7965
8000
|
const routerURL = resolveRouterURL(baseURL);
|
|
7966
8001
|
if (routerURL) {
|
|
7967
8002
|
config.configuration = {
|
|
@@ -7971,8 +8006,13 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7971
8006
|
}
|
|
7972
8007
|
return new openai.ChatOpenAI(config);
|
|
7973
8008
|
},
|
|
7974
|
-
[ModelProvider.ANTHROPIC]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL }, promptCacheControl) => {
|
|
8009
|
+
[ModelProvider.ANTHROPIC]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultThinking, requestFields }, promptCacheControl) => {
|
|
7975
8010
|
const routerURL = resolveRouterURL(baseURL);
|
|
8011
|
+
const { thinking, output_config: outputConfig, ...invocationKwargs } = mergeRequestFields(defaultThinking && {
|
|
8012
|
+
thinking: {
|
|
8013
|
+
type: defaultThinking
|
|
8014
|
+
}
|
|
8015
|
+
}, requestFields) ?? {};
|
|
7976
8016
|
return new anthropic.ChatAnthropic({
|
|
7977
8017
|
modelName,
|
|
7978
8018
|
// Claude Opus 4.7+ / Claude 5 reject `temperature` outright — the key
|
|
@@ -7988,6 +8028,16 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7988
8028
|
...promptCacheControl && {
|
|
7989
8029
|
cache_control: promptCacheControl
|
|
7990
8030
|
},
|
|
8031
|
+
// The thinking mode as the API's own parameter; absent when unset.
|
|
8032
|
+
...thinking !== void 0 && {
|
|
8033
|
+
thinking
|
|
8034
|
+
},
|
|
8035
|
+
...outputConfig !== void 0 && {
|
|
8036
|
+
outputConfig
|
|
8037
|
+
},
|
|
8038
|
+
...Object.keys(invocationKwargs).length > 0 && {
|
|
8039
|
+
invocationKwargs
|
|
8040
|
+
},
|
|
7991
8041
|
anthropicApiKey: apiToken || this.resolveApiKey(ModelProvider.ANTHROPIC),
|
|
7992
8042
|
...routerURL && {
|
|
7993
8043
|
anthropicApiUrl: routerURL
|
|
@@ -8194,7 +8244,9 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8194
8244
|
defaultTemperature: sampling.temperature,
|
|
8195
8245
|
defaultMaxTokens: toOptionalNumber(config.maxTokens) ?? toOptionalNumber(modelConfig.defaultMaxTokens),
|
|
8196
8246
|
baseURL: config.baseURL ?? modelConfig.baseURL,
|
|
8197
|
-
defaultEffort: config.effort ?? modelConfig.defaultEffort
|
|
8247
|
+
defaultEffort: config.effort ?? modelConfig.defaultEffort,
|
|
8248
|
+
defaultThinking: config.thinking ?? modelConfig.defaultThinking,
|
|
8249
|
+
requestFields: config.requestFields
|
|
8198
8250
|
};
|
|
8199
8251
|
const promptCacheControl = resolvePromptCacheControl([
|
|
8200
8252
|
finalConfig.bedrockModelId,
|
|
@@ -8206,7 +8258,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8206
8258
|
this.logger.debug(`Creating new chat model instance: ${cacheKey}`);
|
|
8207
8259
|
let model;
|
|
8208
8260
|
if (finalConfig.useBedrock && finalConfig.bedrockModelId) {
|
|
8209
|
-
const effortFields =
|
|
8261
|
+
const effortFields = mergeRequestFields(buildReasoningRequestFields(config.effort ?? modelConfig.defaultEffort, config.thinking ?? modelConfig.defaultThinking), config.requestFields);
|
|
8210
8262
|
model = new FlutchChatBedrockConverse({
|
|
8211
8263
|
model: finalConfig.bedrockModelId,
|
|
8212
8264
|
region: this.resolveBedrockRegion(),
|
|
@@ -8215,6 +8267,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8215
8267
|
temperature: finalConfig.defaultTemperature
|
|
8216
8268
|
},
|
|
8217
8269
|
...effortFields && {
|
|
8270
|
+
// Plain JSON: what Converse's DocumentType describes.
|
|
8218
8271
|
additionalModelRequestFields: effortFields
|
|
8219
8272
|
},
|
|
8220
8273
|
maxTokens: finalConfig.defaultMaxTokens,
|
|
@@ -9211,6 +9264,7 @@ exports.bootstrap = bootstrap;
|
|
|
9211
9264
|
exports.buildEffortRequestFields = buildEffortRequestFields;
|
|
9212
9265
|
exports.buildOAuthAuthorizationUrl = buildOAuthAuthorizationUrl;
|
|
9213
9266
|
exports.buildOpenAIModelConfig = buildOpenAIModelConfig;
|
|
9267
|
+
exports.buildReasoningRequestFields = buildReasoningRequestFields;
|
|
9214
9268
|
exports.clearAttachmentDataStore = clearAttachmentDataStore;
|
|
9215
9269
|
exports.createEndpointDescriptors = createEndpointDescriptors;
|
|
9216
9270
|
exports.createGraphAttachment = createGraphAttachment;
|
|
@@ -9248,6 +9302,7 @@ exports.isToolSearchCall = isToolSearchCall;
|
|
|
9248
9302
|
exports.joinTextSteps = joinTextSteps;
|
|
9249
9303
|
exports.loadOAuthProviders = loadOAuthProviders;
|
|
9250
9304
|
exports.loadedToolNames = loadedToolNames;
|
|
9305
|
+
exports.mergeRequestFields = mergeRequestFields;
|
|
9251
9306
|
exports.modelAcceptsSamplingParams = modelAcceptsSamplingParams;
|
|
9252
9307
|
exports.modelSupportsPromptCache = modelSupportsPromptCache;
|
|
9253
9308
|
exports.normalizeToolConfigs = normalizeToolConfigs;
|