Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/apiv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@

import * as auth from "./auth";
import { FirebaseError } from "./error";
import { isFirebaseMcp, detectAIAgent } from "./env";
import { logger } from "./logger";
import { responseToError } from "./responseToError";
import * as FormData from "form-data";

// Using import would require resolveJsonModule, which seems to break the
// build/output format.
const pkg = require("../package.json");

Check warning on line 19 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

Check warning on line 19 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const CLI_VERSION: string = pkg.version;

Check warning on line 20 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .version on an `any` value

Check warning on line 20 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

const agent = detectAIAgent();
const agentStr = agent === "unknown" ? "None" : agent;
const platform = isFirebaseMcp() ? "FirebaseMCP" : "FirebaseCLI";
const clientVersion = `${platform}/${CLI_VERSION}/${agentStr}`;

export const STANDARD_HEADERS: Record<string, string> = {
Connection: "keep-alive",
"User-Agent": `FirebaseCLI/${CLI_VERSION}`,
"X-Client-Version": `FirebaseCLI/${CLI_VERSION}`,
"User-Agent": clientVersion,
"X-Client-Version": clientVersion,
};

const GOOG_QUOTA_USER_HEADER = "x-goog-quota-user";
Expand Down Expand Up @@ -124,7 +130,7 @@

/**
* Gets a singleton access token
* @returns An access token

Check warning on line 133 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid JSDoc tag (preference). Replace "returns" JSDoc tag with "return"
*/
export async function getAccessToken(): Promise<string> {
const valid = auth.haveValidTokens(refreshToken, []);
Expand Down Expand Up @@ -229,7 +235,7 @@
* Makes a request as specified by the options.
* By default, this will:
* - use content-type: application/json
* - assume the HTTP GET method

Check warning on line 238 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected only 0 line after block description
*
* @example
* const res = apiv2.request<ResourceType>({
Expand Down Expand Up @@ -268,7 +274,7 @@
}
try {
return await this.doRequest<ReqT, ResT>(internalReqOptions);
} catch (thrown: any) {

Check warning on line 277 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (thrown instanceof FirebaseError) {
throw thrown;
}
Expand All @@ -277,7 +283,7 @@
if (thrown instanceof Error) {
err = thrown;
} else {
err = new Error(thrown);

Check warning on line 286 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string | undefined`
}
throw new FirebaseError(`Failed to make request: ${err.message}`, { original: err });
}
Expand Down Expand Up @@ -365,7 +371,7 @@
}

if (options.signal) {
const signal = options.signal as any;

Check warning on line 374 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 374 in src/apiv2.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
signal.reason = "";
signal.throwIfAborted = () => {
throw new FirebaseError("Aborted");
Expand Down
12 changes: 12 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ export function isFirebaseStudio() {
export function isFirebaseMcp() {
return !!process.env.IS_FIREBASE_MCP;
}

// Detect if the CLI was invoked by a coding agent, based on well-known env vars.
export function detectAIAgent(): string {
if (process.env.ANTIGRAVITY_CLI_ALIAS) return "antigravity";
if (process.env.CLAUDECODE) return "claude_code";
if (process.env.CLINE_ACTIVE) return "cline";
if (process.env.CODEX_SANDBOX) return "codex_cli";
if (process.env.CURSOR_AGENT) return "cursor";
if (process.env.GEMINI_CLI) return "gemini_cli";
if (process.env.OPENCODE) return "open_code";
return "unknown";
}
13 changes: 1 addition & 12 deletions src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@ import { getGlobalDefaultAccount } from "./auth";

import { configstore } from "./configstore";
import { logger } from "./logger";
import { isFirebaseStudio } from "./env";
import { isFirebaseStudio, detectAIAgent } from "./env";
const pkg = require("../package.json");

// Detect if the CLI was invoked by a coding agent, based on well-known env vars.
function detectAIAgent(): string {
if (process.env.CLAUDECODE) return "claude_code";
if (process.env.CLINE_ACTIVE) return "cline";
if (process.env.CODEX_SANDBOX) return "codex_cli";
if (process.env.CURSOR_AGENT) return "cursor";
if (process.env.GEMINI_CLI) return "gemini_cli";
if (process.env.OPENCODE) return "open_code";
return "unknown";
}

type cliEventNames =
| "command_execution"
| "product_deploy"
Expand Down
Loading