( customToolId: string, context: GetToolAsyncContext )
| 132 | } |
| 133 | |
| 134 | async function fetchCustomToolFromDB( |
| 135 | customToolId: string, |
| 136 | context: GetToolAsyncContext |
| 137 | ): Promise<ToolConfig | undefined> { |
| 138 | const { workflowId, userId, workspaceId } = context |
| 139 | const identifier = customToolId.replace('custom_', '') |
| 140 | |
| 141 | if (!userId) { |
| 142 | throw new Error(`Cannot fetch custom tool without userId: ${identifier}`) |
| 143 | } |
| 144 | if (!workspaceId) { |
| 145 | throw new Error(`Cannot fetch custom tool without workspaceId: ${identifier}`) |
| 146 | } |
| 147 | |
| 148 | try { |
| 149 | const customTool = await getCustomToolByIdOrTitle({ |
| 150 | identifier, |
| 151 | userId, |
| 152 | workspaceId, |
| 153 | }) |
| 154 | |
| 155 | if (!customTool) { |
| 156 | logger.error(`Custom tool not found: ${identifier}`) |
| 157 | return undefined |
| 158 | } |
| 159 | |
| 160 | const customToolDefinition = toCustomToolDefinition(customTool) |
| 161 | if (!customToolDefinition) { |
| 162 | return undefined |
| 163 | } |
| 164 | |
| 165 | const toolConfig = createToolConfig(customToolDefinition, customToolId) |
| 166 | |
| 167 | return { |
| 168 | ...toolConfig, |
| 169 | params: createParamSchema(customTool), |
| 170 | request: { |
| 171 | ...toolConfig.request, |
| 172 | body: createCustomToolRequestBody(customTool, false, workflowId), |
| 173 | }, |
| 174 | } |
| 175 | } catch (error) { |
| 176 | logger.error(`Error fetching custom tool ${identifier} from DB:`, error) |
| 177 | return undefined |
| 178 | } |
| 179 | } |
no test coverage detected