|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -from typing import Any, Awaitable, Callable, Dict, Optional |
| 15 | +from typing import Any, Awaitable, Callable, Dict, Optional, cast |
16 | 16 |
|
17 | 17 | import toolbox_core |
18 | 18 | from fastapi.openapi.models import ( |
@@ -127,38 +127,28 @@ async def run_async( |
127 | 127 | oauth2=OAuth2Auth( |
128 | 128 | client_id=self._auth_config.client_id, |
129 | 129 | client_secret=self._auth_config.client_secret, |
130 | | - scopes=scopes, |
131 | 130 | ), |
132 | 131 | ), |
133 | 132 | ) |
134 | 133 |
|
135 | 134 | # Check if we already have credentials from a previous exchange |
136 | 135 | try: |
137 | 136 | # get_auth_response returns AuthCredential if found |
138 | | - creds = tool_context.get_auth_response(auth_config_adk) |
| 137 | + ctx_any = cast(Any, tool_context) |
| 138 | + creds = ctx_any.get_auth_response(auth_config_adk) |
139 | 139 | if creds and creds.oauth2 and creds.oauth2.access_token: |
140 | 140 | reset_token = USER_TOKEN_CONTEXT_VAR.set(creds.oauth2.access_token) |
141 | 141 | else: |
142 | | - # Request credentials. This will signal the runner to pause. |
143 | | - # We return None (or raise) to stop current execution. |
144 | | - tool_context.request_credential(auth_config_adk) |
145 | | - # Returning None here. The ADK runner will see the requested_auth_configs |
146 | | - # in the tool_context/event and trigger the client event. |
| 142 | + # Request credentials and pause execution |
| 143 | + ctx_any.request_credential(auth_config_adk) |
147 | 144 | return None |
148 | 145 | except Exception as e: |
149 | | - # If get_auth_response fails drastically or request_credential fails |
150 | 146 | ctx.error = e |
151 | | - # We might want to request credential if retrieval failed? |
152 | | - # For now let's assume if it fails we can't proceed. |
153 | | - # Actually, strictly we should probably request credential if get_auth_response returns nothing |
154 | | - # but get_auth_response typically handles the lookup. |
155 | | - # If exception is unrelated, raise. |
156 | | - if "credential" in str(e).lower() or isinstance( |
157 | | - e, ValueError |
158 | | - ): # Loose check, but safest is to re-raise |
| 147 | + if "credential" in str(e).lower() or isinstance(e, ValueError): |
159 | 148 | raise e |
160 | | - # Fallback to request logic if it was a lookup error? |
161 | | - tool_context.request_credential(auth_config_adk) |
| 149 | + # Fallback to request logic |
| 150 | + ctx_any = cast(Any, tool_context) |
| 151 | + ctx_any.request_credential(auth_config_adk) |
162 | 152 | return None |
163 | 153 |
|
164 | 154 | try: |
|
0 commit comments