@botbotgo/better-call 0.1.41 → 0.1.42

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 +25 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/better-call",
3
- "version": "0.1.41",
3
+ "version": "0.1.42",
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
@@ -8,6 +8,18 @@ function errorMessage(error) {
8
8
  return error instanceof Error ? error.message : String(error);
9
9
  }
10
10
 
11
+ function createGatewayErrorResult(originalToolName, reason, details = {}) {
12
+ return {
13
+ status: "error",
14
+ originalToolName,
15
+ toolName: null,
16
+ reason,
17
+ errorType: details.type ?? null,
18
+ errorMessage: details.message ?? null,
19
+ errorCause: details.cause ?? null,
20
+ };
21
+ }
22
+
11
23
  function errorDetails(error) {
12
24
  if (error instanceof Error) {
13
25
  const causeMessage =
@@ -86,7 +98,7 @@ const stockQuote = {
86
98
 
87
99
  // Intentionally malformed repair input: "symbol" should be "ticker", and
88
100
  // "NASDAQ" is not one of the schema-valid markets ("US", "HK", or "CN").
89
- const malformedRepairArgs = { symbol: "Apple", market: "NASDAQ" };
101
+ const intentionallyMalformedArgs = { symbol: "Apple", market: "NASDAQ" };
90
102
 
91
103
  const wrappedTools = betterTools([stockQuote], {
92
104
  userInput: "Get Apple stock in the US market.",
@@ -106,9 +118,9 @@ const wrappedStockQuote = wrappedTools[0];
106
118
 
107
119
  let wrappedOutput;
108
120
  try {
109
- wrappedOutput = await wrappedStockQuote.invoke(malformedRepairArgs);
121
+ wrappedOutput = await wrappedStockQuote.invoke(intentionallyMalformedArgs);
110
122
  } catch (error) {
111
- const context = `tool=stock_quote args=${JSON.stringify(malformedRepairArgs)}`;
123
+ const context = `tool=stock_quote args=${JSON.stringify(intentionallyMalformedArgs)}`;
112
124
  const message = `${errorMessage(error)} (${context})`;
113
125
  const contextualError =
114
126
  error instanceof Error ? new Error(message, { cause: error }) : new Error(message);
@@ -121,9 +133,9 @@ try {
121
133
  userInput: "Get Apple stock in the US market.",
122
134
  tools: [stockQuote],
123
135
  // Both the tool name and args are intentionally wrong to demonstrate repair:
124
- // "stock_price" should be "stock_quote"; malformedRepairArgs uses
136
+ // "stock_price" should be "stock_quote"; intentionallyMalformedArgs uses
125
137
  // "symbol"/"NASDAQ" instead of schema-valid stock_quote args.
126
- calls: [{ tool: "stock_price", args: malformedRepairArgs }],
138
+ calls: [{ tool: "stock_price", args: intentionallyMalformedArgs }],
127
139
  repair() {
128
140
  return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
129
141
  },
@@ -157,29 +169,17 @@ try {
157
169
  });
158
170
  } catch (error) {
159
171
  const details = errorDetails(error);
160
- gatewayResult = {
161
- status: "error",
162
- originalToolName: "research",
163
- toolName: null,
164
- reason: `repairToolCall failed: ${details.message}`,
165
- errorType: details.type,
166
- errorMessage: details.message,
167
- errorCause: details.cause,
168
- };
172
+ gatewayResult = createGatewayErrorResult(
173
+ "research",
174
+ `repairToolCall failed: ${details.message}`,
175
+ details
176
+ );
169
177
  }
170
178
 
171
179
  const gatewayRepair =
172
180
  gatewayResult != null && typeof gatewayResult === "object"
173
181
  ? gatewayResult
174
- : {
175
- status: "error",
176
- originalToolName: "research",
177
- toolName: null,
178
- reason: "repairToolCall returned no result.",
179
- errorType: null,
180
- errorMessage: null,
181
- errorCause: null,
182
- };
182
+ : createGatewayErrorResult("research", "repairToolCall returned no result.");
183
183
 
184
184
  // Missing or empty calls are expected in some demo/error paths; normalize to null for reporting.
185
185
  const repairedCall =
@@ -189,11 +189,11 @@ const repairedCall =
189
189
 
190
190
  const report = {
191
191
  wrappedTool: {
192
- before: malformedRepairArgs,
192
+ before: intentionallyMalformedArgs,
193
193
  after: wrappedOutput,
194
194
  },
195
195
  reliableToolCalls: {
196
- before: { tool: "stock_price", args: malformedRepairArgs },
196
+ before: { tool: "stock_price", args: intentionallyMalformedArgs },
197
197
  repaired: repairedCall,
198
198
  diagnostics: reliableResult?.diagnostics ?? null,
199
199
  },