Commit Graph
131 Commits
Author SHA1 Message Date
Andrew Heard 384fed9a83 feat(ai): support speech metadata on text parts (#16749)
Add SpeechMetadata (public preview) so requests to Gemini
text-to-speech models can attach turn-level instructions to a
TextPart:

- speaker assigns the turn to a voice configured in
  MultiSpeakerVoiceConfig. Multi-speaker requests require it on
  every part.
- style describes sustained delivery, such as emotion, pacing, or
  volume, so it isn't read aloud as part of the transcript.
  Momentary sounds and pauses stay inline as vocal tags, such as
  <laugh> or <short pause>.

Set metadata with the new TextPart.init(_:speechMetadata:). The
existing init(_:) is kept so references like
[String].map(TextPart.init) still compile. TextPart.speechMetadata
and the SpeechMetadata properties are internal while the API is in
preview.

InternalPart encodes and decodes speechMetadata on the wire. History
doesn't merge streamed text parts that carry speech metadata, so
speaker turns stay separate.

Document the multi-speaker requirements on SpeechConfig,
MultiSpeakerVoiceConfig, and SpeakerVoiceConfig.

Replace the gemini-3.1-flash-tts-preview integration tests with a
TextToSpeechTests suite covering gemini-3.8-flash-tts and
gemini-3.8-flash-lite-tts in unary and streaming, single- and
multi-speaker requests.
2026-10-14 18:56:25 -04:00
Paul Beusterien a4c30acb2d feat(ai): add voice activity support to the Live API (#16889) 2026-10-13 11:51:20 -07:00
Andrew Heard ead1af3543 refactor(ai): revert renaming to Gemini Enterprise API (#16846)
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.
2026-10-05 23:54:12 +00:00
Paul Beusterien dd61534812 fix(ai): harden handling of unexpected server response parts (#16756) 2026-10-02 07:26:35 -07:00
Andrew Heard 5dd4053791 docs(ai): mark prompt templates as public preview (#16741)
Revert the General Availability (GA) designation for Server Prompt
Templates in docstrings and CHANGELOG.md. Multi-turn conversations
(`TemplateChat`) and function calling (`TemplateTool`) remain public,
annotated with Public Preview warnings.

Key changes:
- Add Public Preview annotations and warnings across the Server Prompt
  Templates public API surface (TemplateGenerativeModel, TemplateChat,
  TemplateTool, and TemplateToolConfig).
- Update CHANGELOG.md to reflect Public Preview status.
2026-09-30 12:15:54 -04:00
Andrew Heard 3f9bc4e013 refactor(ai)!: rename Tool to GenerativeModel.Tool (#16700)
Nest `Tool` inside `GenerativeModel` as `GenerativeModel.Tool` to avoid
naming conflicts with Apple's `FoundationModels.Tool` protocol when both
modules are imported in the same file.

Moving `Tool` into `GenerativeModel` allows developers to adopt Apple's
Foundation Models framework without ambiguous symbol errors for
unqualified `Tool`. Call sites passing tools via leading-dot syntax
(e.g., `tools: [.googleSearch()]`) continue to work without changes.

- Nest `Tool` inside `GenerativeModel` and remove top-level `Tool`.
- Move static conveniences (`.googleSearch()`, `.googleMaps()`,
  `.functionDeclarations()`, `.urlContext()`, `.codeExecution()`) to an
  extension on `GenerativeModel.Tool`.
- Update `FirebaseAI.generativeModel`, `FirebaseAI.liveModel`,
  `LiveGenerativeModel`, and internal request types to use
  `GenerativeModel.Tool`.
- Remove leftover internal `isFoundationModeCompatible` property.
- Update DocC links and unit/integration tests across the module.

BREAKING CHANGE: The top-level `Tool` type in `FirebaseAILogic` has been
removed and nested inside `GenerativeModel` as `GenerativeModel.Tool`.
Call sites explicitly typed as `Tool` must update to
`GenerativeModel.Tool`. Calls using leading-dot syntax continue to
compile unmodified.
2026-09-24 12:17:30 -04:00
Andrew Heard 555203f373 refactor(ai)!: remove legacy Foundation Models integration (#16693)
Clean up the interim integration with Apple's Foundation Models
framework in Firebase AI Logic for Firebase 13.

Apple now natively supports third-party providers in the Foundation
Models framework via LanguageModel, which is implemented directly by
GeminiLanguageModel. The custom GenerativeModelSession,
SystemLanguageModel, HybridModel, custom GenerationSchema, and related
bridging types and protocols are now obsolete.

- Remove GenerativeModelSession, SystemLanguageModel, HybridModel,
  GeminiModel, and related session protocols and provider types.
- Remove custom GenerationSchema, GeneratedContent, and related
  structured output protocols.
- Remove internal responseJSONSchema support from GenerationConfig and
  associated test permutations in FirebaseAILogic and TestApp.
- Remove IS_FOUNDATION_MODELS_SUPPORTED_PLATFORM build settings from
  Package.swift and FirebaseAILogic.podspec.

BREAKING CHANGE: GenerativeModelSession, SystemLanguageModel,
HybridModel, GeminiModel, and associated interim integration types and
protocols have been removed. Use GeminiLanguageModel with Apple's
Foundation Models framework instead.
2026-09-24 10:01:14 -04:00
Andrew Heard 67debaf689 feat(ai): GA prompt templates API with chat/func calling (#16676)
Promote Server Prompt Templates to General Availability (GA) in the
FirebaseAILogic Swift SDK, enabling developers to decouple prompt
engineering, schemas, and model configs from client release cycles.

Key changes:
- Expose TemplateGenerativeModel publicly via FirebaseAI's
  templateGenerativeModel(tools:toolConfig:requestOptions:).
- Introduce TemplateChat and TemplateGenerativeModel.startChat for
  multi-turn conversations with templates containing {{history}},
  supporting empty turns to run template prompts.
- Add TemplateTool with functionDeclarations and googleMaps, as well
  as TemplateToolConfig for Grounding with Google Maps.
- Add Schema.toJSONSchema() to convert Schema instances to JSON Schema
  Draft 7/2020-12 for function parameter declarations.
- Add TemplateInput conversion supporting primitives, arrays, and
  dictionaries, with NSNumber boolean disambiguation and rich errors.
- Sanitize and percent-encode template IDs in request URLs to prevent
  path and method injection.
- Add comprehensive unit test coverage and end-to-end integration
  tests covering generation, streaming, chat, and function calling.
2026-09-23 17:47:48 -04:00
Paul Beusterien 2c81ae02c2 refactor(ai)!: remove deprecated vertexAI APIs (#16689) 2026-09-23 11:51:05 -07:00
Paul Beusterien dd2cfa8df1 docs(ai): deprecate agentPlatform in favor of enterprise (#16685) 2026-09-23 08:57:25 -07:00
Andrew Heard f55af5b56f docs(ai): fix broken links in codebase and changelog (#16683) 2026-09-22 20:44:54 -04:00
Andrew Heard 97932016ef feat(ai): use VALIDATED function calling mode in GLM (#16649)
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.
2026-09-17 17:51:18 -04:00
Paul Beusterienandgemini-code-assist[bot] 7cbe0686da API doc link improvements (#16660)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-09-17 11:09:29 -04:00
Paul Beusterien 8f5e12c76c Deprecate Gemini 3.x tuning parameters (#16630) 2026-09-11 12:36:11 -07:00
Andrew Heard 27eaab3918 feat(ai): document and expose GeminiLanguageModel (#16631)
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.
2026-09-09 15:57:01 -04:00
Andrew Heard a512638ecd refactor(ai): consolidate HTTP request headers (#16612) 2026-09-04 21:45:01 -04:00
Andrew Heard 3796a55fdf feat(ai): add GeminiLanguageModel (#16601)
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.
2026-09-04 18:05:45 -04:00
Andrew Heard 56c1eef4ea chore(ci): add xcode 27 to spm test matrix (#16604) 2026-09-04 11:38:33 -04:00
Paul Beusterien 58bd319bae Fix AppCheck concurrency infinite recursion bug in Auth (#16552) 2026-09-01 09:02:03 -07:00
Daymon 6e43483efa fix(ml): missing import causing build error (#16563) 2026-08-27 14:07:21 -05:00
Paul Beusterien 3b2287ec40 Remove deprecated Imagen APIs (#16483) 2026-08-06 09:51:46 -07:00
Andrew Heard 2bee8bc6a8 fix(ai): correct FunctionResponsePart role to "user" (#16478) 2026-08-05 12:19:57 -04:00
06d2b95fe5 feat(ai): add support for RealtimeInputConfig (#16441)
Co-authored-by: Andrew Heard <andrewheard@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-07-29 10:31:43 -05:00
Paul BeusterienandAndrew Heard f98844f320 docs(FirebaseAI): rename Vertex AI to Agent Platform Gemini API in comments (#16457)
Co-authored-by: Andrew Heard <andrewheard@google.com>
2026-07-28 07:57:06 -07:00
Mila ce61e5ac81 [AI] Mark speech output feature "public preview" (#16432) 2026-07-22 13:16:20 -04:00
Nick Cooke 1d28bb5de0 fix(firebaseai): prevent stream leak on cancellation (#16393) 2026-07-20 14:23:07 -05:00
Paul BeusterienandAndrew Heard 6b581ae875 [AI] Rename vertexAI to agentPlatform (#16372)
Co-authored-by: Andrew Heard <andrewheard@google.com>
2026-07-13 14:32:58 -07:00
Nick Cooke 1f73a56da7 fix(ailogic): xcode 27 renaming deprecation (#16297) 2026-06-30 15:47:19 -04:00
Paul Beusterien fa96c86bcc [Firebase AI Logic] Fix GenerateContentResponse decode failure when citation endIndex is missing (#16329) 2026-06-29 10:59:20 -07:00
Nick Cooke 71b30c0c56 fix(ailogic): stream errors should not be ignored (#16298) 2026-06-23 12:06:37 -04:00
5681734e91 [AI] Support SpeechConfig in Text-To-Speech (#16226)
Co-authored-by: Ryan Wilson <wilsonryan@google.com>
Co-authored-by: Daymon <daymxn@google.com>
Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
Co-authored-by: Daymon <17409137+daymxn@users.noreply.github.com>
Co-authored-by: Nick Cooke <nickcooke@google.com>
2026-06-10 18:05:58 -05:00
Andrew Heard 57e4e51357 fix(ai): Handle Xcode 27 LanguageModelSession.Error collision (#16257) 2026-06-10 10:49:03 -04:00
Andrew Heard 2e6f24faec [AI] Revert rename of GeminiModel to GeminiLanguageModel (#16237) 2026-06-07 15:21:43 -04:00
Andrew Heard bf840dae85 [AI] Add public init for GeminiLanguageModel (#16234) 2026-06-05 06:29:52 -04:00
Andrew Heard 3257ea8e0f [AI] Add Hashable conformance to model config types (#16233) 2026-06-04 20:56:54 -04:00
Andrew Heard 67d2c5d0f2 [AI] Rename GeminiModel to GeminiLanguageModel (#16227) 2026-06-04 09:56:35 -04:00
Andrew Heard 3dbf64a63f [AI] Handle GenerateContentResponse with only usageMetadata (#16171) 2026-05-19 11:06:20 -04:00
Daymon 62c9ced719 fix(docs): fix maps grounding phrasing per Rachel's comment (#16180) 2026-05-15 17:16:18 -07:00
Seyed Mojtaba Hosseini Zeidabadi 33ca06ed47 chore: fix a bunch of typos in the swift files (#16179) 2026-05-15 06:38:45 -07:00
Andrew Heard 7de0b35fa7 [AI] Remove Gemma from header comment on GeminiModel (#16177) 2026-05-14 11:27:18 -07:00
Andrew Heard d47bc4e3d2 [AI] Use respond(to:options:) for String generation (#16165) 2026-05-12 22:31:44 -04:00
Andrew Heard 09298bd555 [AI] Add hybrid and Foundation Models debug logging (#16134) 2026-04-29 00:16:01 -04:00
Andrew Heard e79590ee1e [AI] Add GenerateContentResponse.modelVersion to public API (#16132) 2026-04-28 23:42:08 -04:00
Andrew Heard ad11c22db8 [AI] Remove GenerativeModelSession public initializer (#16130) 2026-04-28 21:40:40 -04:00
c4a15f1f2c feat(ai): add live session resumption (#15904)
Co-authored-by: Daymon <daymxn@google.com>
Co-authored-by: Daymon <17409137+daymxn@users.noreply.github.com>
2026-04-28 19:22:48 +00:00
d2ef47c3d5 [AI] Finish Reasons (#15931)
Co-authored-by: Andrew Heard <andrewheard@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Daymon <17409137+daymxn@users.noreply.github.com>
Co-authored-by: Daymon <daymxn@google.com>
2026-04-28 19:09:08 +00:00
7c3c8b531a [AI] Add ImageConfig support for generateContent (#15923)
Co-authored-by: Andrew Heard <andrewheard@google.com>
Co-authored-by: Daymon <daymxn@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-04-28 14:04:34 -05:00
Andrew Heard d377408ea0 [AI] Refactor GeminiModelSession to use text(isThought:) (#16122) 2026-04-27 09:55:01 -04:00
Andrew Heard 223f04dc41 [AI] Lazily initialize sessions in HybridModelSession (#16119) 2026-04-25 11:38:21 -04:00
Andrew Heardandgemini-code-assist[bot] 59d89567f6 [AI] Add hybrid tag in x-goog-api-client header (#16118)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-04-24 17:19:18 -04:00