@botbotgo/better-call 0.1.42 → 0.1.43
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 +31 -6
package/package.json
CHANGED
package/scripts/demo.mjs
CHANGED
|
@@ -100,11 +100,36 @@ const stockQuote = {
|
|
|
100
100
|
// "NASDAQ" is not one of the schema-valid markets ("US", "HK", or "CN").
|
|
101
101
|
const intentionallyMalformedArgs = { symbol: "Apple", market: "NASDAQ" };
|
|
102
102
|
|
|
103
|
+
function repairDemoStockCall(repairInput = {}) {
|
|
104
|
+
const attemptedArgs =
|
|
105
|
+
Array.isArray(repairInput?.calls) && repairInput.calls[0]?.args != null
|
|
106
|
+
? repairInput.calls[0].args
|
|
107
|
+
: intentionallyMalformedArgs;
|
|
108
|
+
|
|
109
|
+
const attemptedTicker =
|
|
110
|
+
typeof attemptedArgs.ticker === "string"
|
|
111
|
+
? attemptedArgs.ticker
|
|
112
|
+
: typeof attemptedArgs.symbol === "string"
|
|
113
|
+
? attemptedArgs.symbol
|
|
114
|
+
: "AAPL";
|
|
115
|
+
const normalizedTicker = attemptedTicker.trim().toLowerCase();
|
|
116
|
+
const ticker =
|
|
117
|
+
normalizedTicker === "apple" || normalizedTicker === ""
|
|
118
|
+
? "AAPL"
|
|
119
|
+
: normalizedTicker.toUpperCase();
|
|
120
|
+
|
|
121
|
+
const attemptedMarket = typeof attemptedArgs.market === "string" ? attemptedArgs.market : null;
|
|
122
|
+
const market =
|
|
123
|
+
attemptedMarket != null && VALID_MARKETS.includes(attemptedMarket)
|
|
124
|
+
? attemptedMarket
|
|
125
|
+
: "US";
|
|
126
|
+
|
|
127
|
+
return [{ tool: "stock_quote", args: { ticker, market } }];
|
|
128
|
+
}
|
|
129
|
+
|
|
103
130
|
const wrappedTools = betterTools([stockQuote], {
|
|
104
131
|
userInput: "Get Apple stock in the US market.",
|
|
105
|
-
repair
|
|
106
|
-
return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
|
|
107
|
-
},
|
|
132
|
+
repair: repairDemoStockCall,
|
|
108
133
|
});
|
|
109
134
|
|
|
110
135
|
if (!Array.isArray(wrappedTools) || wrappedTools.length === 0) {
|
|
@@ -136,9 +161,7 @@ try {
|
|
|
136
161
|
// "stock_price" should be "stock_quote"; intentionallyMalformedArgs uses
|
|
137
162
|
// "symbol"/"NASDAQ" instead of schema-valid stock_quote args.
|
|
138
163
|
calls: [{ tool: "stock_price", args: intentionallyMalformedArgs }],
|
|
139
|
-
repair
|
|
140
|
-
return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
|
|
141
|
-
},
|
|
164
|
+
repair: repairDemoStockCall,
|
|
142
165
|
});
|
|
143
166
|
} catch (error) {
|
|
144
167
|
exitWithError("tool-call repair", error);
|
|
@@ -182,6 +205,8 @@ const gatewayRepair =
|
|
|
182
205
|
: createGatewayErrorResult("research", "repairToolCall returned no result.");
|
|
183
206
|
|
|
184
207
|
// Missing or empty calls are expected in some demo/error paths; normalize to null for reporting.
|
|
208
|
+
// This demo reports only the first repaired call so the summary stays compact and stable.
|
|
209
|
+
// If multiple calls are present, subsequent calls are intentionally left out of this view.
|
|
185
210
|
const repairedCall =
|
|
186
211
|
Array.isArray(reliableResult?.calls) && reliableResult.calls.length > 0
|
|
187
212
|
? reliableResult.calls[0]
|