@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
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const TOOL_BRAND: unique symbol;
|
|
5
|
+
type ZodSchema = z.ZodType;
|
|
6
|
+
type InferInput<T extends ZodSchema> = z.infer<T>;
|
|
7
|
+
type ExecuteFn<T extends ZodSchema> = (params: InferInput<T>) => unknown | Promise<unknown>;
|
|
8
|
+
interface ToolDefinition<T extends ZodSchema> {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly description: string;
|
|
11
|
+
readonly parameters: T;
|
|
12
|
+
readonly execute: ExecuteFn<T>;
|
|
13
|
+
}
|
|
14
|
+
interface Tool<T extends ZodSchema = ZodSchema> {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
readonly parameters: T;
|
|
18
|
+
readonly execute: ExecuteFn<T>;
|
|
19
|
+
readonly [TOOL_BRAND]: true;
|
|
20
|
+
}
|
|
21
|
+
interface NormalizedParameter {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'any';
|
|
24
|
+
readonly description: string;
|
|
25
|
+
readonly required: boolean;
|
|
26
|
+
readonly default?: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface NormalizedTool {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly description: string;
|
|
31
|
+
readonly parameters: readonly NormalizedParameter[];
|
|
32
|
+
readonly execute: (params: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Define a tool with type-safe parameters.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const searchUsers = defineTool({
|
|
39
|
+
* name: 'searchUsers',
|
|
40
|
+
* description: 'Search users by name or email',
|
|
41
|
+
* parameters: z.object({
|
|
42
|
+
* query: z.string().describe('Search query'),
|
|
43
|
+
* limit: z.number().optional().default(10),
|
|
44
|
+
* }),
|
|
45
|
+
* execute: async ({ query, limit }) => db.users.search(query).limit(limit),
|
|
46
|
+
* });
|
|
47
|
+
*/
|
|
48
|
+
declare function defineTool<T extends ZodSchema>(definition: ToolDefinition<T>): Tool<T>;
|
|
49
|
+
declare function isTool(value: unknown): value is Tool;
|
|
50
|
+
declare function normalizeTools(tools: readonly Tool[]): NormalizedTool[];
|
|
51
|
+
|
|
52
|
+
type ToolCollection = readonly Tool[];
|
|
53
|
+
interface ExecutionResult {
|
|
54
|
+
readonly success: boolean;
|
|
55
|
+
readonly output: string;
|
|
56
|
+
readonly error?: string;
|
|
57
|
+
readonly executionTimeMs: number;
|
|
58
|
+
readonly images?: readonly string[];
|
|
59
|
+
}
|
|
60
|
+
interface GeneratedCode {
|
|
61
|
+
readonly code: string;
|
|
62
|
+
readonly explanation?: string;
|
|
63
|
+
readonly rawResponse?: string;
|
|
64
|
+
}
|
|
65
|
+
interface ProgrammaticResult {
|
|
66
|
+
readonly code: string;
|
|
67
|
+
readonly explanation?: string;
|
|
68
|
+
readonly result: ExecutionResult;
|
|
69
|
+
}
|
|
70
|
+
interface ToolCallRequest {
|
|
71
|
+
readonly tool: string;
|
|
72
|
+
readonly arguments: Readonly<Record<string, unknown>>;
|
|
73
|
+
}
|
|
74
|
+
interface ToolCallResponse {
|
|
75
|
+
readonly success: boolean;
|
|
76
|
+
readonly result?: unknown;
|
|
77
|
+
readonly error?: string;
|
|
78
|
+
}
|
|
79
|
+
interface LLMAdapter {
|
|
80
|
+
generateCode(userRequest: string, systemPrompt: string): Promise<GeneratedCode>;
|
|
81
|
+
}
|
|
82
|
+
interface ExecutorConfig {
|
|
83
|
+
readonly tools: ToolCollection;
|
|
84
|
+
readonly timeout?: number;
|
|
85
|
+
readonly e2bApiKey?: string;
|
|
86
|
+
readonly instructions?: string;
|
|
87
|
+
readonly debug?: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Programmatic Executor
|
|
92
|
+
*
|
|
93
|
+
* Orchestrates the complete flow:
|
|
94
|
+
* 1. LLM generates JavaScript code
|
|
95
|
+
* 2. Code executes in secure E2B Bun sandbox
|
|
96
|
+
* 3. Tool calls relay back to host via WebSocket
|
|
97
|
+
* 4. Results return to user
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
interface CreateExecutorOptions extends ExecutorConfig {
|
|
101
|
+
readonly llm: LLMAdapter;
|
|
102
|
+
}
|
|
103
|
+
declare function createExecutor(options: CreateExecutorOptions): ProgrammaticExecutor;
|
|
104
|
+
declare class ProgrammaticExecutor {
|
|
105
|
+
private readonly originalTools;
|
|
106
|
+
private readonly normalizedTools;
|
|
107
|
+
private readonly toolsMap;
|
|
108
|
+
private readonly llm;
|
|
109
|
+
private readonly timeout;
|
|
110
|
+
private readonly e2bApiKey?;
|
|
111
|
+
private readonly instructions?;
|
|
112
|
+
private readonly debug;
|
|
113
|
+
constructor(options: CreateExecutorOptions);
|
|
114
|
+
run(userRequest: string): Promise<ProgrammaticResult>;
|
|
115
|
+
executeCode(code: string): Promise<ExecutionResult>;
|
|
116
|
+
getTools(): readonly NormalizedTool[];
|
|
117
|
+
getToolDocumentation(): string;
|
|
118
|
+
private generateCode;
|
|
119
|
+
private createSandbox;
|
|
120
|
+
private connectRelay;
|
|
121
|
+
private cleanup;
|
|
122
|
+
private log;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
type ErrorCode = 'CODE_GENERATION_ERROR' | 'EXECUTION_ERROR' | 'TOOL_ERROR' | 'RELAY_CONNECTION_ERROR' | 'RELAY_TIMEOUT_ERROR' | 'PROTOCOL_ERROR' | 'SANDBOX_ERROR' | 'AUTHENTICATION_ERROR' | 'VALIDATION_ERROR' | 'CONFIGURATION_ERROR';
|
|
126
|
+
declare class OPTError extends Error {
|
|
127
|
+
readonly code: ErrorCode;
|
|
128
|
+
readonly cause?: Error;
|
|
129
|
+
constructor(message: string, code: ErrorCode, cause?: Error);
|
|
130
|
+
toJSON(): {
|
|
131
|
+
name: string;
|
|
132
|
+
code: ErrorCode;
|
|
133
|
+
message: string;
|
|
134
|
+
cause: string | undefined;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
declare class CodeGenerationError extends OPTError {
|
|
138
|
+
constructor(message: string, cause?: Error);
|
|
139
|
+
}
|
|
140
|
+
declare class ExecutionError extends OPTError {
|
|
141
|
+
readonly output?: string;
|
|
142
|
+
constructor(message: string, output?: string, cause?: Error);
|
|
143
|
+
toJSON(): {
|
|
144
|
+
output: string | undefined;
|
|
145
|
+
name: string;
|
|
146
|
+
code: ErrorCode;
|
|
147
|
+
message: string;
|
|
148
|
+
cause: string | undefined;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
declare class ToolError extends OPTError {
|
|
152
|
+
readonly toolName: string;
|
|
153
|
+
constructor(message: string, toolName: string, cause?: Error);
|
|
154
|
+
toJSON(): {
|
|
155
|
+
toolName: string;
|
|
156
|
+
name: string;
|
|
157
|
+
code: ErrorCode;
|
|
158
|
+
message: string;
|
|
159
|
+
cause: string | undefined;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
declare class RelayConnectionError extends OPTError {
|
|
163
|
+
constructor(message: string, cause?: Error);
|
|
164
|
+
}
|
|
165
|
+
declare class RelayTimeoutError extends OPTError {
|
|
166
|
+
constructor(message: string);
|
|
167
|
+
}
|
|
168
|
+
declare class SandboxError extends OPTError {
|
|
169
|
+
constructor(message: string, cause?: Error);
|
|
170
|
+
}
|
|
171
|
+
declare class AuthenticationError extends OPTError {
|
|
172
|
+
constructor(message: string);
|
|
173
|
+
}
|
|
174
|
+
declare class ConfigurationError extends OPTError {
|
|
175
|
+
constructor(message: string);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
declare function buildSystemPrompt(toolDefinitions: string, additionalInstructions?: string): string;
|
|
179
|
+
declare function extractCode(response: string): string;
|
|
180
|
+
|
|
181
|
+
declare function generateTypeHints(tools: readonly Tool[]): string;
|
|
182
|
+
|
|
183
|
+
export { AuthenticationError, CodeGenerationError, ConfigurationError, type CreateExecutorOptions, ExecutionError, type ExecutionResult, type ExecutorConfig, type GeneratedCode, type LLMAdapter, type NormalizedParameter, type NormalizedTool, OPTError, ProgrammaticExecutor, type ProgrammaticResult, RelayConnectionError, RelayTimeoutError, SandboxError, type Tool, type ToolCallRequest, type ToolCallResponse, type ToolCollection, type ToolDefinition, ToolError, buildSystemPrompt, createExecutor, defineTool, extractCode, generateTypeHints, isTool, normalizeTools };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supertools
|
|
3
|
+
*
|
|
4
|
+
* Let any LLM write code that calls your tools.
|
|
5
|
+
* 10x faster. 90% cheaper.
|
|
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 queryDb = defineTool({
|
|
14
|
+
* name: 'queryDatabase',
|
|
15
|
+
* description: 'Execute a SQL query',
|
|
16
|
+
* parameters: z.object({
|
|
17
|
+
* sql: z.string().describe('The SQL query to execute'),
|
|
18
|
+
* }),
|
|
19
|
+
* execute: async ({ sql }) => db.query(sql),
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Create sandbox and wrap your SDK client
|
|
23
|
+
* const sandbox = await Sandbox.create('supertools-bun');
|
|
24
|
+
* const client = supertools(new Anthropic(), { tools: [queryDb], sandbox });
|
|
25
|
+
*
|
|
26
|
+
* // Use exactly like normal - tools execute automatically
|
|
27
|
+
* const response = await client.messages.create({
|
|
28
|
+
* model: 'claude-haiku-4-5-20251001',
|
|
29
|
+
* max_tokens: 1024,
|
|
30
|
+
* messages: [{ role: 'user', content: 'List all admin users' }],
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @packageDocumentation
|
|
35
|
+
*/
|
|
36
|
+
export { supertools, detectProvider } from './supertools';
|
|
37
|
+
export type { SupertoolsConfig, SupportedProvider } from './supertools';
|
|
38
|
+
export { defineTool, z } from './tool';
|
|
39
|
+
export type { Tool, ToolDefinition } from './tool';
|
|
40
|
+
export { createExecutor, ProgrammaticExecutor } from './executor';
|
|
41
|
+
export type { CreateExecutorOptions } from './executor';
|
|
42
|
+
export type { ToolCollection, ExecutionResult, GeneratedCode, ProgrammaticResult, ToolCallRequest, ToolCallResponse, LLMAdapter, ExecutorConfig, ExecutionEvent, } from './types';
|
|
43
|
+
export { OPTError, CodeGenerationError, ExecutionError, ToolError, RelayConnectionError, RelayTimeoutError, SandboxError, ConfigurationError, } from './utils/errors';
|
|
44
|
+
export { buildSystemPrompt, extractCode } from './prompts';
|
|
45
|
+
export { generateTypeHints } from './utils/type-hints';
|
|
46
|
+
export { normalizeTools, isTool } from './tool';
|
|
47
|
+
export type { NormalizedTool, NormalizedParameter } from './tool';
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC"}
|