@flutchai/flutch-sdk 0.7.3 → 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 +51 -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 +51 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5990,6 +5990,10 @@ exports.LangGraphEngine = class _LangGraphEngine {
|
|
|
5990
5990
|
traceEvents: trace?.events?.length || 0,
|
|
5991
5991
|
hadError: !!streamError
|
|
5992
5992
|
});
|
|
5993
|
+
if (streamError && isRecursionLimit(streamError) && content?.text?.trim()) {
|
|
5994
|
+
this.logger.warn(`[STREAM-ERROR] Recursion limit reached after the answer was written; returning the answer`);
|
|
5995
|
+
return content;
|
|
5996
|
+
}
|
|
5993
5997
|
if (streamError) {
|
|
5994
5998
|
throw streamError;
|
|
5995
5999
|
}
|
|
@@ -6198,6 +6202,10 @@ exports.LangGraphEngine = _ts_decorate22([
|
|
|
6198
6202
|
typeof config.ConfigService === "undefined" ? Object : config.ConfigService
|
|
6199
6203
|
])
|
|
6200
6204
|
], exports.LangGraphEngine);
|
|
6205
|
+
function isRecursionLimit(error) {
|
|
6206
|
+
return error.name === "GraphRecursionError" || /Recursion limit of \d+ reached/.test(error.message);
|
|
6207
|
+
}
|
|
6208
|
+
__name(isRecursionLimit, "isRecursionLimit");
|
|
6201
6209
|
|
|
6202
6210
|
// src/engines/graph-engine.factory.ts
|
|
6203
6211
|
function _ts_decorate23(decorators, target, key, desc) {
|
|
@@ -7161,6 +7169,14 @@ function shortDescription(description) {
|
|
|
7161
7169
|
return sentenceEnd > HIT_DESCRIPTION_CHARS / 2 ? cut.slice(0, sentenceEnd + 1) : `${cut.trimEnd()}\u2026`;
|
|
7162
7170
|
}
|
|
7163
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");
|
|
7164
7180
|
var ToolSearchCatalog = class {
|
|
7165
7181
|
static {
|
|
7166
7182
|
__name(this, "ToolSearchCatalog");
|
|
@@ -7235,6 +7251,17 @@ var ToolSearchCatalog = class {
|
|
|
7235
7251
|
}));
|
|
7236
7252
|
}
|
|
7237
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
|
+
/**
|
|
7238
7265
|
* What the catalog covers, as name prefixes with counts:
|
|
7239
7266
|
* "funnel_* (4), recipe_* (5), rl_* (41)". Goes into the search tool's
|
|
7240
7267
|
* description so the model knows a search is worth making. Sorted, so the
|
|
@@ -7329,10 +7356,13 @@ function splitTools(tools, options, extraCore = []) {
|
|
|
7329
7356
|
};
|
|
7330
7357
|
}
|
|
7331
7358
|
__name(splitTools, "splitTools");
|
|
7332
|
-
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()}. `;
|
|
7333
7363
|
return new tools.DynamicStructuredTool({
|
|
7334
7364
|
name: TOOL_SEARCH_NAME,
|
|
7335
|
-
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.",
|
|
7336
7366
|
schema: zod.z.object({
|
|
7337
7367
|
query: zod.z.string().describe("What the tool should do, in a few words, or tool names separated by commas"),
|
|
7338
7368
|
limit: zod.z.number().int().min(1).max(20).optional().describe(`How many tools to return (default ${maxResults})`)
|
|
@@ -7614,7 +7644,11 @@ function generateModelCacheKey(modelId, temperature, maxTokens, toolsConfig, bas
|
|
|
7614
7644
|
return parts.join(":");
|
|
7615
7645
|
}
|
|
7616
7646
|
__name(generateModelCacheKey, "generateModelCacheKey");
|
|
7617
|
-
function
|
|
7647
|
+
function toOpenAIEffort(effort) {
|
|
7648
|
+
return effort === "max" ? "xhigh" : effort;
|
|
7649
|
+
}
|
|
7650
|
+
__name(toOpenAIEffort, "toOpenAIEffort");
|
|
7651
|
+
function buildOpenAIModelConfig(modelName, temperature, maxTokens, apiToken, effort) {
|
|
7618
7652
|
if (isReasoningModel(modelName)) {
|
|
7619
7653
|
return {
|
|
7620
7654
|
modelName,
|
|
@@ -7622,7 +7656,14 @@ function buildOpenAIModelConfig(modelName, temperature, maxTokens, apiToken) {
|
|
|
7622
7656
|
maxCompletionTokens: maxTokens,
|
|
7623
7657
|
streaming: true,
|
|
7624
7658
|
useResponsesApi: true,
|
|
7625
|
-
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
|
+
}
|
|
7626
7667
|
};
|
|
7627
7668
|
}
|
|
7628
7669
|
return {
|
|
@@ -7889,8 +7930,8 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7889
7930
|
}
|
|
7890
7931
|
// Chat model creators
|
|
7891
7932
|
chatModelCreators = {
|
|
7892
|
-
[ModelProvider.OPENAI]: ({ modelName, defaultTemperature, defaultMaxTokens, apiToken, baseURL }) => {
|
|
7893
|
-
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);
|
|
7894
7935
|
const routerURL = resolveRouterURL(baseURL);
|
|
7895
7936
|
if (routerURL) {
|
|
7896
7937
|
config.configuration = {
|
|
@@ -8122,7 +8163,8 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8122
8163
|
...modelConfig,
|
|
8123
8164
|
defaultTemperature: sampling.temperature,
|
|
8124
8165
|
defaultMaxTokens: toOptionalNumber(config.maxTokens) ?? toOptionalNumber(modelConfig.defaultMaxTokens),
|
|
8125
|
-
baseURL: config.baseURL ?? modelConfig.baseURL
|
|
8166
|
+
baseURL: config.baseURL ?? modelConfig.baseURL,
|
|
8167
|
+
defaultEffort: config.effort ?? modelConfig.defaultEffort
|
|
8126
8168
|
};
|
|
8127
8169
|
const promptCacheControl = resolvePromptCacheControl([
|
|
8128
8170
|
finalConfig.bedrockModelId,
|
|
@@ -8243,7 +8285,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
8243
8285
|
...customTools ?? []
|
|
8244
8286
|
],
|
|
8245
8287
|
deferred,
|
|
8246
|
-
searchTool: createToolSearchTool(catalog, maxResults),
|
|
8288
|
+
searchTool: createToolSearchTool(catalog, maxResults, toolSearch.options.index === true),
|
|
8247
8289
|
mode,
|
|
8248
8290
|
bindOptions: promptCacheControl ? boundOptions : void 0
|
|
8249
8291
|
});
|
|
@@ -9194,6 +9236,7 @@ exports.sanitizeReasoningForBedrock = sanitizeReasoningForBedrock;
|
|
|
9194
9236
|
exports.sanitizeTraceData = sanitizeTraceData;
|
|
9195
9237
|
exports.splitTools = splitTools;
|
|
9196
9238
|
exports.storeAttachmentData = storeAttachmentData;
|
|
9239
|
+
exports.toOpenAIEffort = toOpenAIEffort;
|
|
9197
9240
|
exports.toOptionalNumber = toOptionalNumber;
|
|
9198
9241
|
exports.toolSearchApplies = toolSearchApplies;
|
|
9199
9242
|
exports.toolSearchTerms = toolSearchTerms;
|