@flutchai/flutch-sdk 0.7.4 → 0.7.5
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 +43 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7169,6 +7169,14 @@ function shortDescription(description) {
|
|
|
7169
7169
|
return sentenceEnd > HIT_DESCRIPTION_CHARS / 2 ? cut.slice(0, sentenceEnd + 1) : `${cut.trimEnd()}\u2026`;
|
|
7170
7170
|
}
|
|
7171
7171
|
__name(shortDescription, "shortDescription");
|
|
7172
|
+
var INDEX_DESCRIPTION_CHARS = 100;
|
|
7173
|
+
function indexDescription(description) {
|
|
7174
|
+
const flat = description.replace(/\s+/g, " ").trim();
|
|
7175
|
+
const sentenceEnd = flat.search(/[.!?](\s|$)/);
|
|
7176
|
+
const sentence = sentenceEnd >= 0 ? flat.slice(0, sentenceEnd) : flat;
|
|
7177
|
+
return sentence.length <= INDEX_DESCRIPTION_CHARS ? sentence : `${sentence.slice(0, INDEX_DESCRIPTION_CHARS).trimEnd()}\u2026`;
|
|
7178
|
+
}
|
|
7179
|
+
__name(indexDescription, "indexDescription");
|
|
7172
7180
|
var ToolSearchCatalog = class {
|
|
7173
7181
|
static {
|
|
7174
7182
|
__name(this, "ToolSearchCatalog");
|
|
@@ -7243,6 +7251,17 @@ var ToolSearchCatalog = class {
|
|
|
7243
7251
|
}));
|
|
7244
7252
|
}
|
|
7245
7253
|
/**
|
|
7254
|
+
* Every tool of the catalog on its own line: its name and the start of its
|
|
7255
|
+
* description. Costs a few tokens per tool instead of a full schema, and
|
|
7256
|
+
* lets the model ask for a tool by its exact name.
|
|
7257
|
+
*/
|
|
7258
|
+
index() {
|
|
7259
|
+
return this.entries.map((entry) => {
|
|
7260
|
+
const brief = indexDescription(entry.description);
|
|
7261
|
+
return brief ? `- ${entry.name}: ${brief}` : `- ${entry.name}`;
|
|
7262
|
+
}).join("\n");
|
|
7263
|
+
}
|
|
7264
|
+
/**
|
|
7246
7265
|
* What the catalog covers, as name prefixes with counts:
|
|
7247
7266
|
* "funnel_* (4), recipe_* (5), rl_* (41)". Goes into the search tool's
|
|
7248
7267
|
* description so the model knows a search is worth making. Sorted, so the
|
|
@@ -7337,10 +7356,13 @@ function splitTools(tools, options, extraCore = []) {
|
|
|
7337
7356
|
};
|
|
7338
7357
|
}
|
|
7339
7358
|
__name(splitTools, "splitTools");
|
|
7340
|
-
function createToolSearchTool(catalog, maxResults = DEFAULT_TOOL_SEARCH_RESULTS) {
|
|
7359
|
+
function createToolSearchTool(catalog, maxResults = DEFAULT_TOOL_SEARCH_RESULTS, index = false) {
|
|
7360
|
+
const covered = index ? `${catalog.size} more are found by search:
|
|
7361
|
+
${catalog.index()}
|
|
7362
|
+
` : `${catalog.size} more are found by search: ${catalog.summary()}. `;
|
|
7341
7363
|
return new tools.DynamicStructuredTool({
|
|
7342
7364
|
name: TOOL_SEARCH_NAME,
|
|
7343
|
-
description: `Find more tools. You see only some of your tools; ${
|
|
7365
|
+
description: `Find more tools. You see only some of your tools; ${covered}` + (index ? "Give the exact names of the tools you need, separated by commas, or describe the task in a few words. " : 'Describe the task in a few words (what to do and with what, e.g. "customer review quotes by theme"), or give exact tool names. ') + "Found tools become callable right away and stay available for the rest of the conversation. Search before saying you cannot do something.",
|
|
7344
7366
|
schema: zod.z.object({
|
|
7345
7367
|
query: zod.z.string().describe("What the tool should do, in a few words, or tool names separated by commas"),
|
|
7346
7368
|
limit: zod.z.number().int().min(1).max(20).optional().describe(`How many tools to return (default ${maxResults})`)
|
|
@@ -7622,7 +7644,11 @@ function generateModelCacheKey(modelId, temperature, maxTokens, toolsConfig, bas
|
|
|
7622
7644
|
return parts.join(":");
|
|
7623
7645
|
}
|
|
7624
7646
|
__name(generateModelCacheKey, "generateModelCacheKey");
|
|
7625
|
-
function
|
|
7647
|
+
function toOpenAIEffort(effort) {
|
|
7648
|
+
return effort === "max" ? "xhigh" : effort;
|
|
7649
|
+
}
|
|
7650
|
+
__name(toOpenAIEffort, "toOpenAIEffort");
|
|
7651
|
+
function buildOpenAIModelConfig(modelName, temperature, maxTokens, apiToken, effort) {
|
|
7626
7652
|
if (isReasoningModel(modelName)) {
|
|
7627
7653
|
return {
|
|
7628
7654
|
modelName,
|
|
@@ -7630,7 +7656,14 @@ function buildOpenAIModelConfig(modelName, temperature, maxTokens, apiToken) {
|
|
|
7630
7656
|
maxCompletionTokens: maxTokens,
|
|
7631
7657
|
streaming: true,
|
|
7632
7658
|
useResponsesApi: true,
|
|
7633
|
-
apiKey: apiToken
|
|
7659
|
+
apiKey: apiToken,
|
|
7660
|
+
// Responses API `reasoning.effort`. Omitted when unset, so the request
|
|
7661
|
+
// stays what it was and the model keeps its own default.
|
|
7662
|
+
...effort && {
|
|
7663
|
+
reasoning: {
|
|
7664
|
+
effort: toOpenAIEffort(effort)
|
|
7665
|
+
}
|
|
7666
|
+
}
|
|
7634
7667
|
};
|
|
7635
7668
|
}
|
|
7636
7669
|
return {
|
|
@@ -7897,8 +7930,8 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7897
7930
|
}
|
|
7898
7931
|
// Chat model creators
|
|
7899
7932
|
chatModelCreators = {
|
|
7900
|
-
[ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL }) => {
|
|
7901
|
-
const config = buildOpenAIModelConfig(modelName, defaultTemperature, defaultMaxTokens, apiToken || this.resolveApiKey(ModelProvider.OPENAI) || "");
|
|
7933
|
+
[ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultEffort }) => {
|
|
7934
|
+
const config = buildOpenAIModelConfig(modelName, defaultTemperature, defaultMaxTokens, apiToken || this.resolveApiKey(ModelProvider.OPENAI) || "", defaultEffort);
|
|
7902
7935
|
const routerURL = resolveRouterURL(baseURL);
|
|
7903
7936
|
if (routerURL) {
|
|
7904
7937
|
config.configuration = {
|
|
@@ -8130,7 +8163,8 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8130
8163
|
...modelConfig,
|
|
8131
8164
|
defaultTemperature: sampling.temperature,
|
|
8132
8165
|
defaultMaxTokens: toOptionalNumber(config.maxTokens) ?? toOptionalNumber(modelConfig.defaultMaxTokens),
|
|
8133
|
-
baseURL: config.baseURL ?? modelConfig.baseURL
|
|
8166
|
+
baseURL: config.baseURL ?? modelConfig.baseURL,
|
|
8167
|
+
defaultEffort: config.effort ?? modelConfig.defaultEffort
|
|
8134
8168
|
};
|
|
8135
8169
|
const promptCacheControl = resolvePromptCacheControl([
|
|
8136
8170
|
finalConfig.bedrockModelId,
|
|
@@ -8251,7 +8285,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8251
8285
|
...customTools ?? []
|
|
8252
8286
|
],
|
|
8253
8287
|
deferred,
|
|
8254
|
-
searchTool: createToolSearchTool(catalog, maxResults),
|
|
8288
|
+
searchTool: createToolSearchTool(catalog, maxResults, toolSearch.options.index === true),
|
|
8255
8289
|
mode,
|
|
8256
8290
|
bindOptions: promptCacheControl ? boundOptions : void 0
|
|
8257
8291
|
});
|
|
@@ -9202,6 +9236,7 @@ exports.sanitizeReasoningForBedrock = sanitizeReasoningForBedrock;
|
|
|
9202
9236
|
exports.sanitizeTraceData = sanitizeTraceData;
|
|
9203
9237
|
exports.splitTools = splitTools;
|
|
9204
9238
|
exports.storeAttachmentData = storeAttachmentData;
|
|
9239
|
+
exports.toOpenAIEffort = toOpenAIEffort;
|
|
9205
9240
|
exports.toOptionalNumber = toOptionalNumber;
|
|
9206
9241
|
exports.toolSearchApplies = toolSearchApplies;
|
|
9207
9242
|
exports.toolSearchTerms = toolSearchTerms;
|