Skip to content

feat(ailogic): add ailogic:config CLI commands#10841

Closed
marb2000 wants to merge 16 commits into
firebase:mainfrom
marb2000:feat/ailogic-configs
Closed

feat(ailogic): add ailogic:config CLI commands#10841
marb2000 wants to merge 16 commits into
firebase:mainfrom
marb2000:feat/ailogic-configs

Conversation

@marb2000

Copy link
Copy Markdown
Member

Description

Adds the firebase ailogic:config:* commands to read and modify Firebase AI Logic configuration, gated behind the ailogic experiment (same as ailogic:providers).

  • ailogic:config:get [path] reads the config. With no path it prints the whole resource; with a path it prints one value. Providers appear as read-only status derived from API enablement.
  • ailogic:config:set <path> <value> writes one setting. Developer-facing paths map to the underlying resource fields:
    • security.auth-only -> trafficFilter.firebaseAuthRequired
    • security.template-only -> trafficFilter.templateOnly
    • monitoring.state -> telemetryConfig.mode (ALL/NONE)
    • monitoring.sample-rate-percentage -> telemetryConfig.samplingRate (an integer percent 1-100 exposed as the API's (0,1] fraction)

Tightening security.auth-only or security.template-only from false to true prompts for confirmation because existing clients start getting rejected; confirm() enforces --force in non-interactive mode. Input (path and value) is validated up front, before the API-enablement flow, so bad input fails fast.

Depends on #10778 (ailogic:providers). This branch is rebased on top of that one, so until #10778 merges the diff here also shows the provider commits; once #10778 lands in main the diff narrows to the config-only changes automatically. Please review the ailogic-config-* and config-related gcp/ailogic.ts changes here; the provider files are the already-approved #10778 content.

Scenarios Tested

  • Unit tests: ailogic-config-get.spec.ts, ailogic-config-set.spec.ts, plus getConfig/updateConfig in gcp/ailogic.spec.ts. Covers unknown path, non-boolean and out-of-range values, false->true tightening confirmation, non-interactive-without-force, value/field mapping, nested-path reads, and fail-fast-before-enablement.
  • npm run build, npm run lint, and tsc --noEmit are clean.
  • Commands are hidden by default and appear under FIREBASE_CLI_EXPERIMENTS=ailogic.

Sample Commands

firebase experiments:enable ailogic
firebase ailogic:config:get
firebase ailogic:config:get security.auth-only
firebase ailogic:config:set security.auth-only true
firebase ailogic:config:set monitoring.sample-rate-percentage 50

marb2000 and others added 10 commits July 8, 2026 09:42
Add `firebase ailogic:providers:{enable,disable,list}` to manage the
Gemini API providers (Gemini Developer API and Agent Platform Gemini API)
for Firebase AI Logic from the CLI.

- providers:enable enables the Firebase AI Logic API and the selected
  provider's underlying API; agent-platform-gemini-api requires the Blaze
  (pay-as-you-go) plan.
- providers:disable prompts for confirmation (--force to skip) and turns
  off the proxy when no providers remain enabled.
- providers:list reports which providers are enabled.
- Adds a shared interactive enablement flow (used when the API is not yet
  enabled) that checks enable permission up front before prompting.
- Adds `firebase help <namespace>` listing of subcommands under a prefix
  so ailogic commands are discoverable.

Requires the firebasevertexai and serviceusage IAM permissions; commands
support --json and --non-interactive.
- Rename provider id agent-platform-gemini-api -> gemini-agent-platform-api
  for symmetry with gemini-developer-api (paulb777).
- Centralize provider-type validation in ailogic.parseProviderType/isProviderType
  and reuse it in the enable/disable commands instead of copying the union
  (christhompsongoogle).
- Add AILOGIC_LOGGING_PREFIX constant; replace the repeated 'ailogic' literals.
- Move enablement-cache invalidation into serviceusage.disableServiceAndPoll and
  drop the per-callsite uncache calls; rename its 'prefix' param to loggingPrefix.
- Drop the redundant non-interactive guard in disable; confirm() already enforces
  --force in non-interactive mode.
- Gate the ailogic commands behind a new 'ailogic' experiment until API-council
  approval.
- Document the help.ts namespace-listing blocks.
- Update/extend unit tests accordingly.
Add `firebase ailogic:config:get [path]` and `ailogic:config:set <path> <value>`
to read and write Firebase AI Logic service configuration from the CLI.

- config:get prints the full config (providers, security, monitoring) or a
  single value by path; it is read-only and reports "not enabled" gracefully
  rather than forcing API enablement.
- config:set updates one setting. Tightening security.auth-only or
  security.template-only from false to true prompts for confirmation
  (--force to skip); monitoring.sample-rate-percentage is validated as an
  integer 1-100.
- Developer-facing paths map onto the underlying config resource
  (trafficFilter.*, telemetryConfig.*), with sample rate stored as a fraction.

Supports --json and --non-interactive.
- Bring config commands under the ailogic experiment gate (via cherry-pick of the
  providers review fixes) and inherit the provider rename + centralized validation.
- config:get/config:set: single source of valid paths (fixes get's validate-vs-error
  mismatch); rename provider id to gemini-agent-platform-api.
- config:set: drop the redundant non-interactive guard (confirm() enforces --force),
  use utils.logSuccess, extract a bool parser, validate the path before the
  API-enablement flow.
- gcp: GLOBAL_LOCATION constant for the config resource; AILOGIC_LOGGING_PREFIX in
  isAILogicApiEnabled.
- Add ailogic-config-get.spec.ts and ailogic-config-set.spec.ts.
- config:set validates the value before the API-enablement flow (fail-fast) and
  returns a {path, value} result so --json produces output.
- config:get path traversal uses an isRecord type guard instead of an `as` cast;
  provider keys/paths derive from ailogic.PROVIDER_TYPES (no duplicated literals).
- Add tests: monitoring.state=false -> NONE, template-only tightening, nested-path
  get, and fail-fast-before-enablement.
@wiz-9635d3485b

wiz-9635d3485b Bot commented Jul 23, 2026

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 2 Low
Software Management Finding Software Management Findings -
Total 2 Low

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the firebase ailogic CLI command surface to manage Gemini API providers and configure AI Logic settings, including commands to enable, disable, and list providers, as well as get and set configuration values. It also updates the help command to support namespace subcommands and adds cache invalidation for disabled APIs. Feedback on the changes highlights a critical startup crash in src/commands/index.ts when the ailogic experiment is disabled because configuration commands are registered on an uninitialized client.ailogic object. Additionally, suggestions were made to parallelize API enablement checks in listProviders for better performance and to allow case-insensitive boolean parsing in parseBool for improved usability.

Comment thread src/commands/index.ts Outdated
Comment thread src/gcp/ailogic.ts
Comment thread src/commands/ailogic-config-set.ts
- Critical: register ailogic:config commands INSIDE the experiment gate; a
  rebase had left them outside, which crashed CLI startup for users without the
  ailogic experiment (client.ailogic was undefined).
- parseBool accepts case-insensitive true/false.
- listProviders runs its two independent enablement checks in parallel.
@codecov-commenter

codecov-commenter commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.55556% with 73 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@16fb909). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/gcp/ailogic.ts 61.53% 31 Missing and 4 partials ⚠️
src/commands/help.ts 59.25% 6 Missing and 5 partials ⚠️
src/commands/index.ts 0.00% 8 Missing and 1 partial ⚠️
src/commands/ailogic-config-set.ts 82.92% 2 Missing and 5 partials ⚠️
src/commands/ailogic-config-get.ts 85.00% 2 Missing and 4 partials ⚠️
src/ensureApiEnabled.ts 20.00% 4 Missing ⚠️
src/gcp/serviceusage.ts 91.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10841   +/-   ##
=======================================
  Coverage        ?   58.32%           
