@botbotgo/better-call 0.1.29 → 0.1.31
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/package.json +1 -1
- package/scripts/demo.mjs +17 -10
package/package.json
CHANGED
package/scripts/demo.mjs
CHANGED
|
@@ -37,18 +37,27 @@ const stockQuote = {
|
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const invalidArgs = { symbol: "Apple", market: "NASDAQ" };
|
|
41
41
|
|
|
42
|
-
const
|
|
42
|
+
const wrappedTools = betterTools([stockQuote], {
|
|
43
43
|
userInput: "Get Apple stock in the US market.",
|
|
44
44
|
repair() {
|
|
45
45
|
return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
|
|
46
46
|
},
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
+
if (!Array.isArray(wrappedTools) || wrappedTools.length === 0) {
|
|
50
|
+
exitWithError(
|
|
51
|
+
"tool wrapping",
|
|
52
|
+
new Error("betterTools returned no wrapped tools for stock_quote")
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const wrappedStockQuote = wrappedTools[0];
|
|
57
|
+
|
|
49
58
|
let wrappedOutput;
|
|
50
59
|
try {
|
|
51
|
-
wrappedOutput = await wrappedStockQuote.invoke(
|
|
60
|
+
wrappedOutput = await wrappedStockQuote.invoke(invalidArgs);
|
|
52
61
|
} catch (error) {
|
|
53
62
|
exitWithError("wrapped stock_quote invocation", error);
|
|
54
63
|
}
|
|
@@ -59,7 +68,7 @@ try {
|
|
|
59
68
|
userInput: "Get Apple stock in the US market.",
|
|
60
69
|
tools: [stockQuote],
|
|
61
70
|
// The tool name is intentionally wrong to demonstrate repair to stock_quote.
|
|
62
|
-
calls: [{ tool: "stock_price", args:
|
|
71
|
+
calls: [{ tool: "stock_price", args: invalidArgs }],
|
|
63
72
|
repair() {
|
|
64
73
|
return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
|
|
65
74
|
},
|
|
@@ -100,19 +109,17 @@ try {
|
|
|
100
109
|
};
|
|
101
110
|
}
|
|
102
111
|
|
|
103
|
-
const repairedCall =
|
|
104
|
-
? reliableResult.calls[0]
|
|
105
|
-
: null;
|
|
112
|
+
const repairedCall = reliableResult?.calls?.[0] ?? null;
|
|
106
113
|
|
|
107
114
|
const report = {
|
|
108
115
|
wrappedTool: {
|
|
109
|
-
before:
|
|
116
|
+
before: invalidArgs,
|
|
110
117
|
after: wrappedOutput,
|
|
111
118
|
},
|
|
112
119
|
reliableToolCalls: {
|
|
113
|
-
before: { tool: "stock_price", args:
|
|
120
|
+
before: { tool: "stock_price", args: invalidArgs },
|
|
114
121
|
repaired: repairedCall,
|
|
115
|
-
diagnostics: reliableResult
|
|
122
|
+
diagnostics: reliableResult?.diagnostics ?? null,
|
|
116
123
|
},
|
|
117
124
|
gatewayRepair: gatewayResult,
|
|
118
125
|
};
|