@botbotgo/better-call 0.1.42 → 0.1.44

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/demo.mjs +38 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/better-call",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "Small-model tool-call reliability layer for LangChain and custom agent runtimes.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/scripts/demo.mjs CHANGED
@@ -100,11 +100,39 @@ 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
+ // This demo falls back to AAPL when no ticker-like value is available.
117
+ const ticker =
118
+ normalizedTicker === ""
119
+ ? "AAPL"
120
+ : normalizedTicker === "apple"
121
+ ? "AAPL"
122
+ : normalizedTicker.toUpperCase();
123
+
124
+ const attemptedMarket = typeof attemptedArgs.market === "string" ? attemptedArgs.market : null;
125
+ const market =
126
+ attemptedMarket != null && VALID_MARKETS.includes(attemptedMarket)
127
+ ? attemptedMarket
128
+ : "US";
129
+
130
+ return [{ tool: "stock_quote", args: { ticker, market } }];
131
+ }
132
+
103
133
  const wrappedTools = betterTools([stockQuote], {
104
134
  userInput: "Get Apple stock in the US market.",
105
- repair() {
106
- return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
107
- },
135
+ repair: repairDemoStockCall,
108
136
  });
109
137
 
110
138
  if (!Array.isArray(wrappedTools) || wrappedTools.length === 0) {
@@ -136,9 +164,7 @@ try {
136
164
  // "stock_price" should be "stock_quote"; intentionallyMalformedArgs uses
137
165
  // "symbol"/"NASDAQ" instead of schema-valid stock_quote args.
138
166
  calls: [{ tool: "stock_price", args: intentionallyMalformedArgs }],
139
- repair() {
140
- return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
141
- },
167
+ repair: repairDemoStockCall,
142
168
  });
143
169
  } catch (error) {
144
170
  exitWithError("tool-call repair", error);
@@ -179,9 +205,14 @@ try {
179
205
  const gatewayRepair =
180
206
  gatewayResult != null && typeof gatewayResult === "object"
181
207
  ? gatewayResult
182
- : createGatewayErrorResult("research", "repairToolCall returned no result.");
208
+ : createGatewayErrorResult(
209
+ "research",
210
+ "repairToolCall returned an invalid result (expected object)."
211
+ );
183
212
 
184
213
  // Missing or empty calls are expected in some demo/error paths; normalize to null for reporting.
214
+ // This demo reports only the first repaired call so the summary stays compact and stable.
215
+ // If multiple calls are present, subsequent calls are intentionally left out of this view.
185
216
  const repairedCall =
186
217
  Array.isArray(reliableResult?.calls) && reliableResult.calls.length > 0
187
218
  ? reliableResult.calls[0]