feat: auto-detect profileArn from Kiro Agent IDE local storage - #239
feat: auto-detect profileArn from Kiro Agent IDE local storage#239Yashwant00CR7 wants to merge 5 commits into
Conversation
|
Thanks for the PR! 🎉 Before merge, we need a one-time CLA confirmation. Full CLA text: Please reply once with: You need to write once, all further messages from me can be ignored. |
|
Thanks for the PR! 🎉 Before merge, we need a one-time CLA confirmation. Full CLA text: Please reply once with: You need to write once, all further messages from me can be ignored. |
|
Thanks for the PR! 🎉 Before merge, we need a one-time CLA confirmation. Full CLA text: Please reply once with: You need to write once, all further messages from me can be ignored. |
|
I have read the CLA and I accept its terms |
|
Thanks for the PR! 🎉 Before merge, we need a one-time CLA confirmation. Full CLA text: Please reply once with: You need to write once, all further messages from me can be ignored. |
|
Thanks for the PR! 🎉 Before merge, we need a one-time CLA confirmation. Full CLA text: Please reply once with: You need to write once, all further messages from me can be ignored. |
Feat: Auto-detect
profileArnfrom Kiro Agent IDE local storageSummary
This pull request introduces an automatic resolution mechanism for the
profileArnparameter by reading the local settings/profile storage file (profile.json) generated by the Kiro Agent IDE (OpenCode / Kiro Desktop). This resolves theprofileArn is required for this requestcompletions error (HTTP 400) out-of-the-box for Kiro Agent IDE users, without requiring manual environment variable configurations or SQLite database syncing.Context & Root Cause
The Kiro completion endpoints (
runtime.kiro.dev) now strictly require the presence of a validprofileArnin the request payload for all authentication types (including personal Builder ID / AWS SSO accounts).Previously, PR #186 bypassed this validation for Builder ID accounts by omitting the
profileArnfield from the request payload. However, due to recent upstream API updates, omitting it now results in a validation exception:{"__type":"com.amazon.kiro.runtimeservice#ValidationException","message":"profileArn is required for this request."}Because the standard AWS SSO token cache file (
kiro-auth-token.json) does not store theprofileArn, the gateway could not retrieve it automatically.Fortunately, the Kiro Agent IDE saves the active session's profile configuration—including the correct
profileArn—insideprofile.jsonin its global storage path.Proposed Changes
1. Utilities (
kiro/utils.py)detect_kiro_agent_profile_arn()to locate the platform-specific Kiro global storage directory:%APPDATA%\Kiro\User\globalStorage\kiro.kiroagent~/Library/Application Support/Kiro/User/globalStorage/kiro.kiroagent~/.config/Kiro/User/globalStorage/kiro.kiroagentprofile.json(both directly and recursively insidekiro.kiroagentto accommodate subfolders) to extract the profile ARN.2. Authentication (
kiro/auth.py)detect_kiro_agent_profile_arn()as a fallback inside theKiroAuthManager.profile_arnproperty.PROFILE_ARNis not set in.envand is not present in the active SQLite database credentials, the manager dynamically resolves and caches theprofileArnfrom the IDE's storage.3. Tests (
tests/unit/test_auth_manager.py)test_profile_arn_fallback_auto_detectionto verify the fallback logic correctly reads the file.test_profile_arn_returns_none_if_no_detectionto ensure the property defaults toNonegracefully if the file is missing or invalid.Verification & Testing
pytest --ignore=tests/unit/test_routes_anthropic_shim.py):