diff --git a/temporalio/contrib/google_genai/_compat.py b/temporalio/contrib/google_genai/_compat.py new file mode 100644 index 000000000..6613e2b9c --- /dev/null +++ b/temporalio/contrib/google_genai/_compat.py @@ -0,0 +1,24 @@ +"""Version-compatibility shims for the ``google-genai`` SDK. + +Single home for workarounds that keep the plugin importable and +type-checkable across the supported ``google-genai`` range; remove entries +as upstream fixes land. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + # google-genai 2.12.0 exports two ``Interaction`` names: the interaction + # resource class and a ``TypeAliasType`` over the trigger-request + # variants. At runtime we get the resource class but type checkers + # resolve to the alias which causes failures (the alias has no ``id``, + # etc.). Force the type checker to see the class' defining module (in + # the same location in 2.10 and 2.12). + from google.genai._gaos.types.interactions.interaction import Interaction +else: + # At runtime, Interaction resolves properly for 2.10 and 2.12 + from google.genai.interactions import Interaction + +__all__ = ["Interaction"] diff --git a/temporalio/contrib/google_genai/_gemini_activity.py b/temporalio/contrib/google_genai/_gemini_activity.py index 2e92c56a1..496bbf1ab 100644 --- a/temporalio/contrib/google_genai/_gemini_activity.py +++ b/temporalio/contrib/google_genai/_gemini_activity.py @@ -17,11 +17,11 @@ from google.genai import Client as GeminiClient from google.genai import errors as genai_errors from google.genai import types -from google.genai.interactions import Interaction from google.genai.types import HttpOptions from google.genai.types import HttpResponse as SdkHttpResponse from temporalio import activity +from temporalio.contrib.google_genai._compat import Interaction from temporalio.contrib.google_genai._models import ( _GeminiApiRequest, _GeminiApiResponse, diff --git a/temporalio/contrib/google_genai/_temporal_interactions.py b/temporalio/contrib/google_genai/_temporal_interactions.py index b5eb2edc0..54d8353cd 100644 --- a/temporalio/contrib/google_genai/_temporal_interactions.py +++ b/temporalio/contrib/google_genai/_temporal_interactions.py @@ -20,9 +20,10 @@ from typing import Any, cast import pydantic -from google.genai.interactions import Interaction, InteractionSSEEvent +from google.genai.interactions import InteractionSSEEvent from temporalio import workflow as temporal_workflow +from temporalio.contrib.google_genai._compat import Interaction from temporalio.contrib.google_genai._models import ( _GeminiInteractionIdRequest, _GeminiInteractionRequest, diff --git a/tests/contrib/google_genai/test_gemini.py b/tests/contrib/google_genai/test_gemini.py index 543ad648c..0881f63b3 100644 --- a/tests/contrib/google_genai/test_gemini.py +++ b/tests/contrib/google_genai/test_gemini.py @@ -32,7 +32,6 @@ from google.genai import types from google.genai.interactions import ( Agent, # pyright: ignore[reportPrivateImportUsage] - Interaction, InteractionSSEEvent, ) from google.genai.types import HttpResponse as SdkHttpResponse @@ -45,6 +44,7 @@ GoogleGenAIPlugin, activity_as_tool, ) +from temporalio.contrib.google_genai._compat import Interaction from temporalio.contrib.google_genai._models import ( _GeminiApiRequest, _GeminiApiResponse,