@botbotgo/better-call 0.1.32 → 0.1.34
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 +16 -8
package/package.json
CHANGED
package/scripts/demo.mjs
CHANGED
|
@@ -37,7 +37,9 @@ const stockQuote = {
|
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
// Intentionally malformed repair input: "symbol" should be "ticker", and
|
|
41
|
+
// "NASDAQ" is not one of the schema-valid markets ("US", "HK", or "CN").
|
|
42
|
+
const malformedRepairArgs = { symbol: "Apple", market: "NASDAQ" };
|
|
41
43
|
|
|
42
44
|
const wrappedTools = betterTools([stockQuote], {
|
|
43
45
|
userInput: "Get Apple stock in the US market.",
|
|
@@ -57,9 +59,13 @@ const wrappedStockQuote = wrappedTools[0];
|
|
|
57
59
|
|
|
58
60
|
let wrappedOutput;
|
|
59
61
|
try {
|
|
60
|
-
wrappedOutput = await wrappedStockQuote.invoke(
|
|
62
|
+
wrappedOutput = await wrappedStockQuote.invoke(malformedRepairArgs);
|
|
61
63
|
} catch (error) {
|
|
62
|
-
|
|
64
|
+
const context = `tool=stock_quote args=${JSON.stringify(malformedRepairArgs)}`;
|
|
65
|
+
const message = `${errorMessage(error)} (${context})`;
|
|
66
|
+
const contextualError =
|
|
67
|
+
error instanceof Error ? new Error(message, { cause: error }) : new Error(message);
|
|
68
|
+
exitWithError("wrapped stock_quote invocation", contextualError);
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
let reliableResult = null;
|
|
@@ -67,8 +73,10 @@ try {
|
|
|
67
73
|
reliableResult = await reliableToolCalls({
|
|
68
74
|
userInput: "Get Apple stock in the US market.",
|
|
69
75
|
tools: [stockQuote],
|
|
70
|
-
//
|
|
71
|
-
|
|
76
|
+
// Both the tool name and args are intentionally wrong to demonstrate repair:
|
|
77
|
+
// "stock_price" should be "stock_quote"; malformedRepairArgs uses
|
|
78
|
+
// "symbol"/"NASDAQ" instead of schema-valid stock_quote args.
|
|
79
|
+
calls: [{ tool: "stock_price", args: malformedRepairArgs }],
|
|
72
80
|
repair() {
|
|
73
81
|
return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
|
|
74
82
|
},
|
|
@@ -113,11 +121,11 @@ const repairedCall = reliableResult?.calls?.[0] ?? null;
|
|
|
113
121
|
|
|
114
122
|
const report = {
|
|
115
123
|
wrappedTool: {
|
|
116
|
-
before:
|
|
124
|
+
before: malformedRepairArgs,
|
|
117
125
|
after: wrappedOutput,
|
|
118
126
|
},
|
|
119
127
|
reliableToolCalls: {
|
|
120
|
-
before: { tool: "stock_price", args:
|
|
128
|
+
before: { tool: "stock_price", args: malformedRepairArgs },
|
|
121
129
|
repaired: repairedCall,
|
|
122
130
|
diagnostics: reliableResult?.diagnostics ?? null,
|
|
123
131
|
},
|
|
@@ -140,7 +148,7 @@ if (json) {
|
|
|
140
148
|
console.log("3. Gateway tool-name repair");
|
|
141
149
|
console.log(` status: ${report.gatewayRepair.status}`);
|
|
142
150
|
console.log(` tool: ${report.gatewayRepair.originalToolName} -> ${report.gatewayRepair.toolName}`);
|
|
143
|
-
console.log(` reason: ${report.gatewayRepair.reason}`);
|
|
151
|
+
console.log(` reason: ${report.gatewayRepair.reason ?? "(none)"}`);
|
|
144
152
|
console.log("");
|
|
145
153
|
console.log("Run with --json for the full structured result.");
|
|
146
154
|
}
|