=======================================
  Files           ?      617           
  Lines           ?    40494           
  Branches        ?     8216           
=======================================
  Hits            ?    23618           
  Misses          ?    14911           
  Partials        ?     1965           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

marb2000 added 2 commits July 22, 2026 22:35
- Remove the unused security-rules layer (generateRulesContent, getSecurityRules,
  updateSecurityRules, the rules import, and their tests); nothing references it.
- Single source for config paths: WRITABLE_CONFIG_PATHS exported from gcp/ailogic,
  READABLE derived from it; shared assertKnownConfigPath error helper; shared
  samplingRateToPercent/percentToSamplingRate codec (both directions were
  hand-coded in each command).
- config:get validates the path before any API call and only checks provider
  enablement when the requested path needs it.
- config:set: buildUpdate is now the single per-path decision site (folds in the
  confirmation message and current-value read), the switch is exhaustive so a new
  path cannot silently fall into the sample-rate branch, the percentage requires a
  plain decimal integer (Number() also accepted hex and scientific notation), and
  the --json result echoes the normalized value.
- ensureAILogicApiEnabled reuses isAILogicApiEnabled instead of inlining the check.
- config:set preflights serviceusage.services.get (ensureAILogicApiEnabled reads
  enablement state via Service Usage; without it a cold cache surfaced a raw 403
  mid-command despite passing requirePermissions).
