ai-tool-set 1.1.0 → 1.2.1

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
@@ -1,6 +1,9 @@
1
1
  <div align='center'>
2
2
 
3
- # ai-tool-set
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="assets/logo-dark.png" />
5
+ <img src="assets/logo-light.png" alt="ai-tool-set logo" width="400" />
6
+ </picture>
4
7
 
5
8
  <p align="center">Conditional tool activation for the AI SDK, fully type-safe</p>
6
9
  <p align="center">
@@ -66,9 +69,7 @@ Use `.activate()` and `.deactivate()` to statically control which tools are avai
66
69
  import { generateText } from 'ai';
67
70
 
68
71
  // Activate and deactivate tools
69
- const toolSet = createToolSet({ tools })
70
- .deactivate(['cancel_order'])
71
- .activate(['list_orders']);
72
+ const toolSet = createToolSet({ tools }).deactivate(['cancel_order']).activate(['list_orders']);
72
73
 
73
74
  // Infer active tools
74
75
  const { tools, activeTools } = toolSet.inferTools();
@@ -142,11 +143,10 @@ const result = await generateText({ model, tools, activeTools, messages });
142
143
  You can also activate multiple tools at once:
143
144
 
144
145
  ```typescript
145
- const toolSet = createToolSet({ tools })
146
- .activateWhen({
147
- list_orders: ({ context }) => context?.isAuthenticated,
148
- cancel_order: ({ messages }) => hasUnfulfilledOrders(messages),
149
- });
146
+ const toolSet = createToolSet({ tools }).activateWhen({
147
+ list_orders: ({ context }) => context?.isAuthenticated,
148
+ cancel_order: ({ messages }) => hasUnfulfilledOrders(messages),
149
+ });
150
150
  ```
151
151
 
152
152
  ### Activation Defaults
@@ -184,11 +184,11 @@ Each activation method appends to an internal list. For each tool, the **last en
184
184
  ```typescript
185
185
  const toolSet = createToolSet({ tools })
186
186
  // cancel_order: activated
187
- .activate(['cancel_order'])
187
+ .activate(['cancel_order'])
188
188
  // cancel_order: deactivated
189
- .deactivate(['cancel_order'])
189
+ .deactivate(['cancel_order'])
190
190
  // cancel_order: deactivated with conditional activation
191
- .activateWhen('cancel_order', ({ messages }) => hasUnfulfilledOrders(messages));
191
+ .activateWhen('cancel_order', ({ messages }) => hasUnfulfilledOrders(messages));
192
192
  ```
193
193
 
194
194
  ### Immutable vs Mutable
@@ -297,14 +297,12 @@ If you already have a custom `UIMessage` type, you can pass it as `MESSAGE` gene
297
297
  import { myTools } from './my-tools.js';
298
298
  import { MyUIMessage } from './my-ui-message.js';
299
299
 
300
- const toolSet = createToolSet<typeof myTools, MyUIMessage>({ tools: myTools })
301
- .activateWhen(
302
- 'cancel_order',
303
- ({ messages }) => hasUnfulfilledOrders(messages),
304
- // ~~~~~~~~
305
- // Messages are now typed as Array<MyUIMessage> | undefined
306
- );
307
-
300
+ const toolSet = createToolSet<typeof myTools, MyUIMessage>({ tools: myTools }).activateWhen(
301
+ 'cancel_order',
302
+ ({ messages }) => hasUnfulfilledOrders(messages),
303
+ // ~~~~~~~~
304
+ // Messages are now typed as Array<MyUIMessage> | undefined
305
+ );
308
306
 
309
307
  const { tools, activeTools } = toolSet.inferTools({ messages });
310
308
  ```
@@ -319,14 +317,12 @@ import { MyUIMessage } from './my-ui-message.js';
319
317
 
320
318
  type MyContext = { userId: string; isAdmin: boolean };
321
319
 
322
- const toolSet = createToolSet<typeof myTools, MyUIMessage, MyContext>({ tools: myTools })
323
- .activateWhen(
324
- 'cancel_order',
325
- ({ context }) => context?.isAdmin,
326
- // ~~~~~~~
327
- // Context is typed as MyContext | undefined
328
- );
329
-
320
+ const toolSet = createToolSet<typeof myTools, MyUIMessage, MyContext>({ tools: myTools }).activateWhen(
321
+ 'cancel_order',
322
+ ({ context }) => context?.isAdmin,
323
+ // ~~~~~~~
324
+ // Context is typed as MyContext | undefined
325
+ );
330
326
 
331
327
  const { tools, activeTools } = toolSet.inferTools({
332
328
  messages,
@@ -521,6 +517,19 @@ type Inactive = InferInactiveTools<typeof toolSet>;
521
517
  // 'cancel_order'
522
518
  ```
523
519
 
520
+ ### `InferAllTools`
521
+
522
+ Extract all tool names from a `ToolSet` instance, regardless of activation state. Works for both immutable and mutable toolsets since the tool record is statically known.
523
+
524
+ ```ts
525
+ import type { InferAllTools } from 'ai-tool-set';
526
+
527
+ const toolSet = createToolSet({ tools }).deactivate(['cancel_order']);
528
+
529
+ type All = InferAllTools<typeof toolSet>;
530
+ // 'search' | 'list_orders' | 'cancel_order'
531
+ ```
532
+
524
533
  ## License
525
534
 
526
535
  MIT
package/dist/index.d.mts CHANGED
@@ -21,6 +21,11 @@ type InferActiveTools<TOOLSET extends AnyToolSet> = TOOLSET extends ImmutableToo
21
21
  * Returns `never` for MutableToolSet (cannot be determined at compile time).
22
22
  */
23
23
  type InferInactiveTools<TOOLSET extends AnyToolSet> = TOOLSET extends ImmutableToolSet<any, any, any, any, infer D> ? D : never;
24
+ /**
25
+ * Extract all tool names from a ToolSet instance — both active and inactive.
26
+ * Works for both ImmutableToolSet and MutableToolSet since the tool record is statically known.
27
+ */
28
+ type InferAllTools<TOOLSET extends AnyToolSet> = keyof InferToolSet<TOOLSET> & string;
24
29
  /**
25
30
  * Input passed to activation predicates.
26
31
  * Use `ActivationInput<MyMsg>` to get per-tool narrowing in callbacks.
@@ -176,4 +181,4 @@ declare function createToolSet<const TOOLS extends ToolRecord, MESSAGE extends M
176
181
  mutable?: false;
177
182
  }): ImmutableToolSet<TOOLS, MESSAGE, CONTEXT, keyof TOOLS & string>;
178
183
  //#endregion
179
- export { type ActivationInput, type InferActiveTools, type InferInactiveTools, type InferToolSet, type InferUIToolSet, type ToolSet, createToolSet };
184
+ export { type ActivationInput, type InferActiveTools, type InferAllTools, type InferInactiveTools, type InferToolSet, type InferUIToolSet, type ToolSet, createToolSet };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-tool-set",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Conditional tool activation for the AI SDK, fully type-safe",
5
5
  "keywords": [
6
6
  "ai",
@@ -28,6 +28,7 @@
28
28
  "@total-typescript/tsconfig": "^1.0.4",
29
29
  "@types/node": "^25.5.2",
30
30
  "ai": "^6.0.153",
31
+ "ai-test-kit": "^1.2.0",
31
32
  "husky": "^9.1.7",
32
33
  "lint-staged": "^16.4.0",
33
34
  "oxfmt": "^0.44.0",