@botbotgo/better-call 0.1.47 → 0.1.48
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 -18
package/package.json
CHANGED
package/scripts/demo.mjs
CHANGED
|
@@ -52,6 +52,19 @@ function displayValue(value) {
|
|
|
52
52
|
return value == null ? "(none)" : String(value);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
function hasUsableArgsShape(value) {
|
|
56
|
+
return (
|
|
57
|
+
typeof value === "object" &&
|
|
58
|
+
value != null &&
|
|
59
|
+
!Array.isArray(value) &&
|
|
60
|
+
("ticker" in value || "symbol" in value || "market" in value)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createDemoMalformedInput() {
|
|
65
|
+
return { symbol: "Apple", market: "NASDAQ" };
|
|
66
|
+
}
|
|
67
|
+
|
|
55
68
|
function exitWithError(step, error) {
|
|
56
69
|
const message = errorMessage(error);
|
|
57
70
|
|
|
@@ -98,10 +111,6 @@ const stockQuote = {
|
|
|
98
111
|
},
|
|
99
112
|
};
|
|
100
113
|
|
|
101
|
-
// Intentionally malformed repair input: "symbol" should be "ticker", and
|
|
102
|
-
// "NASDAQ" is not one of the schema-valid markets ("US", "HK", or "CN").
|
|
103
|
-
const DEMO_MALFORMED_INPUT = { symbol: "Apple", market: "NASDAQ" };
|
|
104
|
-
|
|
105
114
|
/**
|
|
106
115
|
* Repairs malformed stock quote tool-call input into one schema-valid call.
|
|
107
116
|
*
|
|
@@ -116,18 +125,12 @@ const DEMO_MALFORMED_INPUT = { symbol: "Apple", market: "NASDAQ" };
|
|
|
116
125
|
* AAPL, and unsupported markets fall back to US.
|
|
117
126
|
*/
|
|
118
127
|
function repairDemoStockCall(repairInput = {}) {
|
|
119
|
-
const hasUsableArgsShape = (value) =>
|
|
120
|
-
typeof value === "object" &&
|
|
121
|
-
value != null &&
|
|
122
|
-
!Array.isArray(value) &&
|
|
123
|
-
("ticker" in value || "symbol" in value || "market" in value);
|
|
124
|
-
|
|
125
128
|
const attemptedArgs =
|
|
126
129
|
Array.isArray(repairInput?.calls) &&
|
|
127
130
|
repairInput.calls.length > 0 &&
|
|
128
131
|
hasUsableArgsShape(repairInput.calls[0]?.args)
|
|
129
132
|
? repairInput.calls[0].args
|
|
130
|
-
:
|
|
133
|
+
: createDemoMalformedInput();
|
|
131
134
|
|
|
132
135
|
const attemptedTicker =
|
|
133
136
|
typeof attemptedArgs.ticker === "string"
|
|
@@ -165,13 +168,23 @@ if (!Array.isArray(wrappedTools) || wrappedTools.length === 0) {
|
|
|
165
168
|
);
|
|
166
169
|
}
|
|
167
170
|
|
|
168
|
-
const wrappedStockQuote = wrappedTools
|
|
171
|
+
const wrappedStockQuote = wrappedTools.find((tool) => tool?.name === "stock_quote");
|
|
172
|
+
if (wrappedStockQuote == null) {
|
|
173
|
+
exitWithError(
|
|
174
|
+
"tool wrapping",
|
|
175
|
+
new Error("betterTools did not return a wrapped stock_quote tool")
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Intentionally malformed demo input: "symbol" should be "ticker", and
|
|
180
|
+
// "NASDAQ" is not one of the schema-valid markets ("US", "HK", or "CN").
|
|
181
|
+
const demoMalformedInput = createDemoMalformedInput();
|
|
169
182
|
|
|
170
183
|
let wrappedOutput;
|
|
171
184
|
try {
|
|
172
|
-
wrappedOutput = await wrappedStockQuote.invoke(
|
|
185
|
+
wrappedOutput = await wrappedStockQuote.invoke(demoMalformedInput);
|
|
173
186
|
} catch (error) {
|
|
174
|
-
const context = `tool=stock_quote args=${JSON.stringify(
|
|
187
|
+
const context = `tool=stock_quote args=${JSON.stringify(demoMalformedInput)}`;
|
|
175
188
|
const message = `${errorMessage(error)} (${context})`;
|
|
176
189
|
const contextualError =
|
|
177
190
|
error instanceof Error ? new Error(message, { cause: error }) : new Error(message);
|
|
@@ -184,9 +197,9 @@ try {
|
|
|
184
197
|
userInput: "Get Apple stock in the US market.",
|
|
185
198
|
tools: [stockQuote],
|
|
186
199
|
// Both the tool name and args are intentionally wrong to demonstrate repair:
|
|
187
|
-
// "stock_price" should be "stock_quote";
|
|
200
|
+
// "stock_price" should be "stock_quote"; demoMalformedInput uses
|
|
188
201
|
// "symbol"/"NASDAQ" instead of schema-valid stock_quote args.
|
|
189
|
-
calls: [{ tool: "stock_price", args:
|
|
202
|
+
calls: [{ tool: "stock_price", args: demoMalformedInput }],
|
|
190
203
|
repair: repairDemoStockCall,
|
|
191
204
|
});
|
|
192
205
|
} catch (error) {
|
|
@@ -243,11 +256,11 @@ const repairedCall =
|
|
|
243
256
|
|
|
244
257
|
const report = {
|
|
245
258
|
wrappedTool: {
|
|
246
|
-
before:
|
|
259
|
+
before: demoMalformedInput,
|
|
247
260
|
after: wrappedOutput,
|
|
248
261
|
},
|
|
249
262
|
reliableToolCalls: {
|
|
250
|
-
before: { tool: "stock_price", args:
|
|
263
|
+
before: { tool: "stock_price", args: demoMalformedInput },
|
|
251
264
|
repaired: repairedCall,
|
|
252
265
|
// Optional validation/repair metadata; null means this run returned none.
|
|
253
266
|
diagnostics: reliableResult?.diagnostics ?? null,
|