@flutchai/flutch-sdk 0.7.14 → 0.7.15
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 +45 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +43 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5203,6 +5203,29 @@ function sanitizeTraceError(error, options) {
|
|
|
5203
5203
|
}
|
|
5204
5204
|
__name(sanitizeTraceError, "sanitizeTraceError");
|
|
5205
5205
|
|
|
5206
|
+
// src/tools/tool-usage.ts
|
|
5207
|
+
function toolUsageOf(value) {
|
|
5208
|
+
const cost = value?.total_cost;
|
|
5209
|
+
return typeof cost === "number" && Number.isFinite(cost) && cost >= 0 ? {
|
|
5210
|
+
total_cost: cost
|
|
5211
|
+
} : void 0;
|
|
5212
|
+
}
|
|
5213
|
+
__name(toolUsageOf, "toolUsageOf");
|
|
5214
|
+
function toolEndOutput(content, usage) {
|
|
5215
|
+
return usage ? {
|
|
5216
|
+
content,
|
|
5217
|
+
usage_metadata: usage
|
|
5218
|
+
} : content;
|
|
5219
|
+
}
|
|
5220
|
+
__name(toolEndOutput, "toolEndOutput");
|
|
5221
|
+
function toolEndContent(output) {
|
|
5222
|
+
if (!output || typeof output !== "object") return void 0;
|
|
5223
|
+
const o = output;
|
|
5224
|
+
if (typeof o.content !== "string") return void 0;
|
|
5225
|
+
return toolUsageOf(o.usage_metadata) || toolUsageOf(o.artifact?.usage_metadata) ? o.content : void 0;
|
|
5226
|
+
}
|
|
5227
|
+
__name(toolEndContent, "toolEndContent");
|
|
5228
|
+
|
|
5206
5229
|
// src/engines/langgraph/stream-thinking.ts
|
|
5207
5230
|
function splitThinking(blocks) {
|
|
5208
5231
|
const thoughts = [];
|
|
@@ -5688,7 +5711,7 @@ exports.EventProcessor = class _EventProcessor {
|
|
|
5688
5711
|
const output = event.data?.output;
|
|
5689
5712
|
let outputString;
|
|
5690
5713
|
try {
|
|
5691
|
-
outputString = typeof output === "string" ? output : JSON.stringify(output, null, 2);
|
|
5714
|
+
outputString = typeof output === "string" ? output : toolEndContent(output) ?? JSON.stringify(output, null, 2);
|
|
5692
5715
|
} catch {
|
|
5693
5716
|
outputString = typeof output?.content === "string" ? output.content : "[Output too large to display]";
|
|
5694
5717
|
}
|
|
@@ -6957,6 +6980,9 @@ ${paramDescriptions.join("\n")}`;
|
|
|
6957
6980
|
name: mcpTool.name,
|
|
6958
6981
|
description: enhancedDescription,
|
|
6959
6982
|
schema,
|
|
6983
|
+
// The call's cost rides on the ToolMessage's artifact, which the model
|
|
6984
|
+
// never sees and the trace keeps (see tool-usage.ts).
|
|
6985
|
+
responseFormat: "content_and_artifact",
|
|
6960
6986
|
func: /* @__PURE__ */ __name(async (input, _runManager, config) => {
|
|
6961
6987
|
logger3.log(`\u{1F527} [${mcpTool.name}] LLM INPUT: ${JSON.stringify(input)}`);
|
|
6962
6988
|
const configurable = config?.configurable;
|
|
@@ -6985,7 +7011,13 @@ ${paramDescriptions.join("\n")}`;
|
|
|
6985
7011
|
}
|
|
6986
7012
|
const output = typeof result.result === "string" ? result.result : JSON.stringify(result.result, null, 2);
|
|
6987
7013
|
logger3.log(`\u{1F527} [${mcpTool.name}] TOOL OUTPUT: ${output.length > 200 ? output.substring(0, 200) + "..." : output}`);
|
|
6988
|
-
|
|
7014
|
+
const usage = toolUsageOf(result.usage_metadata);
|
|
7015
|
+
return [
|
|
7016
|
+
output,
|
|
7017
|
+
usage ? {
|
|
7018
|
+
usage_metadata: usage
|
|
7019
|
+
} : void 0
|
|
7020
|
+
];
|
|
6989
7021
|
} catch (error) {
|
|
6990
7022
|
logger3.error(`\u{1F527} [${mcpTool.name}] Exception during execution`, error);
|
|
6991
7023
|
if (axios2__default.default.isAxiosError(error)) {
|
|
@@ -7305,12 +7337,17 @@ exports.McpRuntimeHttpClient = class _McpRuntimeHttpClient {
|
|
|
7305
7337
|
]
|
|
7306
7338
|
}, JSON.stringify(enrichedArgs), parsedConfig.runId, void 0, parsedConfig.tags, parsedConfig.metadata, toolName);
|
|
7307
7339
|
const result = await this.executeTool(toolName, enrichedArgs, executionContext, mcpServers, config?.signal);
|
|
7308
|
-
const
|
|
7309
|
-
|
|
7340
|
+
const { usage_metadata: rawUsage, ...shown } = result;
|
|
7341
|
+
const usageMetadata = toolUsageOf(rawUsage);
|
|
7342
|
+
const content = shown.success ? JSON.stringify(shown) : shown.error || JSON.stringify(shown);
|
|
7343
|
+
await runManager?.handleToolEnd(toolEndOutput(content, usageMetadata));
|
|
7310
7344
|
return {
|
|
7311
7345
|
content,
|
|
7312
7346
|
success: result.success,
|
|
7313
|
-
rawResult: result.success ? result.result : void 0
|
|
7347
|
+
rawResult: result.success ? result.result : void 0,
|
|
7348
|
+
...usageMetadata && {
|
|
7349
|
+
usageMetadata
|
|
7350
|
+
}
|
|
7314
7351
|
};
|
|
7315
7352
|
} catch (error) {
|
|
7316
7353
|
this.logger.error(`Error executing tool ${toolName}:`, error);
|
|
@@ -9491,8 +9528,11 @@ exports.splitTools = splitTools;
|
|
|
9491
9528
|
exports.storeAttachmentData = storeAttachmentData;
|
|
9492
9529
|
exports.toOpenAIEffort = toOpenAIEffort;
|
|
9493
9530
|
exports.toOptionalNumber = toOptionalNumber;
|
|
9531
|
+
exports.toolEndContent = toolEndContent;
|
|
9532
|
+
exports.toolEndOutput = toolEndOutput;
|
|
9494
9533
|
exports.toolSearchApplies = toolSearchApplies;
|
|
9495
9534
|
exports.toolSearchTerms = toolSearchTerms;
|
|
9535
|
+
exports.toolUsageOf = toolUsageOf;
|
|
9496
9536
|
exports.traceApiCall = traceApiCall;
|
|
9497
9537
|
exports.withFlutchContext = withFlutchContext;
|
|
9498
9538
|
exports.withToolReferences = withToolReferences;
|