@botbotgo/better-call 0.1.17 → 0.1.19

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/README.md CHANGED
@@ -4,103 +4,124 @@
4
4
 
5
5
  # BetterCall
6
6
 
7
- **One-line wrapper. Eight full BFCL remote runs completed. Best: 73.4% → 83.8%.**
7
+ [![npm version](https://img.shields.io/npm/v/@botbotgo/better-call.svg)](https://www.npmjs.com/package/@botbotgo/better-call)
8
+ [![license](https://img.shields.io/npm/l/@botbotgo/better-call.svg)](LICENSE)
9
+ [![release](https://github.com/botbotgo/better-call/actions/workflows/release.yml/badge.svg)](https://github.com/botbotgo/better-call/actions/workflows/release.yml)
10
+
11
+ BetterCall is a small runtime reliability layer for LangChain and LLM tool calls.
12
+
13
+ Wrap your existing tools, validate model-generated calls before execution, and optionally ask a repair model to fix rejected calls. In full BFCL v4 remote Ollama runs, the best measured lift was `granite4.1:3b`: **73.4% raw -> 83.8% with BetterCall**.
8
14
 
9
15
  ```ts
16
+ import { betterTools } from "@botbotgo/better-call";
17
+
10
18
  const tools = betterTools([searchTool, calculatorTool]);
11
19
  ```
12
20
 
13
- No model means validate + block only. Add `repairModel` when you want automatic repair.
21
+ No model means validate and block only. Add `repairModel` when you want automatic repair.
22
+
23
+ ## Why BetterCall?
24
+
25
+ Small models often know that a tool is needed but still fail at the boundary: wrong tool names, malformed arguments, schema drift, extra fields, or raw tool-call-shaped text. BetterCall sits at that boundary and gives you a typed, auditable way to accept, repair, or reject the call before the real tool runs.
14
26
 
15
- ## Install
27
+ - Use your existing LangChain-style tools.
28
+ - Accept JSON Schema, Zod object schemas, or Zod-shaped records.
29
+ - Block invalid calls when no repair model is configured.
30
+ - Repair rejected calls with a LangChain chat model or custom callback.
31
+ - Keep lower-level primitives available for custom runtimes and gateways.
32
+
33
+ ## Installation
16
34
 
17
35
  ```bash
18
36
  npm install @botbotgo/better-call
19
37
  ```
20
38
 
21
- ## LangGraph Quick Start
39
+ ## Quick Start
40
+
41
+ LangChain tools work directly:
22
42
 
23
43
  ```ts
44
+ import { tool } from "@langchain/core/tools";
24
45
  import { betterTools } from "@botbotgo/better-call";
46
+ import { z } from "zod";
25
47
 
26
- // Validate + block: stop bad calls before execution.
27
- const tools = betterTools([searchTool, calculatorTool]);
28
- ```
29
-
30
- Pass a repair model to let BetterCall fix rejected calls automatically. This can be the same chat model your agent uses, or a separate cheaper/stronger model dedicated to repair:
31
-
32
- ```ts
33
- // Validate + repair: validate, repair with a model, validate again, then execute.
34
- const tools = betterTools([searchTool, calculatorTool], {
35
- repairModel: model,
48
+ const searchTool = tool(async ({ query }) => search(query), {
49
+ name: "search",
50
+ description: "Search the web.",
51
+ schema: z.object({ query: z.string() }),
36
52
  });
37
- ```
38
-
39
- ## Run The BFCL Benchmark
40
53
 
41
- ```bash
42
- npm run bench:bfcl
54
+ const tools = betterTools([searchTool]);
43
55
  ```
44
56
 
45
- This prints the BFCL v4 targeted weak-category table used above. It is a BetterCall wrapper benchmark, not an official leaderboard submission.
46
-
47
- For the full official BFCL v4 reproduction, use Berkeley's published checkpoint/package: commit `f7cf735` or `pip install bfcl-eval==2025.12.17`.
57
+ The same wrapper works for any tool with `name`, `schema`, and `invoke(input)`:
48
58
 
49
- To run the real-model benchmark against your own Ollama endpoint, install the BFCL package and point BetterCall at the package data:
50
-
51
- ```bash
52
- python3 -m venv /tmp/better-call-bfcl-venv
53
- /tmp/better-call-bfcl-venv/bin/pip install "bfcl-eval==2025.12.17" soundfile
59
+ ```ts
60
+ import { betterTools } from "@botbotgo/better-call";
54
61
 
55
- OLLAMA_BASE_URL=http://127.0.0.1:11434 \
56
- BENCH_MODELS=qwen3.5:0.8b \
57
- BENCH_CATEGORIES=all \
58
- BENCH_CASES_PER_CATEGORY=0 \
59
- npm run bench:bfcl:real
62
+ const tools = betterTools([searchTool, calculatorTool]);
60
63
  ```
61
64
 
62
- For long categories, resume or shard a category with `BENCH_CASE_OFFSET` and `BENCH_CASES_PER_CATEGORY`; the benchmark still uses real model calls and counts request errors/timeouts as incorrect.
65
+ To repair rejected calls automatically, pass a LangChain chat model or any model with `invoke(input)`:
63
66
 
64
- For a model/category matrix run, set `OLLAMA_BASE_URL` and run:
67
+ ```ts
68
+ import { ChatOpenAI } from "@langchain/openai";
69
+ import { betterTools } from "@botbotgo/better-call";
65
70
 
66
- ```bash
67
- OLLAMA_BASE_URL=http://127.0.0.1:11434 npm run bench:bfcl:remote-small-all
71
+ const repairModel = new ChatOpenAI({ model: "gpt-4.1-mini" });
72
+
73
+ const tools = betterTools([searchTool, calculatorTool], {
74
+ repairModel,
75
+ });
68
76
  ```
69
77
 
70
- The runner does real `/api/chat` tool-call requests. Benchmark JSON redacts the endpoint by default; set `BENCH_SHOW_ENDPOINT=1` only for private debugging.
78
+ BetterCall validates, repairs rejected calls, validates again, and only then invokes the original tool.
71
79
 
72
80
  ## What It Catches
73
81
 
74
- | Category | Failures | Example |
75
- | --- | --- | --- |
76
- | Tool selection | Unknown tool | `stock_price` instead of `stock_quote` |
77
- | Tool selection | Irrelevant call | Model calls a tool when no tool should be used |
78
- | Arguments | Missing required arg | Missing required `ticker` |
79
- | Arguments | Wrong arg name | `symbol` instead of `ticker` |
80
- | Arguments | Wrong type | `"3"` where an integer is required |
81
- | Schema | Invalid enum | `NASDAQ` where only `US`, `HK`, `CN` are allowed |
82
- | Schema | Extra arg | `currency` when `additionalProperties: false` |
83
- | Policy | Semantic validator rejection | Domain-specific validator rejects unsafe args |
84
-
85
- In validate + block mode, BetterCall rejects these calls before execution. With `repairModel`, it asks the model to fix rejected calls, validates again, and only then executes.
82
+ | Area | Examples |
83
+ | --- | --- |
84
+ | Tool selection | Unknown tools, irrelevant tool calls |
85
+ | Arguments | Missing required args, wrong arg names, extra args |
86
+ | Schema | Wrong types, invalid enums, `additionalProperties: false` violations |
87
+ | Policy | Expected no tool call, expected some tool call |
88
+ | Semantic validation | Domain-specific validator rejects unsafe args |
86
89
 
87
90
  ## API
88
91
 
89
- ### `betterTools`
92
+ ### `betterTools(tools, options?)`
90
93
 
91
- Wrap a LangGraph-style tools array.
94
+ Wraps an existing tool array. Each tool must expose `name` and `invoke(input)`. BetterCall preserves the original tool shape and wraps `invoke`.
92
95
 
93
96
  ```ts
94
- // Validate + block.
95
- const tools = betterTools([searchTool, calculatorTool]);
97
+ const guarded = betterTools([searchTool]);
96
98
 
97
- // Validate + repair.
98
- const toolsWithRepair = betterTools([searchTool, calculatorTool], { repairModel: model });
99
+ const repaired = betterTools([searchTool], {
100
+ repairModel: model,
101
+ });
99
102
  ```
100
103
 
101
- `options` is optional. Each tool must expose `name` and `invoke(input)`. BetterCall preserves each tool's shape and wraps `invoke`.
104
+ Options:
102
105
 
103
- Tool schemas can be plain JSON Schema, Zod object schemas, or Zod-shaped records:
106
+ | Option | Purpose |
107
+ | --- | --- |
108
+ | `repairModel` | Model used by the default repair prompt/parser |
109
+ | `repair` | Custom repair function |
110
+ | `mode` | `"guard"`, `"repair"`, or `"review"` |
111
+ | `policy` | Expected call policy, such as `expected: "none"` |
112
+ | `validate` | Custom semantic validator |
113
+ | `schema` | Override the wrapped tool schema |
114
+ | `userInput` | Original user input or a function that derives it from tool args |
115
+
116
+ Modes:
117
+
118
+ | Mode | Behavior |
119
+ | --- | --- |
120
+ | no model / `"guard"` | Validate and block unsafe calls |
121
+ | `"repair"` or `repairModel` | Repair rejected calls, then validate again |
122
+ | `"review"` | Ask for a full self-check even when calls pass schema |
123
+
124
+ Tool schemas can be JSON Schema, Zod object schemas, or Zod-shaped records:
104
125
 
105
126
  ```ts
106
127
  import { z } from "zod";
@@ -117,121 +138,115 @@ const tools = betterTools([
117
138
  ]);
118
139
  ```
119
140
 
120
- BetterCall converts Zod schemas to JSON Schema before validation and repair. If your runtime already converts schemas, passing JSON Schema directly remains the lowest-dependency path.
141
+ ### `repairToolCall(input)`
121
142
 
122
- The lower-level `guardToolCalls(...)` and `reliableToolCalls(...)` APIs accept the same schema shapes in `ToolDefinition.schema`. For custom runtime adapters, `normalizeToolSchema(schema)` is also exported so tool metadata can share BetterCall's exact conversion behavior.
143
+ Use this at an upstream adapter or tool gateway boundary when the model emitted an invalid tool call, unavailable tool name, or raw tool-call-shaped text before execution:
123
144
 
124
- Without `repairModel` or `repair`, BetterCall validates and blocks unsafe calls instead of fixing them. `repairModel` only needs an `invoke(input)` method, such as a LangChain chat model. If it is provided, BetterCall supplies the repair prompt and JSON parser.
145
+ ```ts
146
+ import { repairToolCall } from "@botbotgo/better-call";
147
+
148
+ const repaired = await repairToolCall({
149
+ userInput: "Research this market.",
150
+ visibleTools: [taskTool],
151
+ hiddenTools: blockedTools,
152
+ invalidToolName: "ls",
153
+ args: { name: "research", query: "Research this market." },
154
+ repairModel,
155
+ });
156
+ ```
125
157
 
126
- Modes:
158
+ The result is structured for runtime traces and audit decisions:
127
159
 
128
- | Mode | Behavior |
129
- | --- | --- |
130
- | no model | Validate and block only |
131
- | `repairModel` | Validate, repair rejected calls, then validate again |
132
- | custom `repair` | Use your own repair function |
133
- | `review` | Ask for a full self-check even when calls pass schema |
160
+ ```ts
161
+ {
162
+ status: "repaired", // "repaired" | "rejected" | "unchanged"
163
+ toolName: "task",
164
+ args: { subagent_type: "research", description: "Research this market." },
165
+ confidence: 0.8,
166
+ reason: "repair function selected a visible tool and schema-compatible arguments",
167
+ originalToolName: "ls",
168
+ originalArgs: { name: "research", query: "Research this market." },
169
+ violations: []
170
+ }
171
+ ```
134
172
 
135
- Default recommendation: start with validate + block, then add `repairModel` for small models or unreliable tool callers. `review` is more expensive and model-dependent.
173
+ BetterCall only repairs an existing tool call or tool-call-shaped intent. It does not invent a tool call from an ordinary final answer.
136
174
 
137
- `irrelevance` is one validation failure type: the model called a tool when no tool should be called. BetterCall also validates tool names, argument names, JSON schema, types, enums, and semantic validators.
175
+ ### Lower-level exports
138
176
 
139
- ## Benchmark
177
+ - `guardToolCalls(...)`
178
+ - `reliableToolCalls(...)`
179
+ - `repairToolCall(...)`
180
+ - `parseToolIntent(...)`
181
+ - `normalizeToolSchema(schema)`
182
+ - `defaultRepair(model)`
183
+ - `BetterToolValidationError`
140
184
 
141
- Measured with real Ollama `/api/chat` calls over all supported BFCL v4 single-turn tool-call categories. Request errors and timeouts count as incorrect. This is **not an official BFCL leaderboard score**; it measures BetterCall as a runtime reliability layer.
185
+ ## Benchmarks
142
186
 
143
- Latest completed remote run artifact: `benchmarks/bfcl-real-remote-completed-summary.json`.
187
+ Run the bundled targeted BFCL wrapper benchmark:
144
188
 
145
- Performance after wrapping the same model outputs with BetterCall:
146
-
147
- ```text
148
- granite4.1:3b
149
- Raw 73.4% | #############################...........
150
- BetterCall 83.8% | ##################################......
151
- qwen2.5:7b-instruct
152
- Raw 72.2% | #############################...........
153
- BetterCall 78.2% | ###############################.........
154
- qwen3:0.6b
155
- Raw 55.5% | ######################..................
156
- BetterCall 63.6% | #########################...............
157
- qwen3.5:0.8b
158
- Raw 54.6% | ######################..................
159
- BetterCall 56.9% | #######################.................
160
- qwen3.5:2b
161
- Raw 53.9% | ######################..................
162
- BetterCall 54.9% | ######################..................
163
- lfm2.5-thinking:latest
164
- Raw 50.8% | ####################....................
165
- BetterCall 54.8% | ######################..................
166
- qwen3.5:4b
167
- Raw 43.6% | #################.......................
168
- BetterCall 43.4% | #################.......................
169
- gemma4:e2b
170
- Raw 24.3% | ##########..............................
171
- BetterCall 24.7% | ##########..............................
189
+ ```bash
190
+ npm run bench:bfcl
172
191
  ```
173
192
 
174
- | Rank | Model | Completed cases | Raw model | BetterCall | Lift | Request errors |
175
- | ---: | --- | ---: | ---: | ---: | ---: | ---: |
176
- | 1 | `granite4.1:3b` | 3,625 | 73.4% | 83.8% | +10.4pp | 25 |
177
- | 2 | `qwen2.5:7b-instruct` | 3,625 | 72.2% | 78.2% | +5.9pp | 80 |
178
- | 3 | `qwen3:0.6b` | 3,625 | 55.5% | 63.6% | +8.2pp | 217 |
179
- | 4 | `qwen3.5:0.8b` | 3,625 | 54.6% | 56.9% | +2.3pp | 901 |
180
- | 5 | `qwen3.5:2b` | 3,625 | 53.9% | 54.9% | +1.0pp | 1,308 |
181
- | 6 | `lfm2.5-thinking:latest` | 3,625 | 50.8% | 54.8% | +4.0pp | 1,142 |
182
- | 7 | `qwen3.5:4b` | 3,625 | 43.6% | 43.4% | -0.2pp | 1,847 |
183
- | 8 | `gemma4:e2b` | 3,625 | 24.3% | 24.7% | +0.4pp | 2,641 |
193
+ Run real-model BFCL v4 calls against your Ollama endpoint:
184
194
 
185
- Latest completed model category detail: `qwen3.5:4b`.
195
+ ```bash
196
+ python3 -m venv /tmp/better-call-bfcl-venv
197
+ /tmp/better-call-bfcl-venv/bin/pip install "bfcl-eval==2025.12.17" soundfile
186
198
 
187
- | Category | Cases | Raw | BetterCall repair | Lift | Request errors |
199
+ OLLAMA_BASE_URL=http://127.0.0.1:11434 \
200
+ BENCH_MODELS=qwen3.5:0.8b \
201
+ BENCH_CATEGORIES=all \
202
+ BENCH_CASES_PER_CATEGORY=0 \
203
+ npm run bench:bfcl:real
204
+ ```
205
+
206
+ Run the small-model matrix:
207
+
208
+ ```bash
209
+ OLLAMA_BASE_URL=http://127.0.0.1:11434 npm run bench:bfcl:remote-small-all
210
+ ```
211
+
212
+ Notes:
213
+
214
+ - These are BetterCall wrapper benchmarks, not official BFCL leaderboard submissions.
215
+ - Full official BFCL v4 reproduction should use Berkeley's published checkpoint/package: commit `f7cf735` or `bfcl-eval==2025.12.17`.
216
+ - Real runs use Ollama `/api/chat` tool-call requests.
217
+ - Request errors and timeouts count as incorrect.
218
+ - Benchmark JSON redacts endpoints by default. Set `BENCH_SHOW_ENDPOINT=1` only for private debugging.
219
+
220
+ Latest completed remote run artifact: `benchmarks/bfcl-real-remote-completed-summary.json`.
221
+
222
+ | Model | Cases | Raw | BetterCall | Lift | Request errors |
188
223
  | --- | ---: | ---: | ---: | ---: | ---: |
189
- | `simple_python` | 400 | 81.3% | 81.3% | +0.0pp | 54 |
190
- | `simple_java` | 100 | 56.0% | 56.0% | +0.0pp | 32 |
191
- | `simple_javascript` | 50 | 48.0% | 48.0% | +0.0pp | 18 |
192
- | `multiple` | 200 | 83.5% | 83.5% | +0.0pp | 20 |
193
- | `parallel` | 200 | 70.0% | 70.0% | +0.0pp | 45 |
194
- | `parallel_multiple` | 200 | 47.0% | 47.0% | +0.0pp | 96 |
195
- | `irrelevance` | 240 | 68.8% | 68.8% | +0.0pp | 75 |
196
- | `live_simple` | 258 | 66.7% | 66.3% | -0.4pp | 45 |
197
- | `live_multiple` | 1,053 | 41.6% | 41.0% | -0.6pp | 538 |
198
- | `live_parallel` | 16 | 0.0% | 0.0% | +0.0pp | 16 |
199
- | `live_parallel_multiple` | 24 | 0.0% | 0.0% | +0.0pp | 24 |
200
- | `live_irrelevance` | 884 | 0.0% | 0.0% | +0.0pp | 884 |
201
-
202
- This `qwen3.5:4b` run hit sustained remote request failures in the live categories; those failures are counted as incorrect by the benchmark.
203
-
204
- Historical targeted wrapper benchmark:
205
-
206
- | Model | Raw | BetterCall repair | Accuracy lift |
207
- | --- | ---: | ---: | ---: |
208
- | `gemma4:e2b` | 81.3% | 91.3% | +10.0pp |
209
- | `qwen3.5:2b` | 75.3% | 84.0% | +8.7pp |
210
- | `qwen3.5:9b` | 84.0% | 90.0% | +6.0pp |
211
- | `qwen3.5:4b` | 82.0% | 87.3% | +5.3pp |
212
- | `granite4.1:3b` | 66.0% | 69.3% | +3.3pp |
213
-
214
- Strongest result: BFCL `irrelevance`, where the model should not call any tool.
215
-
216
- | Model | Raw irrelevance | BetterCall repair |
217
- | --- | ---: | ---: |
218
- | `qwen3.5:2b` | 74% | 100% |
219
- | `qwen3.5:4b` | 84% | 100% |
220
- | `qwen3.5:9b` | 84% | 100% |
221
- | `granite4.1:3b` | 92% | 100% |
222
- | `gemma4:e2b` | 70% | 100% |
223
-
224
- ## Why It Exists
225
-
226
- Small models are useful because they are cheap and fast. They also make tool mistakes:
227
-
228
- - call a tool that does not exist
229
- - fill the wrong parameter names
230
- - pass the wrong types
231
- - call tools when no tool is relevant
232
- - produce a call that looks valid but is unsafe to execute
233
-
234
- BetterCall reduces those failures before they reach production tools.
224
+ | `granite4.1:3b` | 3,625 | 73.4% | 83.8% | +10.4pp | 25 |
225
+ | `qwen2.5:7b-instruct` | 3,625 | 72.2% | 78.2% | +5.9pp | 80 |
226
+ | `qwen3:0.6b` | 3,625 | 55.5% | 63.6% | +8.2pp | 217 |
227
+ | `qwen3.5:0.8b` | 3,625 | 54.6% | 56.9% | +2.3pp | 901 |
228
+ | `qwen3.5:2b` | 3,625 | 53.9% | 54.9% | +1.0pp | 1,308 |
229
+ | `lfm2.5-thinking:latest` | 3,625 | 50.8% | 54.8% | +4.0pp | 1,142 |
230
+ | `qwen3.5:4b` | 3,625 | 43.6% | 43.4% | -0.2pp | 1,847 |
231
+ | `gemma4:e2b` | 3,625 | 24.3% | 24.7% | +0.4pp | 2,641 |
232
+
233
+ ## Requirements
234
+
235
+ BetterCall is an ESM package for modern Node.js runtimes. It has one runtime dependency: `zod`.
236
+
237
+ ## Contributing
238
+
239
+ Install dependencies and run the local checks:
240
+
241
+ ```bash
242
+ npm ci
243
+ npm test
244
+ npm run release:pack
245
+ ```
246
+
247
+ ## Security
248
+
249
+ If you believe you have found a security issue, please do not include sensitive details in a public issue. Open a minimal report first, or contact the maintainers through the repository owner.
235
250
 
236
251
  ## License
237
252
 
package/dist/index.d.ts CHANGED
@@ -2,8 +2,9 @@ export { guardToolCalls } from "./guard.js";
2
2
  export { buildRepairPrompt, buildReviewPrompt } from "./prompts.js";
3
3
  export { defaultRepair } from "./default-repair.js";
4
4
  export type { RepairModelLike } from "./default-repair.js";
5
+ export { parseToolIntent, repairToolCall } from "./inventory-repair.js";
5
6
  export { extractSchemaDescriptor, normalizeArgsBySchema, normalizeToolSchema } from "./schema.js";
6
7
  export { reliableToolCalls } from "./reliable.js";
7
8
  export { BetterToolValidationError, betterTools } from "./better-tool.js";
8
9
  export type { BetterToolLike, BetterToolsOptions } from "./better-tool.js";
9
- export type { GuardPolicy, GuardResult, IssueKind, JsonSchema, ArgsNormalizationOptions, ArgsNormalizationResult, ReliableToolCallsInput, ReliableToolCallsResult, RepairDiagnostics, RepairFunction, RepairInput, RepairPolicy, RepairProposal, SchemaDescriptor, SemanticValidator, ToolCall, ToolCallIssue, ToolDefinition, ToolSchema, } from "./types.js";
10
+ export type { GuardPolicy, GuardResult, InventoryRepairInput, InventoryRepairResult, InventoryRepairStatus, IssueKind, JsonSchema, ArgsNormalizationOptions, ArgsNormalizationResult, ReliableToolCallsInput, ReliableToolCallsResult, RepairDiagnostics, RepairFunction, RepairInput, RepairPolicy, RepairProposal, SchemaDescriptor, SemanticValidator, ToolCall, ToolCallIssue, ToolDefinition, ToolSchema, } from "./types.js";
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { guardToolCalls } from "./guard.js";
2
2
  export { buildRepairPrompt, buildReviewPrompt } from "./prompts.js";
3
3
  export { defaultRepair } from "./default-repair.js";
4
+ export { parseToolIntent, repairToolCall } from "./inventory-repair.js";
4
5
  export { extractSchemaDescriptor, normalizeArgsBySchema, normalizeToolSchema } from "./schema.js";
5
6
  export { reliableToolCalls } from "./reliable.js";
6
7
  export { BetterToolValidationError, betterTools } from "./better-tool.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { InventoryRepairInput, InventoryRepairResult, ToolCall } from "./types.js";
2
+ export declare function repairToolCall(input: InventoryRepairInput): Promise<InventoryRepairResult>;
3
+ export declare function parseToolIntent(value: unknown): ToolCall | undefined;
@@ -0,0 +1,353 @@
1
+ import { defaultRepair } from "./default-repair.js";
2
+ import { guardToolCalls } from "./guard.js";
3
+ import { normalizeArgsBySchema, normalizeToolSchema } from "./schema.js";
4
+ export async function repairToolCall(input) {
5
+ const visibleTools = normalizeTools(input.visibleTools);
6
+ const hiddenTools = normalizeTools(input.hiddenTools ?? []);
7
+ const original = extractOriginalCall(input);
8
+ if (!original) {
9
+ return rejected("no tool-call intent was provided", undefined, undefined, [{
10
+ kind: "parse",
11
+ path: "$.rawIntent",
12
+ message: "could not extract a tool call from the provided intent",
13
+ }]);
14
+ }
15
+ const originalToolName = original.tool;
16
+ const originalArgs = original.args;
17
+ const hiddenTool = hiddenTools.find((tool) => tool.name === original.tool);
18
+ if (hiddenTool) {
19
+ return rejected("model selected a hidden or blocked tool", originalToolName, originalArgs, [{
20
+ kind: "blocked_tool",
21
+ path: "$.tool",
22
+ message: `blocked tool ${original.tool}`,
23
+ tool: original.tool,
24
+ }]);
25
+ }
26
+ const visibleTool = visibleTools.find((tool) => tool.name === original.tool);
27
+ if (visibleTool) {
28
+ return repairKnownTool(input, visibleTools, visibleTool, original, originalToolName, originalArgs);
29
+ }
30
+ const inventoryProposal = await repairUnavailableToolFromInventory(input, visibleTools, original, originalToolName, originalArgs);
31
+ if (inventoryProposal)
32
+ return inventoryProposal;
33
+ const modelProposal = await repairWithModelOrCallback(input, visibleTools, original, [{
34
+ kind: "unknown_tool",
35
+ path: "$.tool",
36
+ message: `unknown tool ${original.tool}`,
37
+ tool: original.tool,
38
+ }]);
39
+ if (modelProposal) {
40
+ return {
41
+ status: "repaired",
42
+ toolName: modelProposal.tool,
43
+ args: modelProposal.args,
44
+ confidence: 0.8,
45
+ reason: "repair function selected a visible tool and schema-compatible arguments",
46
+ originalToolName,
47
+ originalArgs,
48
+ violations: [],
49
+ };
50
+ }
51
+ return rejected("no unambiguous visible tool repair was found", originalToolName, originalArgs, [{
52
+ kind: "unknown_tool",
53
+ path: "$.tool",
54
+ message: `unknown tool ${original.tool}`,
55
+ tool: original.tool,
56
+ }]);
57
+ }
58
+ export function parseToolIntent(value) {
59
+ if (isRecord(value))
60
+ return toolCallFromRecord(value);
61
+ if (typeof value !== "string")
62
+ return undefined;
63
+ const text = stripToolCode(value.trim());
64
+ const jsonCall = parseJsonToolCall(text);
65
+ if (jsonCall)
66
+ return jsonCall;
67
+ return parseFunctionStyleToolCall(text);
68
+ }
69
+ async function repairKnownTool(input, visibleTools, tool, original, originalToolName, originalArgs) {
70
+ const first = await guardToolCalls({ tools: visibleTools, calls: [original] });
71
+ if (first.ok) {
72
+ return {
73
+ status: "unchanged",
74
+ toolName: original.tool,
75
+ args: original.args,
76
+ confidence: 1,
77
+ reason: "tool call already matched the visible inventory and selected schema",
78
+ originalToolName,
79
+ originalArgs,
80
+ violations: [],
81
+ };
82
+ }
83
+ const aliasArgs = repairArgumentAliases(tool.schema, original.args);
84
+ const normalizedArgs = normalizeArgsBySchema(tool.schema, aliasArgs, input.repairPolicy).args;
85
+ const proposed = { tool: original.tool, args: normalizedArgs };
86
+ const second = await guardToolCalls({ tools: visibleTools, calls: [proposed] });
87
+ if (second.ok && !sameCall(original, proposed)) {
88
+ return {
89
+ status: "repaired",
90
+ toolName: proposed.tool,
91
+ args: proposed.args,
92
+ confidence: 0.85,
93
+ reason: "arguments were repaired using the selected tool schema",
94
+ originalToolName,
95
+ originalArgs,
96
+ violations: first.issues,
97
+ };
98
+ }
99
+ const modelProposal = await repairWithModelOrCallback(input, visibleTools, original, first.issues);
100
+ if (modelProposal) {
101
+ return {
102
+ status: "repaired",
103
+ toolName: modelProposal.tool,
104
+ args: modelProposal.args,
105
+ confidence: 0.8,
106
+ reason: "repair function returned a schema-compatible visible tool call",
107
+ originalToolName,
108
+ originalArgs,
109
+ violations: first.issues,
110
+ };
111
+ }
112
+ return rejected("selected tool arguments could not be repaired", originalToolName, originalArgs, first.issues);
113
+ }
114
+ async function repairUnavailableToolFromInventory(input, visibleTools, original, originalToolName, originalArgs) {
115
+ const candidates = [];
116
+ for (const tool of visibleTools) {
117
+ const aliasArgs = repairArgumentAliases(tool.schema, original.args);
118
+ const normalizedArgs = normalizeArgsBySchema(tool.schema, aliasArgs, input.repairPolicy).args;
119
+ const proposed = { tool: tool.name, args: normalizedArgs };
120
+ const result = await guardToolCalls({ tools: visibleTools, calls: [proposed] });
121
+ if (result.ok)
122
+ candidates.push(proposed);
123
+ }
124
+ if (candidates.length !== 1)
125
+ return undefined;
126
+ const [candidate] = candidates;
127
+ return {
128
+ status: "repaired",
129
+ toolName: candidate.tool,
130
+ args: candidate.args,
131
+ confidence: 0.75,
132
+ reason: "exactly one visible tool accepted the repaired argument shape",
133
+ originalToolName,
134
+ originalArgs,
135
+ violations: [{
136
+ kind: "unknown_tool",
137
+ path: "$.tool",
138
+ message: `unknown tool ${original.tool}`,
139
+ tool: original.tool,
140
+ }],
141
+ };
142
+ }
143
+ async function repairWithModelOrCallback(input, visibleTools, original, issues) {
144
+ const repair = input.repair ?? (input.repairModel ? defaultRepair(input.repairModel) : undefined);
145
+ if (!repair)
146
+ return undefined;
147
+ const repaired = await repair({
148
+ userInput: input.userInput,
149
+ tools: visibleTools,
150
+ hiddenTools: normalizeTools(input.hiddenTools ?? []),
151
+ calls: [original],
152
+ issues,
153
+ runtimePolicy: input.runtimePolicy,
154
+ });
155
+ for (const call of repaired) {
156
+ if (!visibleTools.some((tool) => tool.name === call.tool))
157
+ continue;
158
+ const result = await guardToolCalls({ tools: visibleTools, calls: [call] });
159
+ if (result.ok)
160
+ return call;
161
+ }
162
+ return undefined;
163
+ }
164
+ function extractOriginalCall(input) {
165
+ const fromCall = input.call ? toolCallFromRecord(input.call) : undefined;
166
+ if (fromCall)
167
+ return fromCall;
168
+ const fromRaw = parseToolIntent(input.rawIntent);
169
+ if (fromRaw)
170
+ return fromRaw;
171
+ const name = input.invalidToolName;
172
+ if (name)
173
+ return { tool: name, args: input.args ?? {} };
174
+ return undefined;
175
+ }
176
+ function repairArgumentAliases(schema, args) {
177
+ const normalized = normalizeToolSchema(schema);
178
+ if (!normalized?.properties)
179
+ return args;
180
+ let next = { ...args };
181
+ const properties = normalized.properties;
182
+ for (const key of Object.keys(args)) {
183
+ const canonical = findCanonicalKey(key, properties);
184
+ if (canonical && canonical !== key && !(canonical in next)) {
185
+ next[canonical] = next[key];
186
+ delete next[key];
187
+ }
188
+ }
189
+ next = repairSingleRequiredString(normalized, next);
190
+ if (normalized.additionalProperties === false) {
191
+ for (const key of Object.keys(next)) {
192
+ if (!(key in properties))
193
+ delete next[key];
194
+ }
195
+ }
196
+ return next;
197
+ }
198
+ function repairSingleRequiredString(schema, args) {
199
+ const properties = schema.properties ?? {};
200
+ const missingRequired = (schema.required ?? []).filter((key) => !(key in args));
201
+ if (missingRequired.length !== 1)
202
+ return args;
203
+ const [missingKey] = missingRequired;
204
+ const missingSchema = properties[missingKey];
205
+ if (!missingSchema || !expectsString(missingSchema))
206
+ return args;
207
+ const extras = Object.entries(args).filter(([key, value]) => !(key in properties) && typeof value === "string");
208
+ if (extras.length !== 1)
209
+ return args;
210
+ const [[extraKey, extraValue]] = extras;
211
+ const next = { ...args, [missingKey]: extraValue };
212
+ delete next[extraKey];
213
+ return next;
214
+ }
215
+ function findCanonicalKey(key, properties) {
216
+ const normalizedKey = normalizeKey(key);
217
+ return Object.keys(properties).find((candidate) => normalizeKey(candidate) === normalizedKey);
218
+ }
219
+ function normalizeKey(value) {
220
+ return value.toLowerCase().replace(/[^a-z0-9]/gu, "");
221
+ }
222
+ function expectsString(schema) {
223
+ return schema.type === "string" || (Array.isArray(schema.type) && schema.type.includes("string")) || !schema.type;
224
+ }
225
+ function parseJsonToolCall(value) {
226
+ try {
227
+ return toolCallFromRecord(JSON.parse(stripCodeFence(value)));
228
+ }
229
+ catch {
230
+ return undefined;
231
+ }
232
+ }
233
+ function parseFunctionStyleToolCall(value) {
234
+ const match = /^\s*([A-Za-z_$][\w$.-]*)\s*\(([\s\S]*)\)\s*;?\s*$/u.exec(value);
235
+ if (!match)
236
+ return undefined;
237
+ return { tool: match[1], args: parseFunctionArgs(match[2]) };
238
+ }
239
+ function parseFunctionArgs(value) {
240
+ const args = {};
241
+ for (const part of splitTopLevelCommas(value)) {
242
+ const match = /^\s*([A-Za-z_$][\w$.-]*)\s*=\s*([\s\S]*?)\s*$/u.exec(part);
243
+ if (match)
244
+ args[match[1]] = parseScalar(match[2]);
245
+ }
246
+ return args;
247
+ }
248
+ function splitTopLevelCommas(value) {
249
+ const parts = [];
250
+ let current = "";
251
+ let quote;
252
+ let escaped = false;
253
+ for (const char of value) {
254
+ if (escaped) {
255
+ current += char;
256
+ escaped = false;
257
+ continue;
258
+ }
259
+ if (char === "\\") {
260
+ current += char;
261
+ escaped = true;
262
+ continue;
263
+ }
264
+ if (quote) {
265
+ current += char;
266
+ if (char === quote)
267
+ quote = undefined;
268
+ continue;
269
+ }
270
+ if (char === "\"" || char === "'") {
271
+ current += char;
272
+ quote = char;
273
+ continue;
274
+ }
275
+ if (char === ",") {
276
+ parts.push(current);
277
+ current = "";
278
+ continue;
279
+ }
280
+ current += char;
281
+ }
282
+ if (current.trim() !== "")
283
+ parts.push(current);
284
+ return parts;
285
+ }
286
+ function parseScalar(value) {
287
+ const trimmed = value.trim();
288
+ try {
289
+ return JSON.parse(trimmed);
290
+ }
291
+ catch {
292
+ return trimmed.replace(/^["']|["']$/gu, "");
293
+ }
294
+ }
295
+ function stripToolCode(value) {
296
+ const match = /<tool_code>\s*([\s\S]*?)\s*<\/tool_code>/iu.exec(value);
297
+ return match ? match[1].trim() : value;
298
+ }
299
+ function stripCodeFence(value) {
300
+ const match = /^```(?:json)?\s*([\s\S]*?)\s*```$/u.exec(value.trim());
301
+ return match ? match[1] : value;
302
+ }
303
+ function toolCallFromRecord(value) {
304
+ if (!isRecord(value))
305
+ return undefined;
306
+ if (typeof value.tool === "string" && isRecord(value.args))
307
+ return { tool: value.tool, args: value.args };
308
+ if (typeof value.name === "string" && isRecord(value.args))
309
+ return { tool: value.name, args: value.args };
310
+ if (typeof value.name === "string" && isRecord(value.arguments))
311
+ return { tool: value.name, args: value.arguments };
312
+ if (typeof value.name === "string" && typeof value.arguments === "string") {
313
+ const parsed = parseJsonObject(value.arguments);
314
+ if (parsed)
315
+ return { tool: value.name, args: parsed };
316
+ }
317
+ if (isRecord(value.function))
318
+ return toolCallFromRecord(value.function);
319
+ if (Array.isArray(value.calls))
320
+ return value.calls.map(toolCallFromRecord).find(Boolean);
321
+ if (Array.isArray(value.tool_calls))
322
+ return value.tool_calls.map(toolCallFromRecord).find(Boolean);
323
+ return undefined;
324
+ }
325
+ function parseJsonObject(value) {
326
+ try {
327
+ const parsed = JSON.parse(value);
328
+ return isRecord(parsed) ? parsed : undefined;
329
+ }
330
+ catch {
331
+ return undefined;
332
+ }
333
+ }
334
+ function rejected(reason, originalToolName, originalArgs, violations) {
335
+ return {
336
+ status: "rejected",
337
+ confidence: 0,
338
+ reason,
339
+ originalToolName,
340
+ originalArgs,
341
+ violations,
342
+ };
343
+ }
344
+ function normalizeTools(tools) {
345
+ return tools.map((tool) => ({ ...tool, schema: normalizeToolSchema(tool.schema) }));
346
+ }
347
+ function sameCall(left, right) {
348
+ return left.tool === right.tool && JSON.stringify(left.args) === JSON.stringify(right.args);
349
+ }
350
+ function isRecord(value) {
351
+ return typeof value === "object" && value !== null && !Array.isArray(value);
352
+ }
353
+ //# sourceMappingURL=inventory-repair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inventory-repair.js","sourceRoot":"","sources":["../src/inventory-repair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAUzE,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,KAA2B;IAC9D,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC5C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,QAAQ,CAAC,kCAAkC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;gBACzE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,wDAAwD;aAClE,CAAC,CAAC,CAAC;IACN,CAAC;IAED,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC;IACvC,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC;IACnC,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,CAAC;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ACJ,CAAC;AAED,SAAS,cAAc,CAAC,KAAuB;IAC7C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,QAAQ,CAAC,IAAc,EAAE,KAAe;IAC/C,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC9F,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
package/dist/prompts.js CHANGED
@@ -6,6 +6,8 @@ export function buildRepairPrompt(input) {
6
6
  "",
7
7
  `User request: ${input.userInput}`,
8
8
  `Tools: ${JSON.stringify(input.tools)}`,
9
+ `Hidden or blocked tools: ${JSON.stringify(input.hiddenTools ?? [])}`,
10
+ `Runtime policy: ${JSON.stringify(input.runtimePolicy ?? {})}`,
9
11
  `Rejected calls: ${JSON.stringify(input.calls)}`,
10
12
  `Issues: ${JSON.stringify(input.issues)}`,
11
13
  ].join("\n");
@@ -18,6 +20,8 @@ export function buildReviewPrompt(input) {
18
20
  "",
19
21
  `User request: ${input.userInput}`,
20
22
  `Tools: ${JSON.stringify(input.tools)}`,
23
+ `Hidden or blocked tools: ${JSON.stringify(input.hiddenTools ?? [])}`,
24
+ `Runtime policy: ${JSON.stringify(input.runtimePolicy ?? {})}`,
21
25
  `Previous calls: ${JSON.stringify(input.calls)}`,
22
26
  `Validation issues, if any: ${JSON.stringify(input.issues)}`,
23
27
  ].join("\n");
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAAC,KAAkB;IAClD,OAAO;QACL,2DAA2D;QAC3D,8EAA8E;QAC9E,qDAAqD;QACrD,EAAE;QACF,iBAAiB,KAAK,CAAC,SAAS,EAAE;QAClC,UAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACvC,mBAAmB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QAChD,WAAW,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;KAC1C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAkB;IAClD,OAAO;QACL,sEAAsE;QACtE,8FAA8F;QAC9F,0EAA0E;QAC1E,EAAE;QACF,iBAAiB,KAAK,CAAC,SAAS,EAAE;QAClC,UAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACvC,mBAAmB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QAChD,8BAA8B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;KAC7D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAAC,KAAkB;IAClD,OAAO;QACL,2DAA2D;QAC3D,8EAA8E;QAC9E,qDAAqD;QACrD,EAAE;QACF,iBAAiB,KAAK,CAAC,SAAS,EAAE;QAClC,UAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACvC,4BAA4B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE;QACrE,mBAAmB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,EAAE;QAC9D,mBAAmB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QAChD,WAAW,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;KAC1C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAkB;IAClD,OAAO;QACL,sEAAsE;QACtE,8FAA8F;QAC9F,0EAA0E;QAC1E,EAAE;QACF,iBAAiB,KAAK,CAAC,SAAS,EAAE;QAClC,UAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACvC,4BAA4B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE;QACrE,mBAAmB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,EAAE;QAC9D,mBAAmB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QAChD,8BAA8B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;KAC7D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
package/dist/types.d.ts CHANGED
@@ -39,7 +39,7 @@ export type ToolCall = {
39
39
  tool: string;
40
40
  args: Record<string, unknown>;
41
41
  };
42
- export type IssueKind = "unknown_tool" | "irrelevant_call" | "missing_call" | "schema" | "type" | "semantic";
42
+ export type IssueKind = "unknown_tool" | "blocked_tool" | "irrelevant_call" | "missing_call" | "parse" | "schema" | "type" | "semantic";
43
43
  export type ToolCallIssue = {
44
44
  kind: IssueKind;
45
45
  path: string;
@@ -94,8 +94,10 @@ export type SemanticValidator = (input: {
94
94
  export type RepairInput = {
95
95
  userInput: string;
96
96
  tools: ToolDefinition[];
97
+ hiddenTools?: ToolDefinition[];
97
98
  calls: ToolCall[];
98
99
  issues: ToolCallIssue[];
100
+ runtimePolicy?: Record<string, unknown>;
99
101
  };
100
102
  export type RepairFunction = (input: RepairInput) => Promise<ToolCall[]> | ToolCall[];
101
103
  export type ReliableToolCallsInput = {
@@ -113,3 +115,32 @@ export type ReliableToolCallsResult = GuardResult & {
113
115
  original: ToolCall[];
114
116
  diagnostics?: RepairDiagnostics[];
115
117
  };
118
+ export type InventoryRepairStatus = "repaired" | "rejected" | "unchanged";
119
+ export type InventoryRepairInput = {
120
+ userInput: string;
121
+ visibleTools: ToolDefinition[];
122
+ hiddenTools?: ToolDefinition[];
123
+ call?: Partial<ToolCall> & {
124
+ name?: string;
125
+ arguments?: unknown;
126
+ };
127
+ rawIntent?: string;
128
+ invalidToolName?: string;
129
+ args?: Record<string, unknown>;
130
+ runtimePolicy?: Record<string, unknown>;
131
+ repairPolicy?: RepairPolicy;
132
+ repair?: RepairFunction;
133
+ repairModel?: {
134
+ invoke(input: unknown): Promise<unknown> | unknown;
135
+ };
136
+ };
137
+ export type InventoryRepairResult = {
138
+ status: InventoryRepairStatus;
139
+ toolName?: string;
140
+ args?: Record<string, unknown>;
141
+ confidence: number;
142
+ reason: string;
143
+ originalToolName?: string;
144
+ originalArgs?: Record<string, unknown>;
145
+ violations: ToolCallIssue[];
146
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/better-call",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "LLM tool-call reliability layer.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",