* Asynchronously creates local tools based on the provided `Pipe` object. * * @param {Pipe} pipe - The pipe object containing tools to be created. * * The function performs the following steps: * 1. Checks if there are any tools in the `pipe`. If none, it returns immediately. * 2. Retrieves al
(pipe: Pipe)
| 118 | * 8. If any error occurs during the process, it is caught and an appropriate message is displayed. |
| 119 | */ |
| 120 | async function createLocalTool(pipe: Pipe) { |
| 121 | if (!pipe.tools.length) return; |
| 122 | const allTools = await getAvailableTools(); |
| 123 | |
| 124 | try { |
| 125 | await pMap( |
| 126 | pipe.tools, |
| 127 | async tool => { |
| 128 | const hasTool = isToolPresent({ |
| 129 | name: tool.function.name, |
| 130 | allTools |
| 131 | }); |
| 132 | |
| 133 | if (hasTool) { |
| 134 | const toolInfo = await p.group( |
| 135 | { |
| 136 | overwrite: () => |
| 137 | p.confirm({ |
| 138 | message: `${color.dim(icons.tool)} Tool: ${color.cyan(tool.function.name)} already exists. Do you want to overwrite it?`, |
| 139 | initialValue: false |
| 140 | }) |
| 141 | }, |
| 142 | { |
| 143 | onCancel: () => { |
| 144 | p.cancel('Operation cancelled.'); |
| 145 | process.exit(0); |
| 146 | } |
| 147 | } |
| 148 | ); |
| 149 | |
| 150 | if (!toolInfo.overwrite) { |
| 151 | p.outro(`Skipped …`); |
| 152 | return; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | const name = tool.function.name; |
| 157 | const camelCaseName = camelCase(name); |
| 158 | const slugifiedName = slugify(name); |
| 159 | |
| 160 | const code = `import { ToolI } from '@baseai/core'; |
| 161 | |
| 162 | export async function ${name}() { |
| 163 | // Your tool logic here |
| 164 | } |
| 165 | |
| 166 | const ${camelCaseName}Tool = (): ToolI => ({ |
| 167 | run: ${name}, // Name of the function to run |
| 168 | type: 'function' as const, |
| 169 | function: { |
| 170 | name: \`${name}\`, |
| 171 | description: \`${tool.function.description}\`, |
| 172 | parameters: ${JSON.stringify(tool.function.parameters || {}, null, 6)} |
| 173 | } |
| 174 | }); |
| 175 | |
| 176 | export default ${camelCaseName}Tool;`; |
| 177 |
no test coverage detected