Skip to content

Commit 04ebb83

Browse files
committed
feat(docs): added instructions for adding a tool/block to contributing guidelines
1 parent 4470a54 commit 04ebb83

File tree

2 files changed

+388
-0
lines changed

2 files changed

+388
-0
lines changed

CONTRIBUTING.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Thank you for your interest in contributing to Sim Studio! Our goal is to provid
1515
- [Commit Message Guidelines](#commit-message-guidelines)
1616
- [Local Development Setup](#local-development-setup)
1717
- [License](#license)
18+
- [Adding New Blocks and Tools](#adding-new-blocks-and-tools)
1819

1920
---
2021

@@ -162,4 +163,152 @@ This project is licensed under the MIT License. By contributing, you agree that
162163

163164
---
164165

166+
## Adding New Blocks and Tools
167+
168+
Sim Studio is built in a modular fashion where blocks and tools extend the platform's functionality. To maintain consistency and quality, please follow the guidelines below when adding a new block or tool.
169+
170+
### Where to Add Your Code
171+
172+
- **Blocks:** Create your new block file under the `/blocks/blocks` directory.
173+
- **Tools:** Create your new tool file under the `/tools` directory.
174+
175+
In addition, you will need to update the registries:
176+
177+
- **Block Registry:** Update the blocks index (usually `/blocks/index.ts`) to include your new block.
178+
- **Tool Registry:** Update the tools registry (`/tools/index.ts`) to add your new tool.
179+
180+
### How to Create a New Block
181+
182+
1. **Create a New File:**
183+
Create a file for your block (e.g., `newBlock.ts`) in the `/blocks/blocks` directory.
184+
185+
2. **Create a New Icon:**
186+
Create a new icon for your block in the `/components/icons.tsx` file.
187+
188+
3. **Define the Block Configuration:**
189+
Your block should export a constant of type `BlockConfig`. For example:
190+
191+
```typescript:blocks/blocks/newBlock.ts
192+
import { SomeIcon } from '@/components/icons'
193+
import { BlockConfig } from '../types'
194+
195+
// Define response type if needed
196+
interface NewBlockResponse {
197+
output: {
198+
// Define expected output here
199+
result: string
200+
}
201+
}
202+
203+
export const NewBlock: BlockConfig<NewBlockResponse> = {
204+
type: 'new',
205+
name: 'New Block',
206+
description: 'Description of the new block',
207+
category: 'blocks',
208+
bgColor: '#123456',
209+
icon: SomeIcon,
210+
inputs: {
211+
// Define inputs here
212+
exampleInput: { type: 'string', required: true },
213+
},
214+
outputs: {
215+
response: {
216+
type: {
217+
result: 'string',
218+
},
219+
},
220+
},
221+
}
222+
```
223+
224+
4. **Register Your Block:**
225+
Import and add your block to the blocks registry (`blocks/index.ts`) in the appropriate index file so it appears in the workflow builder.
226+
227+
5. **Test Your Block:**
228+
Ensure that the block displays correctly in the UI and that its functionality works as expected.
229+
230+
### How to Create a New Tool
231+
232+
1. **Create a New File:**
233+
Create a file for your tool (e.g., `newTool.ts`) in the `/tools` directory.
234+
235+
2. **Define the Tool Configuration:**
236+
Your tool should export a constant of type `ToolConfig`. For example:
237+
238+
```typescript:tools/newTool.ts
239+
import { ToolConfig, ToolResponse } from './types'
240+
241+
interface NewToolParams {
242+
apiKey: string
243+
query: string
244+
}
245+
246+
interface NewToolResponse extends ToolResponse {
247+
output: {
248+
result: string
249+
}
250+
}
251+
252+
export const newTool: ToolConfig<NewToolParams, NewToolResponse> = {
253+
id: 'new_tool',
254+
name: 'New Tool',
255+
description: 'Description for the new tool',
256+
params: {
257+
apiKey: { type: 'string', required: true },
258+
query: { type: 'string', required: true },
259+
},
260+
request: {
261+
url: 'https://api.example.com/query',
262+
method: 'POST',
263+
headers: (params) => ({
264+
'Content-Type': 'application/json',
265+
Authorization: `Bearer ${params.apiKey}`,
266+
}),
267+
body: (params) => JSON.stringify({ query: params.query }),
268+
},
269+
transformResponse: async (response: Response) => {
270+
const data = await response.json()
271+
return {
272+
success: true,
273+
output: { result: data.result },
274+
}
275+
},
276+
transformError: (error) => {
277+
return error.message || 'An error occurred while processing the tool request'
278+
},
279+
}
280+
```
281+
282+
3. **Register Your Tool:**
283+
Update the tools registry in `/tools/index.ts` to include your new tool. For example, add it to the exported `tools` object:
284+
285+
```typescript:tools/index.ts
286+
import { newTool } from './newTool'
287+
// ... other imports
288+
289+
export const tools: Record<string, ToolConfig> = {
290+
// ... existing tools
291+
new_tool: newTool,
292+
}
293+
294+
export function getTool(toolId: string): ToolConfig | undefined {
295+
return tools[toolId]
296+
}
297+
```
298+
299+
4. **Test Your Tool:**
300+
Ensure that your tool functions correctly by making test requests and verifying the responses.
301+
302+
### Guidelines & Best Practices
303+
304+
- **Code Style:** Follow the project's ESLint and Prettier configurations. Use meaningful variable names and small, focused functions.
305+
- **Documentation:** Clearly document the purpose, inputs, outputs, and any special behavior for your block/tool.
306+
- **Error Handling:** Implement robust error handling and provide user-friendly error messages.
307+
- **Testing:** Add unit or integration tests to verify your changes when possible.
308+
- **Commit Changes:** Update all related components and registries, and describe your changes in your pull request.
309+
310+
Happy coding!
311+
312+
---
313+
165314
Thank you for taking the time to contribute to Sim Studio. We truly appreciate your efforts and look forward to collaborating with you!

0 commit comments

Comments
 (0)