@botbotgo/better-call 0.1.46 → 0.1.47
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 +13 -9
package/package.json
CHANGED
package/scripts/demo.mjs
CHANGED
|
@@ -100,11 +100,14 @@ const stockQuote = {
|
|
|
100
100
|
|
|
101
101
|
// Intentionally malformed repair input: "symbol" should be "ticker", and
|
|
102
102
|
// "NASDAQ" is not one of the schema-valid markets ("US", "HK", or "CN").
|
|
103
|
-
const
|
|
103
|
+
const DEMO_MALFORMED_INPUT = { symbol: "Apple", market: "NASDAQ" };
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Repairs malformed stock quote tool-call input into one schema-valid call.
|
|
107
107
|
*
|
|
108
|
+
* Diagnostics, when present, come from the surrounding reliableToolCalls run
|
|
109
|
+
* and explain validation/repair decisions such as fallback ticker or market values.
|
|
110
|
+
*
|
|
108
111
|
* @param {object} [repairInput={}] Optional repair payload that may include
|
|
109
112
|
* `calls[0].args`.
|
|
110
113
|
* @returns {{ tool: string, args: { ticker: string, market: "US" | "HK" | "CN" } }[]}
|
|
@@ -124,7 +127,7 @@ function repairDemoStockCall(repairInput = {}) {
|
|
|
124
127
|
repairInput.calls.length > 0 &&
|
|
125
128
|
hasUsableArgsShape(repairInput.calls[0]?.args)
|
|
126
129
|
? repairInput.calls[0].args
|
|
127
|
-
:
|
|
130
|
+
: DEMO_MALFORMED_INPUT;
|
|
128
131
|
|
|
129
132
|
const attemptedTicker =
|
|
130
133
|
typeof attemptedArgs.ticker === "string"
|
|
@@ -133,7 +136,7 @@ function repairDemoStockCall(repairInput = {}) {
|
|
|
133
136
|
? attemptedArgs.symbol
|
|
134
137
|
: "AAPL";
|
|
135
138
|
const normalizedTicker = attemptedTicker.trim().toLowerCase();
|
|
136
|
-
// This demo
|
|
139
|
+
// This demo maps empty input and the "apple" alias to AAPL.
|
|
137
140
|
const ticker =
|
|
138
141
|
normalizedTicker === ""
|
|
139
142
|
? "AAPL"
|
|
@@ -166,9 +169,9 @@ const wrappedStockQuote = wrappedTools[0];
|
|
|
166
169
|
|
|
167
170
|
let wrappedOutput;
|
|
168
171
|
try {
|
|
169
|
-
wrappedOutput = await wrappedStockQuote.invoke(
|
|
172
|
+
wrappedOutput = await wrappedStockQuote.invoke(DEMO_MALFORMED_INPUT);
|
|
170
173
|
} catch (error) {
|
|
171
|
-
const context = `tool=stock_quote args=${JSON.stringify(
|
|
174
|
+
const context = `tool=stock_quote args=${JSON.stringify(DEMO_MALFORMED_INPUT)}`;
|
|
172
175
|
const message = `${errorMessage(error)} (${context})`;
|
|
173
176
|
const contextualError =
|
|
174
177
|
error instanceof Error ? new Error(message, { cause: error }) : new Error(message);
|
|
@@ -181,9 +184,9 @@ try {
|
|
|
181
184
|
userInput: "Get Apple stock in the US market.",
|
|
182
185
|
tools: [stockQuote],
|
|
183
186
|
// Both the tool name and args are intentionally wrong to demonstrate repair:
|
|
184
|
-
// "stock_price" should be "stock_quote";
|
|
187
|
+
// "stock_price" should be "stock_quote"; DEMO_MALFORMED_INPUT uses
|
|
185
188
|
// "symbol"/"NASDAQ" instead of schema-valid stock_quote args.
|
|
186
|
-
calls: [{ tool: "stock_price", args:
|
|
189
|
+
calls: [{ tool: "stock_price", args: DEMO_MALFORMED_INPUT }],
|
|
187
190
|
repair: repairDemoStockCall,
|
|
188
191
|
});
|
|
189
192
|
} catch (error) {
|
|
@@ -240,12 +243,13 @@ const repairedCall =
|
|
|
240
243
|
|
|
241
244
|
const report = {
|
|
242
245
|
wrappedTool: {
|
|
243
|
-
before:
|
|
246
|
+
before: DEMO_MALFORMED_INPUT,
|
|
244
247
|
after: wrappedOutput,
|
|
245
248
|
},
|
|
246
249
|
reliableToolCalls: {
|
|
247
|
-
before: { tool: "stock_price", args:
|
|
250
|
+
before: { tool: "stock_price", args: DEMO_MALFORMED_INPUT },
|
|
248
251
|
repaired: repairedCall,
|
|
252
|
+
// Optional validation/repair metadata; null means this run returned none.
|
|
249
253
|
diagnostics: reliableResult?.diagnostics ?? null,
|
|
250
254
|
},
|
|
251
255
|
gatewayRepair: gatewayRepairResult,
|