Regenerate GenerateContent data models from Google Discovery Document
revision 20261019 to resolve drift detected by check-data-models CI,
and move server-side tool invocations into Part.PartData.
Data model updates:
- Candidate.FinishReason: Add continuation case for per-request limits.
- Candidate & GenerateContentRequest: Add continuationToken as String
to round-trip opaque tokens without strict base64 decoding.
- GenerateContentRequest: Add outputConfig for Cloud Storage media
persistence (GenerateContentRequestOutputConfig).
- Part: Add toolCall and toolResponse to oneOf definitions in
firebasevertexai-overrides.yaml and map to Part.PartData variants,
removing top-level stored properties to preserve the invariant that
every Part has data.
Tooling:
- Fix 'swift format' invocation on CI.
Replace `#if canImport(FoundationModels, _version: 2.1)` with
`#if compiler(>=6.4.2)` around the `Transcript.Entry.data` case in
`GeminiTranscriptTranslator` and its test. Xcode 27.2 beta 3 bumped the
Swift compiler to 6.4.2, so the condition no longer depends on the
underscored `_version` parameter of `canImport`.
Earlier Xcode 27.2 betas report Swift 6.4 and skip the case, which is
acceptable since beta 3 supersedes them.
Regenerate GenerateContent/ with the GeminiLanguageModel/scripts/typegen
generator from Discovery Document revision 20260929, fixing the drift
reported by the check-data-models CI job.
Generated model changes:
- Structs use optional `var` properties, an empty `init()` and
`Buildable` instead of memberwise initializers.
- Acronyms are capitalized in Swift names (e.g. `responseMIMEType`,
`URLContext`). JSON schema properties are typed as `JSONObject`, and
`Schema`, `DataType` and `VideoMetadata` are no longer generated.
- Enums combine both backends' cases and decode unknown values to
`.unrecognized`.
- Every generated file has a "DO NOT EDIT" header.
GeminiLanguageModel changes:
- Build requests with `Buildable` closures and adopt the renamed
properties. The encoded JSON is unchanged.
- Add `GeminiLanguageModel.Error.invalidResponse(InvalidResponse)`.
Responses that fail to decode or contain a function call with no
name now throw `invalidResponse` instead of `networkFailure`, and
`InvalidResponse.underlyingError` exposes the original error.
- Map the `MODEL_ARMOR` and `JAILBREAK` block reasons and the
`MODEL_ARMOR` finish reason to `guardrailViolation`.
- Exclude the GeminiLanguageModel test READMEs from the root SwiftPM
manifest so builds with `-warnings-as-errors` succeed.
The Xcode 27.2 SDK (FoundationModels 2.1) adds a `Transcript.Entry.data`
case, which triggers a "switch must be exhaustive" warning in
`GeminiTranscriptTranslator`. Handle the new case by throwing
`unsupportedTranscriptContent`, gated with `canImport(FoundationModels,
_version: 2.1)` so only the one case is conditionally compiled and
Xcode 27.0 and 27.1 continue to build.
Add a unit test for the new case. It requires macOS 27.2 or later at
runtime, so it is skipped on earlier OS versions.
Add a `unit-tests` job to the GeminiLanguageModel workflow that runs
`swift test --skip IntegrationTests` on Xcode 27.0 and 27.2, as well as
on Xcode 26.6 (macOS 26) and Xcode 26.2 (macOS 15). The FoundationModels
code is compiled out on Xcode 26, so those jobs verify that the package
still builds and its remaining tests pass with older toolchains.
Update the test READMEs to use `--skip IntegrationTests`, since
`--skip Integration` also skips the `IntegrationTestingBackendTests`
unit tests.
Gemini 3.x models return the thought signature of a text response on a
trailing empty text part. The executor records this as a signature-only
`.reasoning` transcript entry, which `GeminiTranscriptTranslator` then
round-tripped on the next turn as a stand-alone `Part` containing only
`thought` and `thoughtSignature` and no `data`.
The Gemini Developer API tolerates a part with no data, but the Gemini
Enterprise Agent Platform rejects it nondeterministically with
`400 INVALID_ARGUMENT` ("Request contains an invalid argument."),
making any multi-turn session that follows a completed text response
flaky on that backend (e.g. `sessionRespondSequentialToolCalls`).
Never emit a signature-only reasoning entry as a data-less part:
- A signature preceding a response is attached to the response's text
part.
- A signature following a response is attached to the last part of the
current model turn, mirroring how the server originally sent it.
- If there is no model part to attach to, fall back to a thought part
with empty text so the `data` oneof is always populated.
Replace the unit test that asserted the data-less shape with coverage
for all three cases.
Add the Python pipeline under `GeminiLanguageModel/scripts/typegen` that
generates the Swift data models in `GeminiAPIDataModels/GenerateContent`
from the Firebase AI Logic Google Discovery Document, so the models can
be regenerated in-tree as the upstream API evolves.
- `upgrade_spec.py` fetches the `v1beta` Discovery Document, converts it
to OpenAPI 3.1.0, extracts shared standalone enums per backend, infers
required properties, and merges the schema overrides from
`discovery_documents/firebasevertexai-overrides.yaml`.
- `generate_types.py` (the `swift_typegen` package) strips the Gemini
Developer API and Gemini Enterprise Agent Platform prefixes, resolves
the schemas reachable from the request/response roots, merges both
backends with DocC availability callouts, checks for value-type
cycles, renders Swift via Jinja2 templates, runs `swift-format`, and
prunes stale generated files while preserving hand-written ones.
- Add 117 unit tests covering every pipeline stage, and `pyink` settings
in `pyproject.toml`.
- Add a `check-data-models` CI job that runs the unit tests and warns
when the committed data models are behind the Discovery Document.
- Add `Shared/Buildable.swift`, which the regenerated types depend on.
The `GenerateContent` sources are not regenerated here; that follows in
a separate PR.
Revert commit dd2cfa8df1 (#16685) to undo
the renaming from Gemini Enterprise Agent Platform to Gemini Enterprise
API.
- Restore Backend.agentPlatform(location:) as the primary public API
and remove Backend.enterprise(location:).
- Revert APIConfig.Service.enterprise to .agentPlatform and restore
agentPlatformStagingBypassProxy.
- Revert documentation comments, DocC topics, and guides back to
Agent Platform Gemini API and Gemini Enterprise Agent Platform.
- Clean up leftover Vertex AI symbols to align with Agent Platform and
FirebaseAILogic (isFirebaseAILogicServiceDisabledError and
defaultAgentPlatformAPIConfig).
- Re-align tests and conflict resolutions from #16689, #16693, #16676,
and #16756.
Default to VALIDATED function calling mode in GeminiLanguageModel and
switch guided generation to responseJsonSchema.
Previously, tool-calling requests mapped the default or allowed mode to
AUTO, which does not strictly enforce parameter schemas. Because Swift
decodes tool arguments strictly, schema malformation results in failed
turns. Additionally, guided generation used responseFormat, which the
Gemini backend ignores when VALIDATED mode is active during tool-calling
sessions, dropping response schemas and causing structured decoding
failures in respond(to:generating:).
* Default unset and explicit .allowed toolCallingMode to VALIDATED mode
to strictly enforce schema adherence via constrained decoding.
* Throw LanguageModelError.unsupportedCapability on unrecognized future
tool calling modes instead of silently falling back to allowed.
* Omit functionCallingConfig entirely when requests declare no functions
to avoid contradictory constrained decoding states.
* Send responseJsonSchema with application/json MIME type for guided
generation, which constrained decoding honors alongside VALIDATED.
* Remove unused _responseJsonSchema property from GenerationConfig.
* End SSE response streams and cancel tasks upon receiving terminal
finish reasons or prompt feedback block reasons.
* Add integration test for combined tool calling and guided generation.
* Refresh cached App Check debug tokens proactively within TTL window.
Remove the GEMINI_LANGUAGE_MODEL environment variable check in
Package.swift to unconditionally include GeminiLanguageModel targets
and dependencies on supported Swift 6.4+ toolchains.
Add DocC documentation comments for the GeminiLanguageModel integration
with Apple's Foundation Models framework.
Provide usage guidance, public preview warnings, and links to Apple's
LanguageModel protocol, LanguageModelSession, and DynamicProfile. In
addition, document FirebaseAI.geminiLanguageModel(name:) and include
a code example showing how to instantiate and use the model.
Add function calling (tool calling) support to GeminiLanguageModel
conforming to Apple's FoundationModels framework.
* Add .toolCalling capability to GeminiLanguageModel.
* Translate FoundationModels ToolDefinition into Gemini Tool and
FunctionDeclaration using OpenAPI parametersJsonSchema.
* Map GenerationOptions.ToolCallingMode (.allowed, .required,
.disallowed) to Gemini FunctionCallingConfig.Mode.
* Stream function calls in GeminiLanguageModelExecutor, forwarding
JSON-encoded arguments or empty fallback "{}" into channel actions.
* Translate Transcript tool calls and tool outputs into Gemini Content
parts, preserving thought signatures from reasoning models and
flushing buffered reasoning thoughts cleanly.
* Unpack structured tool responses and wrap scalar text tool outputs
under the result field.
* Support parameterless tools with empty arguments across request
schema translation, model response handling, and transcript history.
* Add unit tests across GeminiLanguageModel, GeminiRequestTranslator,
and GeminiTranscriptTranslator.
* Add end-to-end integration tests covering single-turn, sequential,
parallel, disallowed, parameterless, and reasoning tool calling
across all supported backends.
Add guided generation (structured output) support to
GeminiLanguageModel conforming to Apple's LanguageModel.
* Extend GenerationSchema to translate schemas into Gemini-compatible
JSON Schema definitions, remapping x-order to propertyOrdering.
* Detect unsupported regex pattern guides during encoding and throw
LanguageModelError.unsupportedGenerationGuide.
* Introduce GeminiRequestTranslator to map generation requests and
schemas into GenerateContentRequest and GenerationConfig.
* Delegate request translation in GeminiLanguageModelExecutor to
GeminiRequestTranslator.
* Declare the .guidedGeneration capability on GeminiLanguageModel.
* Add comprehensive unit tests covering property ordering, nested
definitions, enums, recursive schemas, and error throwing.
* Add parameterized integration tests for single-turn and streaming
structured output generation, enum classification, and recursive
hierarchies.
Implemented `GeminiLanguageModel`, providing an adapter for Google's
Gemini models conforming to Apple's `FoundationModels.LanguageModel`
protocol. This PR includes text to text generation capabilities; other
modalities and Gemini features will be handled in follow-up PRs.
**Note:** The `GeminiLanguageModel` implementation is guarded by the
environment variable `GEMINI_LANGUAGE_MODEL`. By default none of the
`GeminiLanguageModel` implementation is included.
Key additions:
- `GeminiLanguageModel`: Implements `LanguageModel` protocol with
reasoning capabilities, configuring execution via `ModelResource`
and `EndpointConfiguration`.
- `GeminiLanguageModelExecutor`: Converts prompt instructions and
history into Gemini streaming requests, yielding responses as
`LanguageModelSession.ResponseStream`.
- `GeminiTranscriptTranslator`: Translates Apple `Transcript` entries
and segments into Gemini `Content` structures while preserving thought
signatures and validating supported transcript features.
- `GeminiLanguageModel.Error` and `GeminiErrorMapper`: Translates Gemini
API, HTTP, and network errors into standard `LanguageModelError` cases
(`rateLimited`, `timeout`, `guardrailViolation`, `refusal`, and
`unsupportedLanguageOrLocale`) or `GeminiLanguageModel.Error` cases
(`serviceUnavailable`, `networkFailure`, `modelNotFound`, `apiError`).
The `APIError` payload is designed for seamless forward compatibility
with both GenerateContent and the upcoming Interactions API.
- Testing infrastructure: Adds `ConditionTrait.requireFoundationModels`
to conditionally run Foundation Models tests only on supported
platforms (macOS 27+, iOS 27+, watchOS 27+, visionOS 27+), along with
shared test constants, mock fixtures, and comprehensive unit and
integration test suites.