@botbotgo/better-call 0.1.45 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/demo.mjs +16 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/better-call",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
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
@@ -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,6 +102,16 @@ 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 = {}) {
104
116
  const hasUsableArgsShape = (value) =>
105
117
  typeof value === "object" &&
@@ -108,7 +120,9 @@ function repairDemoStockCall(repairInput = {}) {
108
120
  ("ticker" in value || "symbol" in value || "market" in value);
109
121
 
110
122
  const attemptedArgs =
111
- Array.isArray(repairInput?.calls) && hasUsableArgsShape(repairInput.calls[0]?.args)
123
+ Array.isArray(repairInput?.calls) &&
124
+ repairInput.calls.length > 0 &&
125
+ hasUsableArgsShape(repairInput.calls[0]?.args)
112
126
  ? repairInput.calls[0].args
113
127
  : intentionallyMalformedArgs;
114
128
 
@@ -118,8 +132,7 @@ function repairDemoStockCall(repairInput = {}) {
118
132
  : typeof attemptedArgs.symbol === "string"
119
133
  ? attemptedArgs.symbol
120
134
  : "AAPL";
121
- const normalizedTicker =
122
- typeof attemptedTicker === "string" ? attemptedTicker.trim().toLowerCase() : "aapl";
135
+ const normalizedTicker = attemptedTicker.trim().toLowerCase();
123
136
  // This demo falls back to AAPL when no ticker-like value is available.
124
137
  const ticker =
125
138
  normalizedTicker === ""