@botbotgo/better-call 0.1.38 → 0.1.40
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 +18 -7
package/package.json
CHANGED
package/scripts/demo.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { betterTools, repairToolCall, reliableToolCalls } from "../dist/index.js";
|
|
3
3
|
|
|
4
4
|
const json = process.argv.includes("--json");
|
|
5
|
+
const VALID_MARKETS = ["US", "HK", "CN"];
|
|
5
6
|
|
|
6
7
|
function errorMessage(error) {
|
|
7
8
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -30,6 +31,15 @@ function errorDetails(error) {
|
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
function displayValue(value) {
|
|
35
|
+
if (typeof value === "string") {
|
|
36
|
+
const trimmed = value.trim();
|
|
37
|
+
return trimmed === "" ? "(none)" : trimmed;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return value == null ? "(none)" : String(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
function exitWithError(step, error) {
|
|
34
44
|
const message = errorMessage(error);
|
|
35
45
|
|
|
@@ -50,7 +60,7 @@ const stockQuote = {
|
|
|
50
60
|
type: "object",
|
|
51
61
|
properties: {
|
|
52
62
|
ticker: { type: "string" },
|
|
53
|
-
market: { type: "string", enum:
|
|
63
|
+
market: { type: "string", enum: VALID_MARKETS },
|
|
54
64
|
},
|
|
55
65
|
required: ["ticker", "market"],
|
|
56
66
|
additionalProperties: false,
|
|
@@ -66,7 +76,7 @@ const stockQuote = {
|
|
|
66
76
|
throw new Error("Invalid ticker: expected a non-empty string.");
|
|
67
77
|
}
|
|
68
78
|
|
|
69
|
-
if (!
|
|
79
|
+
if (!VALID_MARKETS.includes(market)) {
|
|
70
80
|
throw new Error("Invalid market: expected one of US, HK, CN.");
|
|
71
81
|
}
|
|
72
82
|
|
|
@@ -171,8 +181,7 @@ const gatewayRepair =
|
|
|
171
181
|
errorCause: null,
|
|
172
182
|
};
|
|
173
183
|
|
|
174
|
-
const
|
|
175
|
-
const repairedCall = repairedCalls && repairedCalls.length > 0 ? repairedCalls[0] : null;
|
|
184
|
+
const repairedCall = reliableResult?.calls?.[0] ?? null;
|
|
176
185
|
|
|
177
186
|
const report = {
|
|
178
187
|
wrappedTool: {
|
|
@@ -201,9 +210,11 @@ if (json) {
|
|
|
201
210
|
console.log(` after: ${JSON.stringify(report.reliableToolCalls.repaired)}`);
|
|
202
211
|
console.log("");
|
|
203
212
|
console.log("3. Gateway tool-name repair");
|
|
204
|
-
console.log(` status: ${report.gatewayRepair.status}`);
|
|
205
|
-
console.log(
|
|
206
|
-
|
|
213
|
+
console.log(` status: ${displayValue(report.gatewayRepair.status)}`);
|
|
214
|
+
console.log(
|
|
215
|
+
` tool: ${displayValue(report.gatewayRepair.originalToolName)} -> ${displayValue(report.gatewayRepair.toolName)}`
|
|
216
|
+
);
|
|
217
|
+
console.log(` reason: ${displayValue(report.gatewayRepair.reason)}`);
|
|
207
218
|
console.log("");
|
|
208
219
|
console.log("Run with --json for the full structured result.");
|
|
209
220
|
}
|