@supertools-ai/core 0.1.1 → 0.1.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 +55 -38
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Supertools
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img src="assets/banner.svg" alt="Supertools - Let LLMs write code that calls your tools" width="100%">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/bxxf/supertools/refs/heads/main/assets/banner.svg" alt="Supertools - Let LLMs write code that calls your tools" width="100%">
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
> **🚧 Work in Progress** — This project is under active development.
|
|
7
|
+
> **🚧 Work in Progress** — This project is under active development. Contributions are welcome, especially for adding support for other AI providers (OpenAI, Vercel AI SDK, etc.)!
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<a href="#quick-start">Quick Start</a> •
|
|
@@ -50,55 +50,72 @@ User Request → LLM generates code → Sandbox executes → Result
|
|
|
50
50
|
bun add @supertools-ai/core @anthropic-ai/sdk e2b
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
Set your API keys:
|
|
54
|
+
```bash
|
|
55
|
+
export ANTHROPIC_API_KEY=your-key
|
|
56
|
+
export E2B_API_KEY=your-key
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Create `index.ts` and run with `bun run index.ts`:
|
|
60
|
+
|
|
53
61
|
```typescript
|
|
54
62
|
import { supertools, defineTool, z } from '@supertools-ai/core';
|
|
55
63
|
import { Sandbox } from 'e2b';
|
|
56
64
|
import Anthropic from '@anthropic-ai/sdk';
|
|
57
65
|
|
|
58
|
-
//
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
name: 'sendEmail',
|
|
71
|
-
description: 'Send an email',
|
|
66
|
+
// Sample data
|
|
67
|
+
const orders = [
|
|
68
|
+
{ id: 1, customer: 'Alice', total: 150, status: 'completed' },
|
|
69
|
+
{ id: 2, customer: 'Bob', total: 75, status: 'pending' },
|
|
70
|
+
{ id: 3, customer: 'Alice', total: 200, status: 'completed' },
|
|
71
|
+
{ id: 4, customer: 'Charlie', total: 50, status: 'completed' },
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
// Define tools with Zod schemas
|
|
75
|
+
const getOrders = defineTool({
|
|
76
|
+
name: 'getOrders',
|
|
77
|
+
description: 'Get orders, optionally filtered by status',
|
|
72
78
|
parameters: z.object({
|
|
73
|
-
|
|
74
|
-
subject: z.string(),
|
|
75
|
-
body: z.string(),
|
|
79
|
+
status: z.enum(['pending', 'completed']).optional(),
|
|
76
80
|
}),
|
|
77
|
-
returns: z.
|
|
78
|
-
|
|
81
|
+
returns: z.array(z.object({
|
|
82
|
+
id: z.number(),
|
|
83
|
+
customer: z.string(),
|
|
84
|
+
total: z.number(),
|
|
85
|
+
status: z.string(),
|
|
86
|
+
})),
|
|
87
|
+
execute: async ({ status }) =>
|
|
88
|
+
status ? orders.filter(o => o.status === status) : orders,
|
|
79
89
|
});
|
|
80
90
|
|
|
81
|
-
//
|
|
91
|
+
// Main
|
|
82
92
|
const sandbox = await Sandbox.create('supertools-bun');
|
|
83
|
-
const client = supertools(new Anthropic(), {
|
|
84
|
-
tools: [queryDatabase, sendEmail],
|
|
85
|
-
sandbox,
|
|
86
|
-
});
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
94
|
+
try {
|
|
95
|
+
const client = supertools(new Anthropic(), {
|
|
96
|
+
tools: [getOrders],
|
|
97
|
+
sandbox,
|
|
98
|
+
onEvent: (e) => {
|
|
99
|
+
if (e.type === 'tool_call') console.log(`→ ${e.tool}()`);
|
|
100
|
+
if (e.type === 'result') console.log('Result:', e.data);
|
|
101
|
+
},
|
|
102
|
+
});
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
await client.messages.create({
|
|
105
|
+
model: 'claude-sonnet-4-5-20241022',
|
|
106
|
+
max_tokens: 1024,
|
|
107
|
+
messages: [{
|
|
108
|
+
role: 'user',
|
|
109
|
+
content: 'Get all completed orders and calculate the total revenue',
|
|
110
|
+
}],
|
|
111
|
+
});
|
|
112
|
+
} finally {
|
|
113
|
+
await sandbox.kill();
|
|
114
|
+
}
|
|
100
115
|
```
|
|
101
116
|
|
|
117
|
+
**What happens:** The LLM writes code that calls `getOrders()`, loops through results, and calculates the sum — all in one API call.
|
|
118
|
+
|
|
102
119
|
## How It Works
|
|
103
120
|
|
|
104
121
|
When you ask: *"Query sales for all 50 states, find top 5, email a report"*
|
|
@@ -139,7 +156,7 @@ return { topStates: top5, reportSent: true };
|
|
|
139
156
|
## Why Supertools?
|
|
140
157
|
|
|
141
158
|
<p align="center">
|
|
142
|
-
<img src="assets/benchmark.svg" alt="Benchmark Results" width="100%">
|
|
159
|
+
<img src="https://raw.githubusercontent.com/bxxf/supertools/refs/heads/main/assets/benchmark.svg" alt="Benchmark Results" width="100%">
|
|
143
160
|
</p>
|
|
144
161
|
|
|
145
162
|
The benchmark compares three approaches on the same model (Claude Sonnet 4.5):
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supertools-ai/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Programmatic tool calling for LLMs - let AI write code that orchestrates your tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"build": "bun run clean && bun build src/index.ts --outdir dist --target node --format esm && tsc --emitDeclarationOnly",
|
|
22
23
|
"dev": "bun --watch src/index.ts",
|
|
23
24
|
"test": "bun test",
|
|
24
25
|
"typecheck": "tsc --noEmit",
|