ai-tool-set 0.1.0-alpha.2 → 0.1.0-alpha.3

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
@@ -217,6 +217,16 @@ export async function POST(req: Request) {
217
217
  }
218
218
  ```
219
219
 
220
+ Use `.clone()` to convert between immutable and mutable, preserving all activation entries:
221
+
222
+ ```typescript
223
+ // Convert an immutable toolset to mutable
224
+ const mutableToolSet = toolSet.clone({ mutable: true });
225
+
226
+ // Convert a mutable toolset back to immutable
227
+ const immutableToolSet = mutableToolSet.clone();
228
+ ```
229
+
220
230
  ### Typed UI Tool Set
221
231
 
222
232
  Use `InferUIToolSet` to get fully typed UI messages from your tool set:
@@ -362,6 +372,15 @@ const { tools, activeTools } = toolSet.inferTools({ messages, context: {} });
362
372
  const result = await generateText({ model, tools, activeTools, messages });
363
373
  ```
364
374
 
375
+ #### `.clone(options?)`
376
+
377
+ Clone the toolset, preserving all activation entries. Pass `{ mutable: true }` to get a mutable clone, or omit for an immutable clone. Defaults to immutable.
378
+
379
+ ```ts
380
+ const mutableClone = toolSet.clone({ mutable: true });
381
+ const immutableClone = toolSet.clone();
382
+ ```
383
+
365
384
  ## Types
366
385
 
367
386
  ### `ActivationInput`
@@ -401,6 +420,38 @@ type MyUIMessage = UIMessage<unknown, any, InferUIToolSet<typeof toolSet>>;
401
420
  // message.parts[0].output // typed as search tool's return type
402
421
  ```
403
422
 
423
+ ### `ActiveTools`
424
+
425
+ Extract the tool names tracked as active from an immutable `ToolSet` instance. Tracks tools from `.activate()` and `.deactivateWhen()`.
426
+
427
+ > [!NOTE]
428
+ > `ActiveTools` returns `never` for mutable toolsets, since TypeScript cannot track type changes on the same reference across method calls.
429
+
430
+ ```ts
431
+ import type { ActiveTools } from 'ai-tool-set';
432
+
433
+ const toolSet = createToolSet({ tools }).deactivate(['cancel_order']);
434
+
435
+ type Active = ActiveTools<typeof toolSet>;
436
+ // 'search' | 'list_orders'
437
+ ```
438
+
439
+ ### `InactiveTools`
440
+
441
+ Extract the tool names tracked as inactive from an immutable `ToolSet` instance. Tracks tools from `.deactivate()` and `.activateWhen()`.
442
+
443
+ > [!NOTE]
444
+ > `InactiveTools` returns `never` for mutable toolsets, since TypeScript cannot track type changes on the same reference across method calls.
445
+
446
+ ```ts
447
+ import type { InactiveTools } from 'ai-tool-set';
448
+
449
+ const toolSet = createToolSet({ tools }).deactivate(['cancel_order']);
450
+
451
+ type Inactive = InactiveTools<typeof toolSet>;
452
+ // 'cancel_order'
453
+ ```
454
+
404
455
  ## License
405
456
 
406
457
  MIT
package/dist/index.d.mts CHANGED
@@ -95,6 +95,13 @@ declare class ImmutableToolSet<TOOLS extends ToolRecord, MESSAGE extends Message
95
95
  deactivateWhen<NAMES extends keyof TOOLS & string>(predicates: Partial<Record<NAMES, ActivationPredicate<MESSAGE, CONTEXT>>>): ImmutableToolSet<TOOLS, MESSAGE, CONTEXT, ACTIVATED | NAMES, Exclude<DEACTIVATED, NAMES>>;
96
96
  /** Evaluate all predicates with the provided input. Returns resolved `{ tools, activeTools }`. */
97
97
  inferTools(input: ActivationInput<MESSAGE, CONTEXT>): ResolvedToolSet<TOOLS>;
98
+ /** Clone this toolset, optionally switching between immutable and mutable. */
99
+ clone(options: {
100
+ mutable: true;
101
+ }): MutableToolSet<TOOLS, MESSAGE, CONTEXT>;
102
+ clone(options?: {
103
+ mutable?: false;
104
+ }): ImmutableToolSet<TOOLS, MESSAGE, CONTEXT, ACTIVATED, DEACTIVATED>;
98
105
  }
99
106
  /**
100
107
  * A mutable tool set with chainable activation methods.
@@ -125,6 +132,13 @@ declare class MutableToolSet<TOOLS extends ToolRecord, MESSAGE extends MessageTy
125
132
  deactivateWhen(predicates: Partial<Record<keyof TOOLS & string, ActivationPredicate<MESSAGE, CONTEXT>>>): this;
126
133
  /** Evaluate all predicates with the provided input. Returns resolved `{ tools, activeTools }`. */
127
134
  inferTools(input: ActivationInput<MESSAGE, CONTEXT>): ResolvedToolSet<TOOLS>;
135
+ /** Clone this toolset, optionally switching between immutable and mutable. */
136
+ clone(options: {
137
+ mutable: true;
138
+ }): MutableToolSet<TOOLS, MESSAGE, CONTEXT>;
139
+ clone(options?: {
140
+ mutable?: false;
141
+ }): ImmutableToolSet<TOOLS, MESSAGE, CONTEXT, keyof TOOLS & string>;
128
142
  }
129
143
  type CreateToolSetOptions<TOOLS extends ToolRecord> = {
130
144
  tools: TOOLS;
package/dist/index.mjs CHANGED
@@ -107,6 +107,9 @@ var ImmutableToolSet = class ImmutableToolSet {
107
107
  inferTools(input) {
108
108
  return this.#state.inferTools(input);
109
109
  }
110
+ clone(options) {
111
+ return options?.mutable ? new MutableToolSet(this.#state) : new ImmutableToolSet(this.#state);
112
+ }
110
113
  };
111
114
  /**
112
115
  * A mutable tool set with chainable activation methods.
@@ -114,7 +117,7 @@ var ImmutableToolSet = class ImmutableToolSet {
114
117
  * Same resolution semantics as ImmutableToolSet, but methods mutate
115
118
  * in-place and return `this` instead of creating new instances.
116
119
  */
117
- var MutableToolSet = class {
120
+ var MutableToolSet = class MutableToolSet {
118
121
  #state;
119
122
  /** All tools as a standard AI SDK tool record. */
120
123
  tools;
@@ -151,6 +154,9 @@ var MutableToolSet = class {
151
154
  inferTools(input) {
152
155
  return this.#state.inferTools(input);
153
156
  }
157
+ clone(options) {
158
+ return options?.mutable ? new MutableToolSet(this.#state) : new ImmutableToolSet(this.#state);
159
+ }
154
160
  };
155
161
  function createToolSet(options) {
156
162
  const state = new ToolSetState(options.tools, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-tool-set",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "Tool set utilities for the Vercel AI SDK",
5
5
  "keywords": [],
6
6
  "license": "MIT",