@supertools-ai/core 0.1.4 → 0.1.5
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 +7 -7
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -4
- package/dist/relay/client.d.ts +2 -0
- package/dist/relay/client.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ E2B_API_KEY=your-key # Get at e2b.dev
|
|
|
59
59
|
Create `index.ts` and run with `bun run index.ts`:
|
|
60
60
|
|
|
61
61
|
```typescript
|
|
62
|
-
import { supertools, defineTool, z } from '@supertools-ai/core';
|
|
62
|
+
import { supertools, defineTool, z, SANDBOX_TEMPLATE } from '@supertools-ai/core';
|
|
63
63
|
import { Sandbox } from 'e2b';
|
|
64
64
|
import Anthropic from '@anthropic-ai/sdk';
|
|
65
65
|
|
|
@@ -88,8 +88,8 @@ const getOrders = defineTool({
|
|
|
88
88
|
status ? orders.filter(o => o.status === status) : orders,
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
//
|
|
92
|
-
const sandbox = await Sandbox.create(
|
|
91
|
+
// SANDBOX_TEMPLATE is exported by supertools - always use it to ensure compatibility
|
|
92
|
+
const sandbox = await Sandbox.create(SANDBOX_TEMPLATE).catch((e) => {
|
|
93
93
|
console.error('Failed to create sandbox:', e);
|
|
94
94
|
process.exit(1);
|
|
95
95
|
});
|
|
@@ -179,11 +179,11 @@ The benchmark compares three approaches on the same model (Claude Sonnet 4.5):
|
|
|
179
179
|
Wrap any supported LLM SDK client with programmatic tool calling.
|
|
180
180
|
|
|
181
181
|
```typescript
|
|
182
|
-
import { supertools, defineTool, z } from '@supertools-ai/core';
|
|
182
|
+
import { supertools, defineTool, z, SANDBOX_TEMPLATE } from '@supertools-ai/core';
|
|
183
183
|
import { Sandbox } from 'e2b';
|
|
184
184
|
import Anthropic from '@anthropic-ai/sdk';
|
|
185
185
|
|
|
186
|
-
const sandbox = await Sandbox.create(
|
|
186
|
+
const sandbox = await Sandbox.create(SANDBOX_TEMPLATE);
|
|
187
187
|
const client = supertools(new Anthropic(), {
|
|
188
188
|
// Required
|
|
189
189
|
tools: [defineTool({ name, description, parameters, execute })],
|
|
@@ -259,7 +259,7 @@ const calculateStats = defineTool({
|
|
|
259
259
|
For more control, use the executor directly:
|
|
260
260
|
|
|
261
261
|
```typescript
|
|
262
|
-
import { createExecutor, defineTool } from '@supertools-ai/core';
|
|
262
|
+
import { createExecutor, defineTool, SANDBOX_TEMPLATE } from '@supertools-ai/core';
|
|
263
263
|
import { Sandbox } from 'e2b';
|
|
264
264
|
|
|
265
265
|
// Create your own LLM adapter
|
|
@@ -270,7 +270,7 @@ const myAdapter = {
|
|
|
270
270
|
},
|
|
271
271
|
};
|
|
272
272
|
|
|
273
|
-
const sandbox = await Sandbox.create(
|
|
273
|
+
const sandbox = await Sandbox.create(SANDBOX_TEMPLATE);
|
|
274
274
|
const executor = createExecutor({
|
|
275
275
|
llm: myAdapter,
|
|
276
276
|
tools: [/* your tools */],
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
-
* import { supertools, defineTool, z } from '@supertools-ai/core';
|
|
9
|
+
* import { supertools, defineTool, z, SANDBOX_TEMPLATE } from '@supertools-ai/core';
|
|
10
10
|
* import { Sandbox } from 'e2b';
|
|
11
11
|
* import Anthropic from '@anthropic-ai/sdk';
|
|
12
12
|
*
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* });
|
|
21
21
|
*
|
|
22
22
|
* // Create sandbox and wrap your SDK client
|
|
23
|
-
* const sandbox = await Sandbox.create(
|
|
23
|
+
* const sandbox = await Sandbox.create(SANDBOX_TEMPLATE);
|
|
24
24
|
* const client = supertools(new Anthropic(), { tools: [queryDb], sandbox });
|
|
25
25
|
*
|
|
26
26
|
* // Use exactly like normal - tools execute automatically
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
*
|
|
34
34
|
* @packageDocumentation
|
|
35
35
|
*/
|
|
36
|
+
/** The recommended E2B sandbox template for this version of supertools */
|
|
37
|
+
export declare const SANDBOX_TEMPLATE = "supertools-bun-014";
|
|
36
38
|
export { supertools, detectProvider } from './supertools';
|
|
37
39
|
export type { SupertoolsConfig, SupportedProvider } from './supertools';
|
|
38
40
|
export { defineTool, z } from './tool';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGxE,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AACvC,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClE,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGxD,YAAY,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,SAAS,EACT,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACv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 +2637,26 @@ class RelayClient {
|
|
|
2637
2637
|
}
|
|
2638
2638
|
}
|
|
2639
2639
|
onMessage(data) {
|
|
2640
|
-
if (
|
|
2640
|
+
if (typeof data === "string") {
|
|
2641
|
+
const error = `Sandbox template version mismatch. You are using an old sandbox template that uses JSON protocol. Please update to 'supertools-bun-014' or later: Sandbox.create('supertools-bun-014')`;
|
|
2642
|
+
this.log(error);
|
|
2643
|
+
this.state.error = error;
|
|
2644
|
+
this.state.resolver?.({ success: false, error });
|
|
2645
|
+
this.state.resolver = null;
|
|
2646
|
+
return;
|
|
2647
|
+
}
|
|
2648
|
+
const buffer = this.toArrayBuffer(data);
|
|
2649
|
+
if (!buffer) {
|
|
2641
2650
|
this.log("Expected binary message");
|
|
2642
2651
|
return;
|
|
2643
2652
|
}
|
|
2644
|
-
if (
|
|
2645
|
-
this.log(`Message too large: ${
|
|
2653
|
+
if (buffer.byteLength > MAX_MESSAGE_SIZE) {
|
|
2654
|
+
this.log(`Message too large: ${buffer.byteLength}`);
|
|
2646
2655
|
return;
|
|
2647
2656
|
}
|
|
2648
2657
|
let msg;
|
|
2649
2658
|
try {
|
|
2650
|
-
msg = decode(
|
|
2659
|
+
msg = decode(buffer);
|
|
2651
2660
|
} catch (e) {
|
|
2652
2661
|
this.log("Decode error:", e);
|
|
2653
2662
|
return;
|
|
@@ -2696,6 +2705,18 @@ class RelayClient {
|
|
|
2696
2705
|
this.send("tool_result", { id, success: false, error });
|
|
2697
2706
|
}
|
|
2698
2707
|
}
|
|
2708
|
+
toArrayBuffer(data) {
|
|
2709
|
+
if (data instanceof ArrayBuffer) {
|
|
2710
|
+
return data;
|
|
2711
|
+
}
|
|
2712
|
+
if (ArrayBuffer.isView(data)) {
|
|
2713
|
+
const { buffer, byteOffset, byteLength } = data;
|
|
2714
|
+
if (buffer instanceof ArrayBuffer) {
|
|
2715
|
+
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
return null;
|
|
2719
|
+
}
|
|
2699
2720
|
send(type, payload) {
|
|
2700
2721
|
if (!this.connected) {
|
|
2701
2722
|
this.log("Not connected");
|
|
@@ -16932,6 +16953,9 @@ function supertools(client, config2) {
|
|
|
16932
16953
|
throw new ConfigurationError(`Unknown provider: ${provider}`);
|
|
16933
16954
|
}
|
|
16934
16955
|
}
|
|
16956
|
+
|
|
16957
|
+
// src/index.ts
|
|
16958
|
+
var SANDBOX_TEMPLATE = "supertools-bun-014";
|
|
16935
16959
|
export {
|
|
16936
16960
|
exports_external as z,
|
|
16937
16961
|
supertools,
|
|
@@ -16945,6 +16969,7 @@ export {
|
|
|
16945
16969
|
buildSystemPrompt,
|
|
16946
16970
|
ToolError,
|
|
16947
16971
|
SandboxError,
|
|
16972
|
+
SANDBOX_TEMPLATE,
|
|
16948
16973
|
RelayTimeoutError,
|
|
16949
16974
|
RelayConnectionError,
|
|
16950
16975
|
ProgrammaticExecutor,
|
package/dist/relay/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Relay Client
|
|
3
3
|
*
|
|
4
|
+
*
|
|
4
5
|
* WebSocket client for bidirectional communication with the sandbox relay.
|
|
5
6
|
* Uses Protocol Buffers for efficient binary encoding.
|
|
6
7
|
*/
|
|
@@ -39,6 +40,7 @@ export declare class RelayClient {
|
|
|
39
40
|
private onMessage;
|
|
40
41
|
private handleMessage;
|
|
41
42
|
private handleToolCall;
|
|
43
|
+
private toArrayBuffer;
|
|
42
44
|
private send;
|
|
43
45
|
}
|
|
44
46
|
export declare function createRelayClient(config: RelayClientConfig): RelayClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/relay/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/relay/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE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