@botbotgo/better-call 0.1.44 → 0.1.46
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 +23 -3
package/package.json
CHANGED
package/scripts/demo.mjs
CHANGED
|
@@ -65,6 +65,8 @@ function exitWithError(step, error) {
|
|
|
65
65
|
process.exit(1);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// Demo tool definition: validates ticker and market arguments before returning
|
|
69
|
+
// a normalized quote payload. Accepted markets are US, HK, and CN.
|
|
68
70
|
const stockQuote = {
|
|
69
71
|
name: "stock_quote",
|
|
70
72
|
description: "Get a stock quote.",
|
|
@@ -100,9 +102,27 @@ const stockQuote = {
|
|
|
100
102
|
// "NASDAQ" is not one of the schema-valid markets ("US", "HK", or "CN").
|
|
101
103
|
const intentionallyMalformedArgs = { symbol: "Apple", market: "NASDAQ" };
|
|
102
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Repairs malformed stock quote tool-call input into one schema-valid call.
|
|
107
|
+
*
|
|
108
|
+
* @param {object} [repairInput={}] Optional repair payload that may include
|
|
109
|
+
* `calls[0].args`.
|
|
110
|
+
* @returns {{ tool: string, args: { ticker: string, market: "US" | "HK" | "CN" } }[]}
|
|
111
|
+
* A repaired `stock_quote` call with normalized arguments. Ticker input may
|
|
112
|
+
* be provided as `ticker` or legacy `symbol`; missing values fall back to
|
|
113
|
+
* AAPL, and unsupported markets fall back to US.
|
|
114
|
+
*/
|
|
103
115
|
function repairDemoStockCall(repairInput = {}) {
|
|
116
|
+
const hasUsableArgsShape = (value) =>
|
|
117
|
+
typeof value === "object" &&
|
|
118
|
+
value != null &&
|
|
119
|
+
!Array.isArray(value) &&
|
|
120
|
+
("ticker" in value || "symbol" in value || "market" in value);
|
|
121
|
+
|
|
104
122
|
const attemptedArgs =
|
|
105
|
-
Array.isArray(repairInput?.calls) &&
|
|
123
|
+
Array.isArray(repairInput?.calls) &&
|
|
124
|
+
repairInput.calls.length > 0 &&
|
|
125
|
+
hasUsableArgsShape(repairInput.calls[0]?.args)
|
|
106
126
|
? repairInput.calls[0].args
|
|
107
127
|
: intentionallyMalformedArgs;
|
|
108
128
|
|
|
@@ -202,7 +222,7 @@ try {
|
|
|
202
222
|
);
|
|
203
223
|
}
|
|
204
224
|
|
|
205
|
-
const
|
|
225
|
+
const gatewayRepairResult =
|
|
206
226
|
gatewayResult != null && typeof gatewayResult === "object"
|
|
207
227
|
? gatewayResult
|
|
208
228
|
: createGatewayErrorResult(
|
|
@@ -228,7 +248,7 @@ const report = {
|
|
|
228
248
|
repaired: repairedCall,
|
|
229
249
|
diagnostics: reliableResult?.diagnostics ?? null,
|
|
230
250
|
},
|
|
231
|
-
gatewayRepair,
|
|
251
|
+
gatewayRepair: gatewayRepairResult,
|
|
232
252
|
};
|
|
233
253
|
|
|
234
254
|
if (json) {
|