- Echo a normalized sample-rate value ('007' -> '7') so the success message and
  --json output match what was stored.
- ensureAILogicApiEnabled honors --force for its enable confirmation and the
  provider selection offers a cancel choice (the Spark-plan retry loop had no
  exit besides Ctrl+C).
- Strengthen provider specs: pin each provider to its own API via withArgs (a
  swapped destructure passed before) and assert the disable cross-check consults
  the other provider's API.
@joehan
joehan self-requested a review July 24, 2026 19:16

@joehan joehan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, with some simple nits


export const command = new Command("ailogic:config:get [path]")
.description("read AI Logic configuration")
.before(requirePermissions, ["firebasevertexai.config.get", "serviceusage.services.get"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add detailed help text explaining how to use this command using the .help() method. Would be particularly nice to explain what values are allowed for [path]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added help text listing all the readable paths (built from the path list so it stays in sync) plus an example.

export const command = new Command("ailogic:config:set <path> <value>")
.description("set one configuration value")
.option("-f, --force", "bypass confirmation prompt")
.before(requirePermissions, [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add detailed help text explaining how to use this command using the .help() method. Would be particularly nice to explain what values are allowed for [path]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added help text listing each writable path with the values it accepts.

.description("disable a Gemini API provider service")
.option("-f, --force", "bypass confirmation prompt")
.before(requirePermissions, ["serviceusage.services.disable", "firebasevertexai.config.update"])
.action(async (providerType: string, options: Options) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add detailed help text explaining how to use this command using the .help() method. Would be particularly nice to explain what values are allowed for providerType

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added help text listing the valid provider types.

export const command = new Command("ailogic:providers:enable <providerType>")
.description("enable a Gemini API provider service")
.before(requirePermissions, ["serviceusage.services.enable", "firebasevertexai.config.update"])
.action(async (providerType: string, options: Options) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add detailed help text explaining how to use this command using the .help() method. Would be particularly nice to explain what values are allowed for

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added help text listing the valid provider types, noting the Blaze plan requirement for the agent platform.

Comment thread CHANGELOG.md Outdated
@@ -1,3 +1,5 @@
- Added `firebase ailogic:providers:*` CLI commands to enable, disable, and list Gemini API providers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can omit the changelog while we are developing behind a flag - we'll add Changelogs for all when we flip the falg

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the changelog entries; will add them back when the flag flips.

@joehan

joehan commented Jul 24, 2026

Copy link
Copy Markdown
Member

One other note - please move these PRs over to a branch on the main repo. If you don't have access, go/firebase-github-access

Comment thread src/gcp/ailogic.ts Outdated
}
}

/**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty comment blocks - agents love adding these for some reason

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed both empty comment blocks. They had been added to silence a jsdoc lint warning, but it is warn-level only, so removing them is harmless.

Comment thread src/gcp/ailogic.ts Outdated
* Converts the API's telemetry sampling rate, a fraction in (0,1], to the
* integer percentage (1-100) the CLI exposes.
*/
export function samplingRateToPercent(samplingRate: number): number {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super overkill to make this a function when it is only used once. Same with the inverse function. Also, no need to export functions that are not used elsewhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed both functions and inlined the conversions at their single call sites.

marb2000 added 3 commits July 26, 2026 21:26
- Add detailed .help() text to ailogic:config:get/set and
  ailogic:providers:enable/disable documenting allowed values
- Drop CHANGELOG entries while the feature is behind the experiment flag
- Remove empty JSDoc blocks in gcp/ailogic.ts
- Inline single-use sampling-rate conversions instead of exporting helpers
- listProviders now reports a provider as enabled only when the Firebase
  AI Logic API (firebasevertexai.googleapis.com) is also enabled, so
  providers:list can no longer disagree with other ailogic commands about
  whether AI Logic is enabled on the project
- enableProvider enables the AI Logic API before the provider's service
  API, so a partial failure cannot land in that inconsistent state
@marb2000

Copy link
Copy Markdown
Member Author

FYI: I found and fixed a provider-state inconsistency bug on the providers PR (details in #10778 (comment)). This branch picks the fix up via a merge commit.

@marb2000

Copy link
Copy Markdown
Member Author

Closing in favor of #10850, which moves this to a branch on the main repo as @joehan requested. The branch is identical (all review nits addressed, and it carries the provider-state consistency fix via the providers branch). @christhompsongoogle FYI. Approvals do not carry over, so a fresh stamp on #10850 would be appreciated.

@marb2000 marb2000 closed this Jul 27, 2026
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.

4 participants