ai-code-agents 0.1.0-beta.1

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/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Felix Arntz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,231 @@
1
+ # AI Code Agents
2
+
3
+ A TypeScript SDK for creating AI agents that interact with sandboxed code execution environments. Built on the [Vercel AI SDK](https://ai-sdk.dev/), it provides a flexible, type-safe framework for building AI coding agents—for vibe coding, coding assistance, or multi-agentic workflows—with comprehensive tool support and environment abstraction.
4
+
5
+ ## Key Features
6
+
7
+ - **🔓 No Vendor Lock-in**: Environment abstraction layer works across any execution environment (local, Docker, cloud sandboxes). Model-agnostic architecture supports any AI provider through the Vercel AI SDK.
8
+ - **🛡️ Type-Safe**: Full TypeScript support with strict typing and comprehensive Zod schemas for all tool inputs/outputs.
9
+ - **🔧 Flexible Tool System**: Several built-in tools with configurable safety levels (`readonly`, `basic`, `all`). Easy to extend with custom tools.
10
+ - **🌍 Environment Abstraction**: Write tools once, run anywhere. All tools work seamlessly across different environment implementations.
11
+ - **📦 Multiple Environments**: Support for single or multiple environments per agent, enabling complex multi-context workflows.
12
+ - **🎯 Step-by-Step Execution**: Built-in step tracking and logging for transparent agent behavior.
13
+
14
+ ## Installation
15
+
16
+ You will need Node.js 20+ and npm or another package manager installed on your local machine.
17
+
18
+ ```bash
19
+ npm install ai-code-agents
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import { openai } from '@ai-sdk/openai';
26
+ import { createCodeAgent, createEnvironment } from 'ai-code-agents';
27
+
28
+ // Create a Docker environment (requires a running container)
29
+ const environment = createEnvironment('docker', {
30
+ containerId: 'my-container-id',
31
+ directoryPath: '/workspace',
32
+ });
33
+
34
+ // Create an agent with all tools
35
+ const agent = createCodeAgent({
36
+ model: openai('gpt-4'),
37
+ environment,
38
+ environmentToolsDefinition: 'all',
39
+ maxSteps: 10,
40
+ });
41
+
42
+ // Run the agent
43
+ const result = await agent.execute({
44
+ prompt: 'Create a simple Node.js HTTP server in server.js',
45
+ });
46
+
47
+ console.log(result.text);
48
+ ```
49
+
50
+ ## Core Concepts
51
+
52
+ ### Environments
53
+
54
+ Environments provide sandboxed execution contexts for agents. All tools are built against environment interfaces, ensuring complete interoperability.
55
+
56
+ **Currently Available:**
57
+
58
+ - `docker` - Docker container environments
59
+ - `node-filesystem` - Node.js filesystem operations (read-only recommended)
60
+ - `unsafe-local` - Local filesystem with command execution (development only)
61
+ - `mock-filesystem` - In-memory filesystem for testing
62
+
63
+ **Planned:**
64
+
65
+ - `e2b` - E2B cloud sandboxes
66
+ - `vercel-sandbox` - Vercel sandbox environments
67
+
68
+ ### Tools
69
+
70
+ Tools enable agents to interact with their environments. Each tool has a well-defined purpose with comprehensive input/output validation.
71
+
72
+ **Currently Available:**
73
+
74
+ - `read_file` - Read file contents
75
+ - `write_file` - Write or create files
76
+ - `delete_file` - Delete files
77
+ - `edit_file` - Edit files with search/replace operations
78
+ - `move_file` - Move or rename files
79
+ - `copy_file` - Copy files
80
+ - `read_many_files` - Batch read multiple files
81
+ - `get_project_file_structure` - Get complete project tree structure
82
+ - `glob` - Pattern-based file search
83
+ - `list_directory` - List directory contents
84
+ - `run_command` - Execute shell commands
85
+
86
+ **Planned:**
87
+
88
+ - `run_npm_script` - Execute npm/pnpm/yarn scripts from package.json
89
+ - `run_composer_script` - Execute Composer scripts from composer.json
90
+ - `run_make_target` - Execute Makefile targets
91
+
92
+ **Safety Levels:**
93
+
94
+ - `readonly` - Only read operations (safe for production)
95
+ - `basic` - Read and write operations, no deletions or commands
96
+ - `all` - Full access including deletions and command execution
97
+
98
+ ### Agent Integrations
99
+
100
+ **Currently Available:**
101
+
102
+ - [Vercel AI SDK](https://ai-sdk.dev/) - Integration with AI SDK agents
103
+
104
+ **Planned:**
105
+
106
+ - [Mastra](https://mastra.ai/) - Integration with Mastra agents
107
+ - [AI SDK Tools](https://ai-sdk-tools.dev/) - Integration with AI SDK Tools agents
108
+
109
+ ## Usage Examples
110
+
111
+ ### Single Environment Agent
112
+
113
+ ```typescript
114
+ import { anthropic } from '@ai-sdk/anthropic';
115
+ import { createCodeAgent, createEnvironment } from 'ai-code-agents';
116
+
117
+ const environment = createEnvironment('unsafe-local', {
118
+ directoryPath: '/path/to/project',
119
+ });
120
+
121
+ const agent = createCodeAgent({
122
+ model: anthropic('claude-3-5-sonnet-20241022'),
123
+ environment,
124
+ environmentToolsDefinition: 'basic', // Read/write only, no deletions
125
+ maxSteps: 15,
126
+ logStep: (log, index) => {
127
+ console.log(`Step ${index + 1}:\n${log}\n`);
128
+ },
129
+ });
130
+
131
+ const result = await agent.execute({
132
+ prompt: 'Create a Python script that calculates fibonacci numbers',
133
+ });
134
+ ```
135
+
136
+ ### Multi-Environment Agent
137
+
138
+ ```typescript
139
+ import { openai } from '@ai-sdk/openai';
140
+ import { createCodeAgent, createEnvironment } from 'ai-code-agents';
141
+
142
+ // Create multiple environments (requires running containers)
143
+ const environments = {
144
+ frontend: createEnvironment('docker', {
145
+ containerId: 'frontend-container-id',
146
+ directoryPath: '/app',
147
+ }),
148
+ backend: createEnvironment('docker', {
149
+ containerId: 'backend-container-id',
150
+ directoryPath: '/app',
151
+ }),
152
+ };
153
+
154
+ // Configure tools per environment
155
+ const agent = createCodeAgent({
156
+ model: openai('gpt-4'),
157
+ environments,
158
+ environmentToolsDefinition: {
159
+ frontend: 'all',
160
+ backend: 'basic',
161
+ },
162
+ maxSteps: 20,
163
+ });
164
+
165
+ const result = await agent.execute({
166
+ prompt: 'Create a React frontend and Flask backend for a todo app',
167
+ });
168
+ ```
169
+
170
+ ### Custom Tool Configuration
171
+
172
+ ```typescript
173
+ import { createCodeAgent, createEnvironment } from 'ai-code-agents';
174
+ import { google } from '@ai-sdk/google';
175
+
176
+ const environment = createEnvironment('node-filesystem', {
177
+ directoryPath: '/path/to/project',
178
+ });
179
+
180
+ const agent = createCodeAgent({
181
+ model: google('gemini-2.0-flash-exp'),
182
+ environment,
183
+ environmentToolsDefinition: [
184
+ 'read_file',
185
+ 'read_many_files',
186
+ 'get_project_file_structure',
187
+ {
188
+ toolName: 'write_file',
189
+ toolConfig: {
190
+ needsApproval: true, // Require approval before writing
191
+ },
192
+ },
193
+ ],
194
+ maxSteps: 10,
195
+ });
196
+ ```
197
+
198
+ ### With Submit Tool
199
+
200
+ Enable agents to signal completion before reaching max steps:
201
+
202
+ ```typescript
203
+ const agent = createCodeAgent({
204
+ model: openai('gpt-4'),
205
+ environment,
206
+ environmentToolsDefinition: 'all',
207
+ maxSteps: 20,
208
+ allowSubmit: true, // Agent can call submit() to finish early
209
+ });
210
+ ```
211
+
212
+ ### Step Logging
213
+
214
+ Track agent execution with detailed step logs:
215
+
216
+ ```typescript
217
+ const agent = createCodeAgent({
218
+ model: anthropic('claude-3-5-sonnet-20241022'),
219
+ environment,
220
+ environmentToolsDefinition: 'all',
221
+ maxSteps: 15,
222
+ logStep: (stepLog) => {
223
+ // stepLog contains formatted information about the step
224
+ console.log(stepLog);
225
+ },
226
+ });
227
+ ```
228
+
229
+ ## Contributing
230
+
231
+ Contributions to the AI Code Agents SDK are welcome and highly appreciated.