@botbotgo/better-call 0.1.27 → 0.1.29

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 +72 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/better-call",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
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
@@ -3,6 +3,23 @@ import { betterTools, repairToolCall, reliableToolCalls } from "../dist/index.js
3
3
 
4
4
  const json = process.argv.includes("--json");
5
5
 
6
+ function errorMessage(error) {
7
+ return error instanceof Error ? error.message : String(error);
8
+ }
9
+
10
+ function exitWithError(step, error) {
11
+ const message = errorMessage(error);
12
+
13
+ if (json) {
14
+ console.error(JSON.stringify({ error: step, message }, null, 2));
15
+ } else {
16
+ console.error(`BetterCall demo failed during ${step}.`);
17
+ console.error(message);
18
+ }
19
+
20
+ process.exit(1);
21
+ }
22
+
6
23
  const stockQuote = {
7
24
  name: "stock_quote",
8
25
  description: "Get a stock quote.",
@@ -29,39 +46,63 @@ const [wrappedStockQuote] = betterTools([stockQuote], {
29
46
  },
30
47
  });
31
48
 
32
- const wrappedOutput = await wrappedStockQuote.invoke(badArgs);
49
+ let wrappedOutput;
50
+ try {
51
+ wrappedOutput = await wrappedStockQuote.invoke(badArgs);
52
+ } catch (error) {
53
+ exitWithError("wrapped stock_quote invocation", error);
54
+ }
33
55
 
34
- const reliableResult = await reliableToolCalls({
35
- userInput: "Get Apple stock in the US market.",
36
- tools: [stockQuote],
37
- // The tool name is intentionally wrong to demonstrate repair to stock_quote.
38
- calls: [{ tool: "stock_price", args: badArgs }],
39
- repair() {
40
- return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
41
- },
42
- });
56
+ let reliableResult;
57
+ try {
58
+ reliableResult = await reliableToolCalls({
59
+ userInput: "Get Apple stock in the US market.",
60
+ tools: [stockQuote],
61
+ // The tool name is intentionally wrong to demonstrate repair to stock_quote.
62
+ calls: [{ tool: "stock_price", args: badArgs }],
63
+ repair() {
64
+ return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
65
+ },
66
+ });
67
+ } catch (error) {
68
+ exitWithError("tool-call repair", error);
69
+ }
43
70
 
44
- const gatewayResult = await repairToolCall({
45
- userInput: "Research the current market.",
46
- visibleTools: [{
47
- name: "task",
48
- description: "Delegate a task to a visible specialist.",
49
- schema: {
50
- type: "object",
51
- properties: {
52
- subagent_type: { type: "string", enum: ["research", "ops"] },
53
- description: { type: "string" },
71
+ let gatewayResult;
72
+ try {
73
+ gatewayResult = await repairToolCall({
74
+ userInput: "Research the current market.",
75
+ visibleTools: [{
76
+ name: "task",
77
+ description: "Delegate a task to a visible specialist.",
78
+ schema: {
79
+ type: "object",
80
+ properties: {
81
+ subagent_type: { type: "string", enum: ["research", "ops"] },
82
+ description: { type: "string" },
83
+ },
84
+ required: ["subagent_type", "description"],
85
+ additionalProperties: false,
54
86
  },
55
- required: ["subagent_type", "description"],
56
- additionalProperties: false,
87
+ }],
88
+ invalidToolName: "research",
89
+ args: {
90
+ subagent_type: "research",
91
+ description: "Research the current market.",
57
92
  },
58
- }],
59
- invalidToolName: "research",
60
- args: {
61
- subagent_type: "research",
62
- description: "Research the current market.",
63
- },
64
- });
93
+ });
94
+ } catch (error) {
95
+ gatewayResult = {
96
+ status: "error",
97
+ originalToolName: "research",
98
+ toolName: null,
99
+ reason: `repairToolCall failed: ${errorMessage(error)}`,
100
+ };
101
+ }
102
+
103
+ const repairedCall = Array.isArray(reliableResult.calls) && reliableResult.calls.length > 0
104
+ ? reliableResult.calls[0]
105
+ : null;
65
106
 
66
107
  const report = {
67
108
  wrappedTool: {
@@ -70,8 +111,8 @@ const report = {
70
111
  },
71
112
  reliableToolCalls: {
72
113
  before: { tool: "stock_price", args: badArgs },
73
- repaired: reliableResult.calls[0],
74
- diagnostics: reliableResult.diagnostics,
114
+ repaired: repairedCall,
115
+ diagnostics: reliableResult.diagnostics ?? null,
75
116
  },
76
117
  gatewayRepair: gatewayResult,
77
118
  };