Skip to content

feat(schematics): rewrite Vertex AI imports to AI Logic on ng update - #3725

Open
armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:a19-vertexai-ai-migration
Open

feat(schematics): rewrite Vertex AI imports to AI Logic on ng update#3725
armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:a19-vertexai-ai-migration

Conversation

@armando-navarro

Copy link
Copy Markdown
Collaborator

Adds an ng update migration that moves a workspace off the Vertex AI module onto Firebase AI Logic, and a guide for upgrading from AngularFire 20 to 21.

Background

AngularFire 21 renamed the Vertex AI module to Firebase AI Logic. The @angular/fire/vertexai entry point (and the older @angular/fire/vertexai-preview) were removed in favor of @angular/fire/ai, and the exported symbols were renamed. A project upgrading from 20 that used Vertex AI would fail to compile until it updated those imports by hand.

What this does

  • Extends the existing v21 migration (the one that aligns the firebase dependency) to also rewrite Vertex AI imports and their usages to AI Logic. It parses each source file with the TypeScript compiler and edits only real references, leaving strings, comments, and unrelated identifiers that happen to share a name untouched. It handles named imports and aliases, namespace imports in value and type position, bare local re-exports, and shorthand properties.
  • Adds docs/version-21-upgrade.md, a note in docs/ai.md, and a README link.
  • Adds typescript to the schematics esbuild externals, so the compiler is resolved from the workspace at ng update time rather than bundled into the package. This matches how Angular's own migrations ship and keeps the package from growing by several megabytes.

Symbol map

Before (@angular/fire/vertexai) After (@angular/fire/ai)
getVertexAI getAI
provideVertexAI provideAI
VertexAI AI
VertexAIInstances AIInstances
vertexAIInstance$ AIInstance$
VertexAIModule AIModule

getGenerativeModel and getImagenModel keep their names.

Known limitation

The rewrite matches by name, so a local variable that shadows an imported name with the same spelling can be mis-renamed. ng update always shows its changes as a diff to review, so this surfaces on inspection.

Verification

Unit specs cover each kind of code the migration can run into:

  • named imports, and aliased imports where only the imported name changes
  • namespace imports, in both value position (ns.getVertexAI()) and type position (ns.VertexAI)
  • shorthand properties ({ getVertexAI }) and bare local re-exports (export { VertexAI })
  • unchanged symbols, a file with nothing to rewrite, and an idempotent second run

I also ran the migration for real, not just in specs:

  • scaffolded a fresh Angular 20 app that imports from @angular/fire/vertexai
  • ran ng update and confirmed every import and usage rewrote to @angular/fire/ai
  • confirmed firebase aligned to ^12.4.0, and that a second run made no changes

Refs #3686

AngularFire 21 renamed the Vertex AI module to Firebase AI Logic: the
@angular/fire/vertexai and older @angular/fire/vertexai-preview entry points
were removed in favor of @angular/fire/ai, and the exported symbols were renamed
(getVertexAI to getAI, provideVertexAI to provideAI, VertexAI to AI, and so on).
A workspace on 20 that used Vertex AI would fail to compile after the upgrade.

Extend the existing v21 migration (which aligns the firebase dependency) to also
rewrite these imports and their usages. The rewrite parses each source file with
the TypeScript compiler and edits only genuine references, so it leaves strings,
comments, and unrelated identifiers that merely share a name untouched. It
handles named imports and their aliases, namespace imports in both value and
type position, bare local re-exports, and shorthand properties.

The one accepted limitation is name shadowing: because the rewrite matches by
name, a local variable that shadows an imported name with the same spelling can
be mis-renamed. ng update always presents its changes as a diff for review, so
this is caught on inspection.

Also add typescript to the schematics esbuild externals so the compiler is
resolved from the workspace at ng-update time rather than bundled into the
package, matching how Angular's own migrations ship.

Docs: add a 20-to-21 upgrade guide, note the rename in the AI Logic guide, and
link the upgrade guide from the README.

Refs angular#3686
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant