@flutchai/flutch-sdk 0.7.4 → 0.7.6

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 CHANGED
@@ -6844,6 +6844,7 @@ ${paramDescriptions.join("\n")}`;
6844
6844
  }
6845
6845
  }
6846
6846
  };
6847
+ var MCP_RUNTIME_TIMEOUT_MS = Number(process.env.MCP_RUNTIME_TIMEOUT_MS) || 2e4;
6847
6848
  var McpToolFilter = class _McpToolFilter {
6848
6849
  static {
6849
6850
  __name(this, "McpToolFilter");
@@ -6877,7 +6878,7 @@ var McpToolFilter = class _McpToolFilter {
6877
6878
  if (context) requestBody.context = context;
6878
6879
  this.logger.debug(`[DEBUG] Request body: ${JSON.stringify(requestBody)}`);
6879
6880
  const response = await axios2__default.default.post(`${this.mcpRuntimeUrl}/tools/schemas`, requestBody, {
6880
- timeout: 5e3,
6881
+ timeout: MCP_RUNTIME_TIMEOUT_MS,
6881
6882
  headers: {
6882
6883
  "Content-Type": "application/json"
6883
6884
  }
@@ -6920,7 +6921,7 @@ var McpToolFilter = class _McpToolFilter {
6920
6921
  async getAllTools() {
6921
6922
  try {
6922
6923
  const response = await axios2__default.default.get(`${this.mcpRuntimeUrl}/tools/list`, {
6923
- timeout: 5e3
6924
+ timeout: MCP_RUNTIME_TIMEOUT_MS
6924
6925
  });
6925
6926
  const allTools = Array.isArray(response.data) ? response.data : [];
6926
6927
  this.logger.debug(`Retrieved ${allTools.length} total MCP tools`);
@@ -6967,7 +6968,7 @@ var McpToolFilter = class _McpToolFilter {
6967
6968
  async getAvailableToolNames() {
6968
6969
  try {
6969
6970
  const response = await axios2__default.default.get(`${this.mcpRuntimeUrl}/tools/list`, {
6970
- timeout: 5e3
6971
+ timeout: MCP_RUNTIME_TIMEOUT_MS
6971
6972
  });
6972
6973
  const tools = Array.isArray(response.data) ? response.data : [];
6973
6974
  return tools.map((tool) => tool.name);
@@ -7169,6 +7170,14 @@ function shortDescription(description) {
7169
7170
  return sentenceEnd > HIT_DESCRIPTION_CHARS / 2 ? cut.slice(0, sentenceEnd + 1) : `${cut.trimEnd()}\u2026`;
7170
7171
  }
7171
7172
  __name(shortDescription, "shortDescription");
7173
+ var INDEX_DESCRIPTION_CHARS = 100;
7174
+ function indexDescription(description) {
7175
+ const flat = description.replace(/\s+/g, " ").trim();
7176
+ const sentenceEnd = flat.search(/[.!?](\s|$)/);
7177
+ const sentence = sentenceEnd >= 0 ? flat.slice(0, sentenceEnd) : flat;
7178
+ return sentence.length <= INDEX_DESCRIPTION_CHARS ? sentence : `${sentence.slice(0, INDEX_DESCRIPTION_CHARS).trimEnd()}\u2026`;
7179
+ }
7180
+ __name(indexDescription, "indexDescription");
7172
7181
  var ToolSearchCatalog = class {
7173
7182
  static {
7174
7183
  __name(this, "ToolSearchCatalog");
@@ -7243,6 +7252,17 @@ var ToolSearchCatalog = class {
7243
7252
  }));
7244
7253
  }
7245
7254
  /**
7255
+ * Every tool of the catalog on its own line: its name and the start of its
7256
+ * description. Costs a few tokens per tool instead of a full schema, and
7257
+ * lets the model ask for a tool by its exact name.
7258
+ */
7259
+ index() {
7260
+ return this.entries.map((entry) => {
7261
+ const brief = indexDescription(entry.description);
7262
+ return brief ? `- ${entry.name}: ${brief}` : `- ${entry.name}`;
7263
+ }).join("\n");
7264
+ }
7265
+ /**
7246
7266
  * What the catalog covers, as name prefixes with counts:
7247
7267
  * "funnel_* (4), recipe_* (5), rl_* (41)". Goes into the search tool's
7248
7268
  * description so the model knows a search is worth making. Sorted, so the
@@ -7337,10 +7357,13 @@ function splitTools(tools, options, extraCore = []) {
7337
7357
  };
7338
7358
  }
7339
7359
  __name(splitTools, "splitTools");
7340
- function createToolSearchTool(catalog, maxResults = DEFAULT_TOOL_SEARCH_RESULTS) {
7360
+ function createToolSearchTool(catalog, maxResults = DEFAULT_TOOL_SEARCH_RESULTS, index = false) {
7361
+ const covered = index ? `${catalog.size} more are found by search:
7362
+ ${catalog.index()}
7363
+ ` : `${catalog.size} more are found by search: ${catalog.summary()}. `;
7341
7364
  return new tools.DynamicStructuredTool({
7342
7365
  name: TOOL_SEARCH_NAME,
7343
- description: `Find more tools. You see only some of your tools; ${catalog.size} more are found by search: ${catalog.summary()}. 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.`,
7366
+ 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
7367
  schema: zod.z.object({
7345
7368
  query: zod.z.string().describe("What the tool should do, in a few words, or tool names separated by commas"),
7346
7369
  limit: zod.z.number().int().min(1).max(20).optional().describe(`How many tools to return (default ${maxResults})`)
@@ -7622,7 +7645,11 @@ function generateModelCacheKey(modelId, temperature, maxTokens, toolsConfig, bas
7622
7645
  return parts.join(":");
7623
7646
  }
7624
7647
  __name(generateModelCacheKey, "generateModelCacheKey");
7625
- function buildOpenAIModelConfig(modelName, temperature, maxTokens, apiToken) {
7648
+ function toOpenAIEffort(effort) {
7649
+ return effort === "max" ? "xhigh" : effort;
7650
+ }
7651
+ __name(toOpenAIEffort, "toOpenAIEffort");
7652
+ function buildOpenAIModelConfig(modelName, temperature, maxTokens, apiToken, effort) {
7626
7653
  if (isReasoningModel(modelName)) {
7627
7654
  return {
7628
7655
  modelName,
@@ -7630,7 +7657,14 @@ function buildOpenAIModelConfig(modelName, temperature, maxTokens, apiToken) {
7630
7657
  maxCompletionTokens: maxTokens,
7631
7658
  streaming: true,
7632
7659
  useResponsesApi: true,
7633
- apiKey: apiToken
7660
+ apiKey: apiToken,
7661
+ // Responses API `reasoning.effort`. Omitted when unset, so the request
7662
+ // stays what it was and the model keeps its own default.
7663
+ ...effort && {
7664
+ reasoning: {
7665
+ effort: toOpenAIEffort(effort)
7666
+ }
7667
+ }
7634
7668
  };
7635
7669
  }
7636
7670
  return {
@@ -7897,8 +7931,8 @@ var ModelInitializer = class _ModelInitializer {
7897
7931
  }
7898
7932
  // Chat model creators
7899
7933
  chatModelCreators = {
7900
- [ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL }) => {
7901
- const config = buildOpenAIModelConfig(modelName, defaultTemperature, defaultMaxTokens, apiToken || this.resolveApiKey(ModelProvider.OPENAI) || "");
7934
+ [ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL, defaultEffort }) => {
7935
+ const config = buildOpenAIModelConfig(modelName, defaultTemperature, defaultMaxTokens, apiToken || this.resolveApiKey(ModelProvider.OPENAI) || "", defaultEffort);
7902
7936
  const routerURL = resolveRouterURL(baseURL);
7903
7937
  if (routerURL) {
7904
7938
  config.configuration = {
@@ -8130,7 +8164,8 @@ var ModelInitializer = class _ModelInitializer {
8130
8164
  ...modelConfig,
8131
8165
  defaultTemperature: sampling.temperature,
8132
8166
  defaultMaxTokens: toOptionalNumber(config.maxTokens) ?? toOptionalNumber(modelConfig.defaultMaxTokens),
8133
- baseURL: config.baseURL ?? modelConfig.baseURL
8167
+ baseURL: config.baseURL ?? modelConfig.baseURL,
8168
+ defaultEffort: config.effort ?? modelConfig.defaultEffort
8134
8169
  };
8135
8170
  const promptCacheControl = resolvePromptCacheControl([
8136
8171
  finalConfig.bedrockModelId,
@@ -8251,7 +8286,7 @@ var ModelInitializer = class _ModelInitializer {
8251
8286
  ...customTools ?? []
8252
8287
  ],
8253
8288
  deferred,
8254
- searchTool: createToolSearchTool(catalog, maxResults),
8289
+ searchTool: createToolSearchTool(catalog, maxResults, toolSearch.options.index === true),
8255
8290
  mode,
8256
8291
  bindOptions: promptCacheControl ? boundOptions : void 0
8257
8292
  });
@@ -9202,6 +9237,7 @@ exports.sanitizeReasoningForBedrock = sanitizeReasoningForBedrock;
9202
9237
  exports.sanitizeTraceData = sanitizeTraceData;
9203
9238
  exports.splitTools = splitTools;
9204
9239
  exports.storeAttachmentData = storeAttachmentData;
9240
+ exports.toOpenAIEffort = toOpenAIEffort;
9205
9241
  exports.toOptionalNumber = toOptionalNumber;
9206
9242
  exports.toolSearchApplies = toolSearchApplies;
9207
9243
  exports.toolSearchTerms = toolSearchTerms;