@botbotgo/better-call 0.1.26 → 0.1.28

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.
@@ -12,7 +12,7 @@ LLM tool calling has a boring failure mode that shows up constantly with small m
12
12
 
13
13
  The model knows a tool is needed, but the actual call is not executable.
14
14
 
15
- It may pick a near-miss tool name, send `symbol` instead of `ticker`, use an enum value the schema rejects, include extra fields, or emit raw tool-call-shaped text. If your runtime sends that straight to a real tool, the best case is a failed request. The worse case is the wrong operation reaching production code.
15
+ It may pick a near-miss tool name, send `symbol` instead of `ticker`, use an enum value the schema rejects, include extra fields, or emit raw tool-call-shaped text. If your runtime sends that straight to a real tool, the best case is a failed request. The worst case is the wrong operation reaching production code.
16
16
 
17
17
  BetterCall is a small TypeScript reliability layer for that boundary.
18
18
 
@@ -10,10 +10,10 @@ const result = await reliableToolCalls({
10
10
  tools,
11
11
  calls,
12
12
  repair: async ({ userInput, tools, calls, issues }) => {
13
- const response = await fetch(`${baseUrl}/chat/completions`, {
13
+ const response = await fetch(`${baseUrl}/v1/chat/completions`, {
14
14
  method: "POST",
15
15
  headers: {
16
- "authorization": `Bearer ${apiKey}`,
16
+ "Authorization": `Bearer ${apiKey}`,
17
17
  "content-type": "application/json",
18
18
  },
19
19
  body: JSON.stringify({
@@ -33,5 +33,5 @@ The Ollama and OpenAI-compatible examples expect local model endpoints:
33
33
 
34
34
  ```bash
35
35
  OLLAMA_BASE_URL=http://127.0.0.1:11434 OLLAMA_MODEL=granite4.1:3b node examples/ollama-small-model.mjs
36
- OPENAI_BASE_URL=http://127.0.0.1:8000/v1 OPENAI_MODEL=local-model node examples/adapters/openai-compatible-repair.mjs
36
+ OPENAI_BASE_URL=http://127.0.0.1:8000 OPENAI_MODEL=local-model node examples/adapters/openai-compatible-repair.mjs
37
37
  ```
@@ -1,6 +1,6 @@
1
1
  import { reliableToolCalls } from "../../dist/index.js";
2
2
 
3
- const baseUrl = process.env.OPENAI_BASE_URL ?? "http://127.0.0.1:8000/v1";
3
+ const baseUrl = process.env.OPENAI_BASE_URL ?? "http://127.0.0.1:8000";
4
4
  const model = process.env.OPENAI_MODEL ?? "local-model";
5
5
  const apiKey = process.env.OPENAI_API_KEY ?? "not-needed-for-local";
6
6
 
@@ -23,10 +23,10 @@ const result = await reliableToolCalls({
23
23
  tools,
24
24
  calls: [{ tool: "stock_price", args: { symbol: "Apple", market: "NASDAQ" } }],
25
25
  repair: async ({ userInput, tools, calls, issues }) => {
26
- const response = await fetch(`${baseUrl}/chat/completions`, {
26
+ const response = await fetch(`${baseUrl}/v1/chat/completions`, {
27
27
  method: "POST",
28
28
  headers: {
29
- "authorization": `Bearer ${apiKey}`,
29
+ "Authorization": `Bearer ${apiKey}`,
30
30
  "content-type": "application/json",
31
31
  },
32
32
  body: JSON.stringify({
@@ -17,12 +17,12 @@ const tools = [{
17
17
  },
18
18
  }];
19
19
 
20
- const badCall = { tool: "stock_price", args: { symbol: "Apple", market: "NASDAQ" } };
20
+ const invalidToolCall = { tool: "stock_price", args: { symbol: "Apple", market: "NASDAQ" } };
21
21
 
22
22
  const result = await reliableToolCalls({
23
23
  userInput: "Get Apple stock in the US market.",
24
24
  tools,
25
- calls: [badCall],
25
+ calls: [invalidToolCall],
26
26
  repair: async ({ userInput, tools, calls, issues }) => {
27
27
  const prompt = [
28
28
  "Return corrected JSON only as {\"calls\":[{\"tool\":\"name\",\"args\":{}}]}.",
@@ -43,4 +43,4 @@ const result = await reliableToolCalls({
43
43
  },
44
44
  });
45
45
 
46
- console.log(JSON.stringify({ model, badCall, result }, null, 2));
46
+ console.log(JSON.stringify({ model, invalidToolCall, result }, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/better-call",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
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,38 +46,59 @@ 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
- calls: [{ tool: "stock_price", args: badArgs }],
38
- repair() {
39
- return [{ tool: "stock_quote", args: { ticker: "AAPL", market: "US" } }];
40
- },
41
- });
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
+ }
42
70
 
43
- const gatewayResult = await repairToolCall({
44
- userInput: "Research the current market.",
45
- visibleTools: [{
46
- name: "task",
47
- description: "Delegate a task to a visible specialist.",
48
- schema: {
49
- type: "object",
50
- properties: {
51
- subagent_type: { type: "string", enum: ["research", "ops"] },
52
- 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,
53
86
  },
54
- required: ["subagent_type", "description"],
55
- additionalProperties: false,
87
+ }],
88
+ invalidToolName: "research",
89
+ args: {
90
+ subagent_type: "research",
91
+ description: "Research the current market.",
56
92
  },
57
- }],
58
- invalidToolName: "research",
59
- args: {
60
- subagent_type: "research",
61
- description: "Research the current market.",
62
- },
63
- });
93
+ });
94
+ } catch (error) {
95
+ gatewayResult = {
96
+ status: "error",
97
+ originalToolName: "research",
98
+ toolName: null,
99
+ reason: `repairToolCall failed: ${errorMessage(error)}`,
100
+ };
101
+ }
64
102
 
65
103
  const report = {
66
104
  wrappedTool: {