From 7bfc84bca9aa412dd646b4db21180f3809222775 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 May 2025 09:11:32 +0000 Subject: [PATCH 1/2] chore(ci)(deps): bump codecov/codecov-action from 4 to 5 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4 to 5. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v4...v5) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f7bf5c7..1a86018b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,7 +81,7 @@ jobs: run: poetry run pytest --cov --cov-report=xml:reports/coverage.xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: files: reports/coverage.xml fail_ci_if_error: true \ No newline at end of file From e51a51f46bf0b46d76ce24a1dc95fe269dfc7799 Mon Sep 17 00:00:00 2001 From: Nicola Date: Thu, 15 May 2025 15:05:41 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix(API):=20Add=20api=20key?= =?UTF-8?q?=20to=20the=20hackagent=20class=20as=20it=20was=20missing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hackagent/agent.py | 60 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/hackagent/agent.py b/hackagent/agent.py index 69739b71..43c55704 100644 --- a/hackagent/agent.py +++ b/hackagent/agent.py @@ -52,17 +52,24 @@ def __init__( name: str = None, agent_type: AgentTypeEnum = AgentTypeEnum.UNKNOWN, base_url: Optional[str] = None, + api_key: Optional[str] = None, token: Optional[str] = None, predefined_prompts: Optional[Dict[str, Tuple[str, str]]] = None, raise_on_unexpected_status: bool = False, timeout: Optional[float] = None, env_file_path: Optional[str] = None, ): - display_hackagent_splash() # Display the splash screen on init + display_hackagent_splash() + + resolved_auth_token = self._resolve_api_token( + direct_api_key_param=api_key, + fallback_token_param=token, + env_file_path=env_file_path, + ) self.client = AuthenticatedClient( base_url=base_url, - token=self._resolve_api_token(token, env_file_path), + token=resolved_auth_token, prefix="Api-Key", raise_on_unexpected_status=raise_on_unexpected_status, timeout=timeout, @@ -85,30 +92,47 @@ def __init__( } def _resolve_api_token( - self, token: Optional[str], env_file_path: Optional[str] + self, + direct_api_key_param: Optional[str], + fallback_token_param: Optional[str], + env_file_path: Optional[str], ) -> str: - """Resolves the API token from direct input or environment variables.""" - api_token_resolved = token - if api_token_resolved is None: - logger.debug( - "API token not provided directly, attempting to load from environment." - ) - dotenv_to_load = env_file_path or find_dotenv(usecwd=True) + """Resolves the API token from direct api_key, fallback token parameter, or environment variables.""" + if direct_api_key_param is not None: + logger.debug("Using API token provided directly via 'api_key' parameter.") + return direct_api_key_param + + # If direct_api_key_param is None, try the fallback_token_param + api_token_resolved = fallback_token_param + if api_token_resolved is not None: + logger.debug("Using API token provided via 'token' parameter.") + # This token was provided, so we use it. + # The original logic would then check if it's None *again* before hitting env, + # but if it's not None here, it should be used. + return api_token_resolved + + # If both direct_api_key_param and fallback_token_param are None, attempt to load from environment. + logger.debug( + "API token not provided via 'api_key' or 'token' parameters, attempting to load from environment." + ) + dotenv_to_load = env_file_path or find_dotenv(usecwd=True) - if dotenv_to_load: - logger.debug(f"Loading .env file from: {dotenv_to_load}") - load_dotenv(dotenv_to_load) - else: - logger.debug("No .env file found to load.") + if dotenv_to_load: + logger.debug(f"Loading .env file from: {dotenv_to_load}") + load_dotenv(dotenv_to_load) + else: + logger.debug("No .env file found to load.") - api_token_resolved = os.getenv("HACKAGENT_API_TOKEN") + api_token_resolved = os.getenv("HACKAGENT_API_TOKEN") if not api_token_resolved: error_message = ( - "API token not provided and not found in HACKAGENT_API_TOKEN " - "environment variable (after attempting to load .env)." + "API token not provided via 'api_key' or 'token' parameters, " + "and not found in HACKAGENT_API_TOKEN environment variable " + "(after attempting to load .env)." ) raise ValueError(error_message) + logger.debug("Using API token from HACKAGENT_API_TOKEN environment variable.") return api_token_resolved async def hack(