ai-tool-set 1.2.0 → 1.2.2
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 +24 -28
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<div align='center'>
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-tool-set",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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": "2.0.0-next.2",
|
|
31
32
|
"husky": "^9.1.7",
|
|
32
33
|
"lint-staged": "^16.4.0",
|
|
33
34
|
"oxfmt": "^0.44.0",
|