@supertools-ai/core 0.1.0
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 +379 -0
- package/dist/__tests__/protocol.test.d.ts +5 -0
- package/dist/__tests__/protocol.test.d.ts.map +1 -0
- package/dist/__tests__/security.test.d.ts +5 -0
- package/dist/__tests__/security.test.d.ts.map +1 -0
- package/dist/__tests__/tool.test.d.ts +5 -0
- package/dist/__tests__/tool.test.d.ts.map +1 -0
- package/dist/errors.d.ts +64 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/executor.d.ts +38 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/index.d.mts +183 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14556 -0
- package/dist/index.mjs +937 -0
- package/dist/mcp/client.d.ts +48 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +9 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/schema.d.ts +20 -0
- package/dist/mcp/schema.d.ts.map +1 -0
- package/dist/mcp/types.d.ts +96 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/prompts.d.ts +7 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/providers/anthropic.d.ts +63 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/relay/client.d.ts +46 -0
- package/dist/relay/client.d.ts.map +1 -0
- package/dist/relay/index.d.ts +11 -0
- package/dist/relay/index.d.ts.map +1 -0
- package/dist/relay/protocol.d.ts +84 -0
- package/dist/relay/protocol.d.ts.map +1 -0
- package/dist/relay/security.d.ts +4 -0
- package/dist/relay/security.d.ts.map +1 -0
- package/dist/relay/server.d.ts +15 -0
- package/dist/relay/server.d.ts.map +1 -0
- package/dist/relay/types.d.ts +16 -0
- package/dist/relay/types.d.ts.map +1 -0
- package/dist/relay/utils/protocol.d.ts +92 -0
- package/dist/relay/utils/protocol.d.ts.map +1 -0
- package/dist/relay/utils/token.d.ts +4 -0
- package/dist/relay/utils/token.d.ts.map +1 -0
- package/dist/supertools.d.ts +90 -0
- package/dist/supertools.d.ts.map +1 -0
- package/dist/tool.d.ts +66 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/type-hints.d.ts +3 -0
- package/dist/type-hints.d.ts.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +50 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/sandbox-pool.d.ts +63 -0
- package/dist/utils/sandbox-pool.d.ts.map +1 -0
- package/dist/utils/string.d.ts +5 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/type-hints.d.ts +3 -0
- package/dist/utils/type-hints.d.ts.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supertools
|
|
3
|
+
*
|
|
4
|
+
* Wrap any LLM SDK client with programmatic tool calling.
|
|
5
|
+
* Auto-detects the provider and applies the appropriate wrapper.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { supertools, defineTool, z } from '@supertools-ai/core';
|
|
10
|
+
* import { Sandbox } from 'e2b';
|
|
11
|
+
* import Anthropic from '@anthropic-ai/sdk';
|
|
12
|
+
*
|
|
13
|
+
* const tools = [
|
|
14
|
+
* defineTool({
|
|
15
|
+
* name: 'queryDatabase',
|
|
16
|
+
* description: 'Execute a SQL query',
|
|
17
|
+
* parameters: z.object({ sql: z.string() }),
|
|
18
|
+
* returns: z.array(z.record(z.any())),
|
|
19
|
+
* execute: async ({ sql }) => db.query(sql),
|
|
20
|
+
* }),
|
|
21
|
+
* ];
|
|
22
|
+
*
|
|
23
|
+
* const sandbox = await Sandbox.create('supertools-bun');
|
|
24
|
+
* const client = supertools(new Anthropic(), { tools, sandbox });
|
|
25
|
+
*
|
|
26
|
+
* // Use exactly like the normal SDK
|
|
27
|
+
* const response = await client.messages.create({
|
|
28
|
+
* model: 'claude-haiku-4-5-20251001',
|
|
29
|
+
* max_tokens: 1024,
|
|
30
|
+
* messages: [{ role: 'user', content: 'Query all users and summarize' }],
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
import type { Sandbox } from 'e2b';
|
|
35
|
+
import type { AnyTool } from './tool';
|
|
36
|
+
import type { ExecutionEvent } from './types';
|
|
37
|
+
/**
|
|
38
|
+
* Configuration options for supertools
|
|
39
|
+
*/
|
|
40
|
+
export interface SupertoolsConfig {
|
|
41
|
+
/** Tools to make available */
|
|
42
|
+
readonly tools: readonly AnyTool[];
|
|
43
|
+
/** Pre-created E2B sandbox - caller manages lifecycle */
|
|
44
|
+
readonly sandbox: Sandbox;
|
|
45
|
+
/** Additional instructions for the LLM */
|
|
46
|
+
readonly instructions?: string;
|
|
47
|
+
/** Enable debug logging */
|
|
48
|
+
readonly debug?: boolean;
|
|
49
|
+
/** Callback for structured execution events */
|
|
50
|
+
readonly onEvent?: (event: ExecutionEvent) => void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Supported provider types
|
|
54
|
+
*/
|
|
55
|
+
export type SupportedProvider = 'anthropic';
|
|
56
|
+
/**
|
|
57
|
+
* Detect the provider type from a client instance
|
|
58
|
+
*/
|
|
59
|
+
export declare function detectProvider(client: unknown): SupportedProvider | null;
|
|
60
|
+
/**
|
|
61
|
+
* Wrap an LLM SDK client with programmatic tool calling.
|
|
62
|
+
*
|
|
63
|
+
* The wrapper intercepts API calls and automatically generates code
|
|
64
|
+
* that runs all tool calls in a secure sandbox, returning results
|
|
65
|
+
* in the expected SDK format.
|
|
66
|
+
*
|
|
67
|
+
* @param client - An LLM SDK client (Anthropic, OpenAI, etc.)
|
|
68
|
+
* @param config - Configuration including tools to make available
|
|
69
|
+
* @returns A wrapped client that behaves like the original
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const sandbox = await Sandbox.create('supertools-bun');
|
|
74
|
+
* const client = supertools(new Anthropic(), {
|
|
75
|
+
* tools: [queryDb, sendEmail],
|
|
76
|
+
* sandbox,
|
|
77
|
+
* debug: true,
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* // Works exactly like the normal Anthropic SDK
|
|
81
|
+
* const response = await client.messages.create({
|
|
82
|
+
* model: 'claude-haiku-4-5-20251001',
|
|
83
|
+
* max_tokens: 1024,
|
|
84
|
+
* messages: [{ role: 'user', content: 'Find top users and email report' }],
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function supertools<T>(client: T, config: SupertoolsConfig): T;
|
|
89
|
+
export default supertools;
|
|
90
|
+
//# sourceMappingURL=supertools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supertools.d.ts","sourceRoot":"","sources":["../src/supertools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,CAAC;IACnC,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,0CAA0C;IAC1C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAE5C;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,iBAAiB,GAAG,IAAI,CAKxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,gBAAgB,GAAG,CAAC,CA2BpE;AAED,eAAe,UAAU,CAAC"}
|
package/dist/tool.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const TOOL_BRAND: unique symbol;
|
|
3
|
+
type ZodSchema = z.ZodType;
|
|
4
|
+
type InferInput<T extends ZodSchema> = z.infer<T>;
|
|
5
|
+
type InferOutput<T extends ZodSchema> = z.infer<T>;
|
|
6
|
+
type ExecuteFn<TParams extends ZodSchema, TReturns extends ZodSchema | undefined> = (params: InferInput<TParams>) => TReturns extends ZodSchema ? InferOutput<TReturns> | Promise<InferOutput<TReturns>> : unknown | Promise<unknown>;
|
|
7
|
+
export interface ToolDefinition<TParams extends ZodSchema, TReturns extends ZodSchema | undefined = undefined> {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly description: string;
|
|
10
|
+
readonly parameters: TParams;
|
|
11
|
+
readonly returns?: TReturns;
|
|
12
|
+
readonly execute: ExecuteFn<TParams, TReturns>;
|
|
13
|
+
/**
|
|
14
|
+
* If true, tool runs locally in sandbox (no network round-trip).
|
|
15
|
+
* Use for pure computation that doesn't need host resources.
|
|
16
|
+
*/
|
|
17
|
+
readonly local?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface Tool<TParams extends ZodSchema = ZodSchema, TReturns extends ZodSchema | undefined = undefined> {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
readonly parameters: TParams;
|
|
23
|
+
readonly returns?: TReturns;
|
|
24
|
+
readonly execute: ExecuteFn<TParams, TReturns>;
|
|
25
|
+
readonly local?: boolean;
|
|
26
|
+
readonly [TOOL_BRAND]: true;
|
|
27
|
+
}
|
|
28
|
+
export type AnyTool = Tool<ZodSchema, ZodSchema | undefined>;
|
|
29
|
+
export interface NormalizedParameter {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'any';
|
|
32
|
+
readonly description: string;
|
|
33
|
+
readonly required: boolean;
|
|
34
|
+
readonly default?: unknown;
|
|
35
|
+
}
|
|
36
|
+
export interface NormalizedTool {
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly description: string;
|
|
39
|
+
readonly parameters: readonly NormalizedParameter[];
|
|
40
|
+
readonly execute: (params: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
41
|
+
/** If set, this tool runs locally in sandbox using this code */
|
|
42
|
+
readonly localCode?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Define a tool with type-safe parameters and optional return type.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const searchUsers = defineTool({
|
|
49
|
+
* name: 'searchUsers',
|
|
50
|
+
* description: 'Search users by name or email',
|
|
51
|
+
* parameters: z.object({
|
|
52
|
+
* query: z.string().describe('Search query'),
|
|
53
|
+
* limit: z.number().optional().default(10),
|
|
54
|
+
* }),
|
|
55
|
+
* returns: z.array(z.object({
|
|
56
|
+
* id: z.number(),
|
|
57
|
+
* name: z.string(),
|
|
58
|
+
* })),
|
|
59
|
+
* execute: async ({ query, limit }) => db.users.search(query).limit(limit),
|
|
60
|
+
* });
|
|
61
|
+
*/
|
|
62
|
+
export declare function defineTool<TParams extends ZodSchema, TReturns extends ZodSchema | undefined = undefined>(definition: ToolDefinition<TParams, TReturns>): Tool<TParams, TReturns>;
|
|
63
|
+
export declare function isTool(value: unknown): value is Tool;
|
|
64
|
+
export declare function normalizeTools(tools: readonly AnyTool[]): NormalizedTool[];
|
|
65
|
+
export { z };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;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,EACtG,UAAU,EAAE,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC5C,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAgCzB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAOpD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,cAAc,EAAE,CAoB1E;AA2ID,OAAO,EAAE,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-hints.d.ts","sourceRoot":"","sources":["../src/type-hints.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAqBnC,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,CAKhE"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Sandbox } from 'e2b';
|
|
2
|
+
import type { AnyTool } from './tool';
|
|
3
|
+
export type ToolCollection = readonly AnyTool[];
|
|
4
|
+
export interface ExecutionResult {
|
|
5
|
+
readonly success: boolean;
|
|
6
|
+
readonly output: string;
|
|
7
|
+
readonly error?: string;
|
|
8
|
+
readonly executionTimeMs: number;
|
|
9
|
+
readonly images?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
export interface GeneratedCode {
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly explanation?: string;
|
|
14
|
+
readonly rawResponse?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ProgrammaticResult {
|
|
17
|
+
readonly code: string;
|
|
18
|
+
readonly explanation?: string;
|
|
19
|
+
readonly result: ExecutionResult;
|
|
20
|
+
}
|
|
21
|
+
export interface ToolCallRequest {
|
|
22
|
+
readonly tool: string;
|
|
23
|
+
readonly arguments: Readonly<Record<string, unknown>>;
|
|
24
|
+
}
|
|
25
|
+
export interface ToolCallResponse {
|
|
26
|
+
readonly success: boolean;
|
|
27
|
+
readonly result?: unknown;
|
|
28
|
+
readonly error?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface LLMAdapter {
|
|
31
|
+
generateCode(userRequest: string, systemPrompt: string): Promise<GeneratedCode>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Structured execution events for real-time progress tracking
|
|
35
|
+
*/
|
|
36
|
+
export type ExecutionEvent = {
|
|
37
|
+
readonly type: 'code_generated';
|
|
38
|
+
readonly code: string;
|
|
39
|
+
readonly explanation?: string;
|
|
40
|
+
} | {
|
|
41
|
+
readonly type: 'sandbox_ready';
|
|
42
|
+
readonly sandboxId: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly type: 'tool_call';
|
|
45
|
+
readonly tool: string;
|
|
46
|
+
readonly arguments: Record<string, unknown>;
|
|
47
|
+
readonly callId: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: 'tool_result';
|
|
50
|
+
readonly tool: string;
|
|
51
|
+
readonly result: unknown;
|
|
52
|
+
readonly callId: string;
|
|
53
|
+
readonly durationMs: number;
|
|
54
|
+
} | {
|
|
55
|
+
readonly type: 'tool_error';
|
|
56
|
+
readonly tool: string;
|
|
57
|
+
readonly error: string;
|
|
58
|
+
readonly callId: string;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: 'result';
|
|
61
|
+
readonly data: unknown;
|
|
62
|
+
} | {
|
|
63
|
+
readonly type: 'stdout';
|
|
64
|
+
readonly data: string;
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: 'stderr';
|
|
67
|
+
readonly data: string;
|
|
68
|
+
} | {
|
|
69
|
+
readonly type: 'complete';
|
|
70
|
+
readonly success: boolean;
|
|
71
|
+
readonly output: string;
|
|
72
|
+
readonly error?: string;
|
|
73
|
+
};
|
|
74
|
+
export interface ExecutorConfig {
|
|
75
|
+
readonly tools: ToolCollection;
|
|
76
|
+
/** Pre-created sandbox - you manage its lifecycle */
|
|
77
|
+
readonly sandbox: Sandbox;
|
|
78
|
+
/** Additional instructions for the LLM */
|
|
79
|
+
readonly instructions?: string;
|
|
80
|
+
/** Enable debug logging */
|
|
81
|
+
readonly debug?: boolean;
|
|
82
|
+
/** Callback for structured execution events */
|
|
83
|
+
readonly onEvent?: (event: ExecutionEvent) => void;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,cAAc,GAAG,SAAS,OAAO,EAAE,CAAC;AAEhD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CAClC;AAED,MAAM,WAAW,e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error {
|
|
3
|
+
readonly code: ErrorCode;
|
|
4
|
+
readonly cause?: Error;
|
|
5
|
+
constructor(message: string, code: ErrorCode, cause?: Error);
|
|
6
|
+
toJSON(): {
|
|
7
|
+
name: string;
|
|
8
|
+
code: ErrorCode;
|
|
9
|
+
message: string;
|
|
10
|
+
cause: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare class CodeGenerationError extends OPTError {
|
|
14
|
+
constructor(message: string, cause?: Error);
|
|
15
|
+
}
|
|
16
|
+
export declare class ExecutionError extends OPTError {
|
|
17
|
+
readonly output?: string;
|
|
18
|
+
constructor(message: string, output?: string, cause?: Error);
|
|
19
|
+
toJSON(): {
|
|
20
|
+
output: string | undefined;
|
|
21
|
+
name: string;
|
|
22
|
+
code: ErrorCode;
|
|
23
|
+
message: string;
|
|
24
|
+
cause: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare class ToolError extends OPTError {
|
|
28
|
+
readonly toolName: string;
|
|
29
|
+
constructor(message: string, toolName: string, cause?: Error);
|
|
30
|
+
toJSON(): {
|
|
31
|
+
toolName: string;
|
|
32
|
+
name: string;
|
|
33
|
+
code: ErrorCode;
|
|
34
|
+
message: string;
|
|
35
|
+
cause: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export declare class RelayConnectionError extends OPTError {
|
|
39
|
+
constructor(message: string, cause?: Error);
|
|
40
|
+
}
|
|
41
|
+
export declare class RelayTimeoutError extends OPTError {
|
|
42
|
+
constructor(message: string);
|
|
43
|
+
}
|
|
44
|
+
export declare class SandboxError extends OPTError {
|
|
45
|
+
constructor(message: string, cause?: Error);
|
|
46
|
+
}
|
|
47
|
+
export declare class ConfigurationError extends OPTError {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox Pool
|
|
3
|
+
*
|
|
4
|
+
* Pre-warms sandboxes to eliminate cold start latency.
|
|
5
|
+
* Sandboxes are created in advance and reused.
|
|
6
|
+
*/
|
|
7
|
+
import { Sandbox } from '@e2b/code-interpreter';
|
|
8
|
+
export interface SandboxPoolOptions {
|
|
9
|
+
/** Number of sandboxes to keep warm (default: 1) */
|
|
10
|
+
readonly size?: number;
|
|
11
|
+
/** E2B API key (default: E2B_API_KEY env) */
|
|
12
|
+
readonly apiKey?: string;
|
|
13
|
+
/** Sandbox timeout in ms (default: 300000) */
|
|
14
|
+
readonly timeoutMs?: number;
|
|
15
|
+
/** Template name (default: 'supertools-bun') */
|
|
16
|
+
readonly template?: string;
|
|
17
|
+
/** Enable debug logging */
|
|
18
|
+
readonly debug?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class SandboxPool {
|
|
21
|
+
private readonly pool;
|
|
22
|
+
private readonly size;
|
|
23
|
+
private readonly apiKey?;
|
|
24
|
+
private readonly timeoutMs;
|
|
25
|
+
private readonly template;
|
|
26
|
+
private readonly debug;
|
|
27
|
+
private warming;
|
|
28
|
+
private closed;
|
|
29
|
+
constructor(options?: SandboxPoolOptions);
|
|
30
|
+
private log;
|
|
31
|
+
/**
|
|
32
|
+
* Pre-warm the pool with sandboxes.
|
|
33
|
+
* Call this once at startup for optimal performance.
|
|
34
|
+
*/
|
|
35
|
+
warmup(): Promise<void>;
|
|
36
|
+
private doWarmup;
|
|
37
|
+
private createSandbox;
|
|
38
|
+
/**
|
|
39
|
+
* Acquire a sandbox from the pool.
|
|
40
|
+
* If pool is empty, creates a new one.
|
|
41
|
+
* The sandbox is removed from the pool and must be returned or killed.
|
|
42
|
+
*/
|
|
43
|
+
acquire(): Promise<Sandbox>;
|
|
44
|
+
private refillInBackground;
|
|
45
|
+
/**
|
|
46
|
+
* Return a sandbox to the pool for reuse.
|
|
47
|
+
* Only call if the sandbox is still healthy.
|
|
48
|
+
*/
|
|
49
|
+
release(sandbox: Sandbox): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Close the pool and kill all sandboxes.
|
|
52
|
+
*/
|
|
53
|
+
close(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Get current pool size.
|
|
56
|
+
*/
|
|
57
|
+
get available(): number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a new sandbox pool.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createSandboxPool(options?: SandboxPoolOptions): SandboxPool;
|
|
63
|
+
//# sourceMappingURL=sandbox-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-pool.d.ts","sourceRoot":"","sources":["../../src/utils/sandbox-pool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,8CAA8C;IAC9C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IACtC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,GAAE,kBAAuB;IAQ5C,OAAO,CAAC,GAAG;IAIX;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;YASf,QAAQ;YAiBR,aAAa;IAO3B;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAoBjC,OAAO,CAAC,kBAAkB;IAU1B;;;OAGG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAE3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/utils/string.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-hints.d.ts","sourceRoot":"","sources":["../../src/utils/type-hints.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAsBvC,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAKnE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@supertools-ai/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Programmatic tool calling for LLMs - let AI write code that orchestrates your tools",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "bun build src/index.ts --outdir dist --target node --format esm && tsc --emitDeclarationOnly",
|
|
22
|
+
"dev": "bun --watch src/index.ts",
|
|
23
|
+
"test": "bun test",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"prepublishOnly": "cp ../../README.md . && bun run build && bun run test"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"e2b": "^2.9.0",
|
|
29
|
+
"zod": "^4.2.1"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@anthropic-ai/sdk": ">=0.30.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@anthropic-ai/sdk": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@anthropic-ai/sdk": "^0.30.0",
|
|
41
|
+
"@types/bun": "latest",
|
|
42
|
+
"@types/node": "^20.10.0",
|
|
43
|
+
"typescript": "^5.3.0"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"supertools",
|
|
47
|
+
"llm",
|
|
48
|
+
"tool-calling",
|
|
49
|
+
"programmatic",
|
|
50
|
+
"code-execution",
|
|
51
|
+
"e2b",
|
|
52
|
+
"sandbox",
|
|
53
|
+
"anthropic",
|
|
54
|
+
"openai",
|
|
55
|
+
"ai",
|
|
56
|
+
"agents",
|
|
57
|
+
"claude"
|
|
58
|
+
],
|
|
59
|
+
"author": "Filip Brebera",
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"homepage": "https://github.com/bxxf/supertools#readme",
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/bxxf/supertools/issues"
|
|
64
|
+
},
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "git+https://github.com/bxxf/supertools.git",
|
|
68
|
+
"directory": "packages/core"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=18.0.0"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public"
|
|
75
|
+
},
|
|
76
|
+
"sideEffects": false
|
|
77
|
+
}
|