firebase-tools-with-isolate 15.11.0-3 → 15.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/agentSkills.js +70 -0
- package/lib/api.js +3 -1
- package/lib/apphosting/backend.js +22 -3
- package/lib/apphosting/config.js +19 -2
- package/lib/apphosting/localbuilds.js +25 -4
- package/lib/apphosting/prompts.js +35 -0
- package/lib/bin/mcp.js +5 -1
- package/lib/commands/apphosting-backends-create.js +19 -2
- package/lib/commands/apphosting-backends-list.js +25 -5
- package/lib/commands/ext-info.js +5 -1
- package/lib/commands/functions-delete.js +1 -0
- package/lib/commands/functions-export.js +40 -0
- package/lib/commands/index.js +3 -0
- package/lib/commands/init.js +1 -0
- package/lib/deploy/apphosting/deploy.js +11 -6
- package/lib/deploy/apphosting/prepare.js +88 -4
- package/lib/deploy/apphosting/release.js +2 -5
- package/lib/deploy/apphosting/util.js +45 -2
- package/lib/deploy/functions/prepare.js +5 -1
- package/lib/deploy/functions/prepareFunctionsUpload.js +5 -2
- package/lib/deploy/functions/release/fabricator.js +4 -3
- package/lib/deploy/functions/release/index.js +5 -0
- package/lib/deploy/functions/services/ailogic.js +68 -0
- package/lib/deploy/functions/services/index.js +4 -0
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/storage/rules/manager.js +10 -3
- package/lib/emulator/storage/rules/runtime.js +9 -7
- package/lib/experiments.js +22 -0
- package/lib/extensions/listExtensions.js +2 -0
- package/lib/firebase_studio/migrate.js +30 -61
- package/lib/functions/iac/export.js +36 -0
- package/lib/functions/iac/terraform.js +146 -0
- package/lib/gcp/ailogic.js +108 -0
- package/lib/gcp/apphosting.js +6 -0
- package/lib/gcp/cloudfunctionsv2.js +24 -0
- package/lib/gcp/cloudsql/cloudsqladmin.js +1 -1
- package/lib/init/features/agentSkills.js +26 -0
- package/lib/init/features/apphosting.js +11 -2
- package/lib/init/features/dataconnect/sdk.js +26 -12
- package/lib/init/features/functions/index.js +7 -4
- package/lib/init/features/index.js +4 -1
- package/lib/init/index.js +6 -0
- package/lib/mcp/index.js +1 -1
- package/lib/mcp/tools/core/read_resources.js +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +8 -0
- package/package.json +7 -5
- package/standalone/package.json +1 -1
- package/templates/extensions/typescript/package.lint.json +1 -1
- package/templates/extensions/typescript/package.nolint.json +1 -1
- package/templates/extensions/typescript/tsconfig.json +1 -0
- package/templates/init/functions/typescript/package-ongraphrequest.lint.json +1 -1
- package/templates/init/functions/typescript/package-ongraphrequest.nolint.json +1 -1
- package/templates/init/functions/typescript/package.lint.json +1 -1
- package/templates/init/functions/typescript/package.nolint.json +1 -1
- package/templates/init/functions/typescript/tsconfig.json +1 -0
|
@@ -17,7 +17,8 @@ const secrets_1 = require("../apphosting/secrets");
|
|
|
17
17
|
const env = require("../functions/env");
|
|
18
18
|
const error_1 = require("../error");
|
|
19
19
|
const os = require("os");
|
|
20
|
-
|
|
20
|
+
const agentSkills_1 = require("../agentSkills");
|
|
21
|
+
async function setupAntigravityMcpServer(rootPath, appType, nonInteractive) {
|
|
21
22
|
const mcpConfigDir = path.join(os.homedir(), ".gemini", "antigravity");
|
|
22
23
|
const mcpConfigPath = path.join(mcpConfigDir, "mcp_config.json");
|
|
23
24
|
let mcpConfig = { mcpServers: {} };
|
|
@@ -43,6 +44,7 @@ async function setupAntigravityMcpServer(rootPath, appType) {
|
|
|
43
44
|
const confirmFirebase = await prompt.confirm({
|
|
44
45
|
message: "Would you like to enable the Firebase MCP server for Antigravity?",
|
|
45
46
|
default: true,
|
|
47
|
+
nonInteractive,
|
|
46
48
|
});
|
|
47
49
|
if (confirmFirebase) {
|
|
48
50
|
mcpConfig.mcpServers["firebase"] = {
|
|
@@ -66,6 +68,7 @@ async function setupAntigravityMcpServer(rootPath, appType) {
|
|
|
66
68
|
const confirmDart = await prompt.confirm({
|
|
67
69
|
message: "Would you like to enable the Dart MCP server for Antigravity?",
|
|
68
70
|
default: true,
|
|
71
|
+
nonInteractive,
|
|
69
72
|
});
|
|
70
73
|
if (confirmDart) {
|
|
71
74
|
mcpConfig.mcpServers["dart"] = {
|
|
@@ -89,8 +92,7 @@ async function setupAntigravityMcpServer(rootPath, appType) {
|
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
catch (err) {
|
|
92
|
-
|
|
93
|
-
utils.logWarning(`Could not configure Antigravity MCP server: ${message}`);
|
|
95
|
+
utils.logWarning(`Could not configure Antigravity MCP server: ${(0, error_1.getErrMsg)(err)}`);
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
async function detectAppType(rootPath) {
|
|
@@ -218,7 +220,7 @@ async function updateReadme(rootPath, framework) {
|
|
|
218
220
|
await fs.writeFile(readmePath, newReadme);
|
|
219
221
|
logger_1.logger.info("✅ Updated README.md with project details and origin info");
|
|
220
222
|
}
|
|
221
|
-
async function injectAntigravityContext(rootPath, projectId, appName) {
|
|
223
|
+
async function injectAntigravityContext(rootPath, projectId, appName, nonInteractive) {
|
|
222
224
|
const agentDir = path.join(rootPath, ".agents");
|
|
223
225
|
const rulesDir = path.join(agentDir, "rules");
|
|
224
226
|
const workflowsDir = path.join(agentDir, "workflows");
|
|
@@ -233,40 +235,14 @@ async function injectAntigravityContext(rootPath, projectId, appName) {
|
|
|
233
235
|
{ name: "Globally for all projects", value: "global" },
|
|
234
236
|
],
|
|
235
237
|
default: "local",
|
|
236
|
-
nonInteractive: process.env.NODE_ENV === "test",
|
|
238
|
+
nonInteractive: nonInteractive || process.env.NODE_ENV === "test",
|
|
239
|
+
});
|
|
240
|
+
await (0, agentSkills_1.installAgentSkills)({
|
|
241
|
+
cwd: rootPath,
|
|
242
|
+
global: installLocation === "global",
|
|
243
|
+
background: false,
|
|
244
|
+
agentName: "gemini-cli",
|
|
237
245
|
});
|
|
238
|
-
logger_1.logger.info("⏳ Adding Antigravity skills...");
|
|
239
|
-
try {
|
|
240
|
-
const args = [
|
|
241
|
-
"-y",
|
|
242
|
-
"skills",
|
|
243
|
-
"add",
|
|
244
|
-
"firebase/agent-skills",
|
|
245
|
-
"-a",
|
|
246
|
-
"gemini-cli",
|
|
247
|
-
"--skill",
|
|
248
|
-
"*",
|
|
249
|
-
"-y",
|
|
250
|
-
];
|
|
251
|
-
if (installLocation === "global") {
|
|
252
|
-
args.push("-g");
|
|
253
|
-
}
|
|
254
|
-
const result = (0, child_process_1.spawnSync)("npx", args, {
|
|
255
|
-
cwd: rootPath,
|
|
256
|
-
stdio: "ignore",
|
|
257
|
-
shell: process.platform === "win32",
|
|
258
|
-
});
|
|
259
|
-
if (result.error) {
|
|
260
|
-
throw result.error;
|
|
261
|
-
}
|
|
262
|
-
if (result.status !== 0) {
|
|
263
|
-
throw new Error(`npx skills add exited with code ${result.status}`);
|
|
264
|
-
}
|
|
265
|
-
logger_1.logger.info(`✅ Added Antigravity skills`);
|
|
266
|
-
}
|
|
267
|
-
catch (err) {
|
|
268
|
-
utils.logWarning(`Could not add Antigravity skills, skipping. ${err}`);
|
|
269
|
-
}
|
|
270
246
|
const systemInstructionsTemplate = await (0, templates_1.readTemplate)("firebase-studio-export/system_instructions_template.md");
|
|
271
247
|
const systemInstructions = systemInstructionsTemplate.replace("${appName}", appName);
|
|
272
248
|
await fs.writeFile(path.join(rulesDir, "migration-context.md"), systemInstructions);
|
|
@@ -277,8 +253,7 @@ async function injectAntigravityContext(rootPath, projectId, appName) {
|
|
|
277
253
|
logger_1.logger.info("✅ Created Antigravity startup workflow");
|
|
278
254
|
}
|
|
279
255
|
catch (err) {
|
|
280
|
-
|
|
281
|
-
logger_1.logger.debug(`Could not read or write startup workflow: ${message}`);
|
|
256
|
+
logger_1.logger.debug(`Could not read or write startup workflow: ${(0, error_1.getErrMsg)(err)}`);
|
|
282
257
|
}
|
|
283
258
|
}
|
|
284
259
|
async function getAgyCommand(startAgy) {
|
|
@@ -316,7 +291,7 @@ async function getAgyCommand(startAgy) {
|
|
|
316
291
|
logger_1.logger.info(`⚠️ Antigravity IDE not found in your PATH. To ensure a seamless migration, please download and install Antigravity: ${downloadLink}`);
|
|
317
292
|
return undefined;
|
|
318
293
|
}
|
|
319
|
-
async function createFirebaseConfigs(rootPath, projectId) {
|
|
294
|
+
async function createFirebaseConfigs(rootPath, projectId, nonInteractive) {
|
|
320
295
|
if (!projectId) {
|
|
321
296
|
return;
|
|
322
297
|
}
|
|
@@ -351,7 +326,7 @@ async function createFirebaseConfigs(rootPath, projectId) {
|
|
|
351
326
|
const confirmBackend = await prompt.confirm({
|
|
352
327
|
message: `Would you like to use the App Hosting backend "${selectedBackendId}"?`,
|
|
353
328
|
default: true,
|
|
354
|
-
nonInteractive: process.env.NODE_ENV === "test",
|
|
329
|
+
nonInteractive: nonInteractive || process.env.NODE_ENV === "test",
|
|
355
330
|
});
|
|
356
331
|
if (confirmBackend) {
|
|
357
332
|
backendId = selectedBackendId;
|
|
@@ -376,8 +351,7 @@ async function createFirebaseConfigs(rootPath, projectId) {
|
|
|
376
351
|
}
|
|
377
352
|
}
|
|
378
353
|
catch (err) {
|
|
379
|
-
|
|
380
|
-
utils.logWarning(`Could not fetch backends from Firebase CLI, using default "studio". ${message}`);
|
|
354
|
+
utils.logWarning(`Could not fetch backends from Firebase CLI, using default "studio". ${(0, error_1.getErrMsg)(err)}`);
|
|
381
355
|
}
|
|
382
356
|
const firebaseJson = {
|
|
383
357
|
apphosting: {
|
|
@@ -433,8 +407,7 @@ async function writeAntigravityConfigs(rootPath, framework) {
|
|
|
433
407
|
settings = JSON.parse(settingsContent);
|
|
434
408
|
}
|
|
435
409
|
catch (err) {
|
|
436
|
-
|
|
437
|
-
logger_1.logger.debug(`Could not read ${settingsPath}: ${message}`);
|
|
410
|
+
logger_1.logger.debug(`Could not read ${settingsPath}: ${(0, error_1.getErrMsg)(err)}`);
|
|
438
411
|
}
|
|
439
412
|
const cleanSettings = {};
|
|
440
413
|
for (const [key, value] of Object.entries(settings)) {
|
|
@@ -497,8 +470,7 @@ async function cleanupUnusedFiles(rootPath) {
|
|
|
497
470
|
}
|
|
498
471
|
}
|
|
499
472
|
catch (err) {
|
|
500
|
-
|
|
501
|
-
logger_1.logger.debug(`Could not remove ${docsDir}: ${message}`);
|
|
473
|
+
logger_1.logger.debug(`Could not remove ${docsDir}: ${(0, error_1.getErrMsg)(err)}`);
|
|
502
474
|
}
|
|
503
475
|
const modifiedPath = path.join(rootPath, ".modified");
|
|
504
476
|
try {
|
|
@@ -506,8 +478,7 @@ async function cleanupUnusedFiles(rootPath) {
|
|
|
506
478
|
logger_1.logger.info("✅ Cleaned up .modified");
|
|
507
479
|
}
|
|
508
480
|
catch (err) {
|
|
509
|
-
|
|
510
|
-
logger_1.logger.debug(`Could not delete ${modifiedPath}: ${message}`);
|
|
481
|
+
logger_1.logger.debug(`Could not delete ${modifiedPath}: ${(0, error_1.getErrMsg)(err)}`);
|
|
511
482
|
}
|
|
512
483
|
const mcpJsonPath = path.join(rootPath, ".idx", "mcp.json");
|
|
513
484
|
try {
|
|
@@ -515,8 +486,7 @@ async function cleanupUnusedFiles(rootPath) {
|
|
|
515
486
|
logger_1.logger.info("✅ Cleaned up .idx/mcp.json");
|
|
516
487
|
}
|
|
517
488
|
catch (err) {
|
|
518
|
-
|
|
519
|
-
logger_1.logger.debug(`Could not delete ${mcpJsonPath}: ${message}`);
|
|
489
|
+
logger_1.logger.debug(`Could not delete ${mcpJsonPath}: ${(0, error_1.getErrMsg)(err)}`);
|
|
520
490
|
}
|
|
521
491
|
}
|
|
522
492
|
async function upgradeGenkitVersion(rootPath) {
|
|
@@ -548,8 +518,7 @@ async function upgradeGenkitVersion(rootPath) {
|
|
|
548
518
|
}
|
|
549
519
|
}
|
|
550
520
|
catch (err) {
|
|
551
|
-
|
|
552
|
-
logger_1.logger.debug(`Could not upgrade Genkit version: ${message}`);
|
|
521
|
+
logger_1.logger.debug(`Could not upgrade Genkit version: ${(0, error_1.getErrMsg)(err)}`);
|
|
553
522
|
}
|
|
554
523
|
}
|
|
555
524
|
async function uploadSecrets(rootPath, projectId) {
|
|
@@ -577,11 +546,10 @@ async function uploadSecrets(rootPath, projectId) {
|
|
|
577
546
|
}
|
|
578
547
|
}
|
|
579
548
|
catch (err) {
|
|
580
|
-
|
|
581
|
-
utils.logWarning(`Failed to upload GEMINI_API_KEY secret: ${message}`);
|
|
549
|
+
utils.logWarning(`Failed to upload GEMINI_API_KEY secret: ${(0, error_1.getErrMsg)(err)}`);
|
|
582
550
|
}
|
|
583
551
|
}
|
|
584
|
-
async function askToOpenAntigravity(rootPath, appName, startAntigravity) {
|
|
552
|
+
async function askToOpenAntigravity(rootPath, appName, startAntigravity, nonInteractive) {
|
|
585
553
|
const agyCommand = await getAgyCommand(startAntigravity);
|
|
586
554
|
logger_1.logger.info(`\n🎉 Your Firebase Studio project "${appName}" is now ready for Antigravity!`);
|
|
587
555
|
logger_1.logger.info("Antigravity is Google's agentic IDE, where you can collaborate with AI agents to build, test, and deploy your application.");
|
|
@@ -595,6 +563,7 @@ async function askToOpenAntigravity(rootPath, appName, startAntigravity) {
|
|
|
595
563
|
const answer = await prompt.confirm({
|
|
596
564
|
message: "Would you like to open it in Antigravity now?",
|
|
597
565
|
default: true,
|
|
566
|
+
nonInteractive,
|
|
598
567
|
});
|
|
599
568
|
if (answer) {
|
|
600
569
|
logger_1.logger.info(`⏳ Opening ${appName} in Antigravity...`);
|
|
@@ -629,7 +598,7 @@ async function checkDirectoryExists(dir) {
|
|
|
629
598
|
async function migrate(rootPath, options = { startAntigravity: true }) {
|
|
630
599
|
await checkDirectoryExists(rootPath);
|
|
631
600
|
const appType = await detectAppType(rootPath);
|
|
632
|
-
|
|
601
|
+
await track.trackGA4("firebase_studio_migrate", { app_type: appType, result: "started" });
|
|
633
602
|
logger_1.logger.info("🚀 Starting Firebase Studio to Antigravity migration...");
|
|
634
603
|
logger_1.logger.info("\nFile any bugs at https://github.com/firebase/firebase-tools/issues");
|
|
635
604
|
const { projectId, appName } = await extractMetadata(rootPath, options.project);
|
|
@@ -637,17 +606,17 @@ async function migrate(rootPath, options = { startAntigravity: true }) {
|
|
|
637
606
|
logger_1.logger.info(`✅ Detected framework: ${appType}`);
|
|
638
607
|
}
|
|
639
608
|
await updateReadme(rootPath, appType);
|
|
640
|
-
await createFirebaseConfigs(rootPath, projectId);
|
|
609
|
+
await createFirebaseConfigs(rootPath, projectId, options.nonInteractive);
|
|
641
610
|
await uploadSecrets(rootPath, projectId);
|
|
642
611
|
await upgradeGenkitVersion(rootPath);
|
|
643
|
-
await injectAntigravityContext(rootPath, projectId, appName);
|
|
612
|
+
await injectAntigravityContext(rootPath, projectId, appName, options.nonInteractive);
|
|
644
613
|
await writeAntigravityConfigs(rootPath, appType);
|
|
645
|
-
await setupAntigravityMcpServer(rootPath, appType);
|
|
614
|
+
await setupAntigravityMcpServer(rootPath, appType, options.nonInteractive);
|
|
646
615
|
await cleanupUnusedFiles(rootPath);
|
|
647
616
|
const currentFolderName = path.basename(rootPath);
|
|
648
617
|
if (currentFolderName === "download") {
|
|
649
618
|
logger_1.logger.info(`\n💡 Tip: You may want to rename this folder to "${appName.toLowerCase().replace(/\s+/g, "-")}"`);
|
|
650
619
|
}
|
|
651
620
|
await track.trackGA4("firebase_studio_migrate", { app_type: appType, result: "success" });
|
|
652
|
-
await askToOpenAntigravity(rootPath, appName, options.startAntigravity);
|
|
621
|
+
await askToOpenAntigravity(rootPath, appName, options.startAntigravity, options.nonInteractive);
|
|
653
622
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInternalIac = getInternalIac;
|
|
4
|
+
const runtimes = require("../../deploy/functions/runtimes");
|
|
5
|
+
const supported = require("../../deploy/functions/runtimes/supported");
|
|
6
|
+
const functionsConfig = require("../../functionsConfig");
|
|
7
|
+
const functionsEnv = require("../../functions/env");
|
|
8
|
+
const logger_1 = require("../../logger");
|
|
9
|
+
const yaml = require("js-yaml");
|
|
10
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
11
|
+
const error_1 = require("../../error");
|
|
12
|
+
async function getInternalIac(options, codebase) {
|
|
13
|
+
if (!codebase.source) {
|
|
14
|
+
throw new error_1.FirebaseError("Cannot export a codebase with no source");
|
|
15
|
+
}
|
|
16
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
17
|
+
const firebaseConfig = await functionsConfig.getFirebaseConfig(options);
|
|
18
|
+
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId);
|
|
19
|
+
const delegateContext = {
|
|
20
|
+
projectId,
|
|
21
|
+
sourceDir: options.config.path(codebase.source),
|
|
22
|
+
projectDir: options.config.projectDir,
|
|
23
|
+
runtime: codebase.runtime,
|
|
24
|
+
};
|
|
25
|
+
const runtimeDelegate = await runtimes.getRuntimeDelegate(delegateContext);
|
|
26
|
+
logger_1.logger.debug(`Validating ${runtimeDelegate.language} source`);
|
|
27
|
+
supported.guardVersionSupport(runtimeDelegate.runtime);
|
|
28
|
+
await runtimeDelegate.validate();
|
|
29
|
+
logger_1.logger.debug(`Building ${runtimeDelegate.language} source`);
|
|
30
|
+
await runtimeDelegate.build();
|
|
31
|
+
logger_1.logger.debug(`Discovering ${runtimeDelegate.language} source`);
|
|
32
|
+
const build = await runtimeDelegate.discoverBuild({}, firebaseEnvs);
|
|
33
|
+
return {
|
|
34
|
+
"functions.yaml": yaml.dump(build),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expr = expr;
|
|
4
|
+
exports.copyField = copyField;
|
|
5
|
+
exports.renameField = renameField;
|
|
6
|
+
exports.serviceAccount = serviceAccount;
|
|
7
|
+
exports.serializeValue = serializeValue;
|
|
8
|
+
exports.blockToString = blockToString;
|
|
9
|
+
const utils = require("../../utils");
|
|
10
|
+
const error_1 = require("../../error");
|
|
11
|
+
function expr(string) {
|
|
12
|
+
return { "@type": "HCLExpression", value: string };
|
|
13
|
+
}
|
|
14
|
+
function copyField(attributes, source, field, transform = (v) => v) {
|
|
15
|
+
renameField(attributes, source, utils.toLowerSnakeCase(field), field, transform);
|
|
16
|
+
}
|
|
17
|
+
function renameField(attributes, source, attributeField, sourceField, transform = (v) => v) {
|
|
18
|
+
const val = source[sourceField];
|
|
19
|
+
if (val === undefined) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
attributes[attributeField] = val === null ? null : transform(val);
|
|
23
|
+
}
|
|
24
|
+
function serviceAccount(sa) {
|
|
25
|
+
if (sa.endsWith("@")) {
|
|
26
|
+
return `${sa}\${var.project}.iam.gserviceaccount.com`;
|
|
27
|
+
}
|
|
28
|
+
return sa;
|
|
29
|
+
}
|
|
30
|
+
function serializeValue(value, indentation = 0) {
|
|
31
|
+
if (typeof value === "string") {
|
|
32
|
+
value = value.replace(/{{ *params\.PROJECT_ID *}}/g, "${var.project}");
|
|
33
|
+
if (value.includes("{{ ")) {
|
|
34
|
+
throw new error_1.FirebaseError("Generalized parameterized fields are not supported in terraform yet");
|
|
35
|
+
}
|
|
36
|
+
return JSON.stringify(value);
|
|
37
|
+
}
|
|
38
|
+
else if (typeof value === "number" || typeof value === "boolean") {
|
|
39
|
+
return value.toString();
|
|
40
|
+
}
|
|
41
|
+
else if (value === null || value === undefined) {
|
|
42
|
+
return "null";
|
|
43
|
+
}
|
|
44
|
+
else if (Array.isArray(value)) {
|
|
45
|
+
if (value.some((e) => e !== null &&
|
|
46
|
+
typeof e === "object" &&
|
|
47
|
+
(Array.isArray(e) || e["@type"] !== "HCLExpression"))) {
|
|
48
|
+
return `[\n${value.map((v) => " ".repeat(indentation + 1) + serializeValue(v, indentation + 1)).join(",\n")}\n${" ".repeat(indentation)}]`;
|
|
49
|
+
}
|
|
50
|
+
return `[${value.map((v) => serializeValue(v)).join(", ")}]`;
|
|
51
|
+
}
|
|
52
|
+
else if (typeof value === "object") {
|
|
53
|
+
if (value["@type"] === "HCLExpression") {
|
|
54
|
+
return value.value;
|
|
55
|
+
}
|
|
56
|
+
const entries = Object.entries(value).map(([k, v]) => `${" ".repeat(indentation + 1)}${k} = ${serializeValue(v, indentation + 1)}`);
|
|
57
|
+
return `{\n${entries.join("\n")}\n${" ".repeat(indentation)}}`;
|
|
58
|
+
}
|
|
59
|
+
throw new error_1.FirebaseError(`Unsupported terraform value type ${typeof value}`, { exit: 1 });
|
|
60
|
+
}
|
|
61
|
+
const PREFIX_ARGUMENTS = new Set(["count", "for_each", "provider"]);
|
|
62
|
+
const SUFFIX_ARGUMENTS = new Set(["lifecycle", "depends_on"]);
|
|
63
|
+
const NON_BLOCK_PARAMETERS = {
|
|
64
|
+
google_cloudfunctions_function: new Set([
|
|
65
|
+
"name",
|
|
66
|
+
"runtime",
|
|
67
|
+
"description",
|
|
68
|
+
"available_memory_mb",
|
|
69
|
+
"timeout",
|
|
70
|
+
"entry_point",
|
|
71
|
+
"source_archive_bucket",
|
|
72
|
+
"source_archive_object",
|
|
73
|
+
"trigger_http",
|
|
74
|
+
"environment_variables",
|
|
75
|
+
"vpc_connector",
|
|
76
|
+
"service_account_email",
|
|
77
|
+
"max_instances",
|
|
78
|
+
"min_instances",
|
|
79
|
+
"project",
|
|
80
|
+
"region",
|
|
81
|
+
]),
|
|
82
|
+
google_cloudfunctions2_function: new Set(["name", "location", "description", "project"]),
|
|
83
|
+
google_cloud_scheduler_job: new Set([
|
|
84
|
+
"name",
|
|
85
|
+
"description",
|
|
86
|
+
"schedule",
|
|
87
|
+
"time_zone",
|
|
88
|
+
"paused",
|
|
89
|
+
"attempt_deadline",
|
|
90
|
+
"region",
|
|
91
|
+
"project",
|
|
92
|
+
]),
|
|
93
|
+
google_cloud_tasks_queue: new Set(["name", "location", "desired_state", "project"]),
|
|
94
|
+
google_eventarc_trigger: new Set(["name", "location", "project", "service_account"]),
|
|
95
|
+
google_pubsub_topic: new Set([
|
|
96
|
+
"name",
|
|
97
|
+
"project",
|
|
98
|
+
"labels",
|
|
99
|
+
"kms_key_name",
|
|
100
|
+
"message_retention_duration",
|
|
101
|
+
]),
|
|
102
|
+
google_pubsub_subscription: new Set([
|
|
103
|
+
"name",
|
|
104
|
+
"topic",
|
|
105
|
+
"project",
|
|
106
|
+
"labels",
|
|
107
|
+
"ack_deadline_seconds",
|
|
108
|
+
"message_retention_duration",
|
|
109
|
+
"retain_acked_messages",
|
|
110
|
+
"enable_message_ordering",
|
|
111
|
+
"filter",
|
|
112
|
+
]),
|
|
113
|
+
};
|
|
114
|
+
function serializeResourceAttributes(attributes, resourceType, indentation = 0) {
|
|
115
|
+
const nonBlockParams = NON_BLOCK_PARAMETERS[resourceType] || new Set();
|
|
116
|
+
const prefixGroup = [];
|
|
117
|
+
const nonBlockGroup = [];
|
|
118
|
+
const blockGroup = [];
|
|
119
|
+
const suffixGroup = [];
|
|
120
|
+
for (const [k, v] of Object.entries(attributes)) {
|
|
121
|
+
const serialized = `${" ".repeat(indentation + 1)}${k} = ${serializeValue(v, indentation + 1)}`;
|
|
122
|
+
if (PREFIX_ARGUMENTS.has(k)) {
|
|
123
|
+
prefixGroup.push(serialized);
|
|
124
|
+
}
|
|
125
|
+
else if (nonBlockParams.has(k)) {
|
|
126
|
+
nonBlockGroup.push(serialized);
|
|
127
|
+
}
|
|
128
|
+
else if (SUFFIX_ARGUMENTS.has(k)) {
|
|
129
|
+
suffixGroup.push(serialized);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
blockGroup.push(serialized);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const nonemptyGroups = [prefixGroup, nonBlockGroup, blockGroup, suffixGroup].filter((g) => g.length > 0);
|
|
136
|
+
const joinedGroups = nonemptyGroups.map((g) => g.join("\n")).join("\n\n");
|
|
137
|
+
return `{\n${joinedGroups}\n${" ".repeat(indentation)}}`;
|
|
138
|
+
}
|
|
139
|
+
function blockToString(block, indentation = 0) {
|
|
140
|
+
const labels = (block.labels || []).map((l) => `"${l}"`).join(" ");
|
|
141
|
+
if (block.type === "resource" && block.labels?.length) {
|
|
142
|
+
const resourceType = block.labels[0];
|
|
143
|
+
return `${" ".repeat(indentation)}${block.type} ${labels ? labels + " " : ""}${serializeResourceAttributes(block.attributes, resourceType, indentation)}`;
|
|
144
|
+
}
|
|
145
|
+
return `${" ".repeat(indentation)}${block.type} ${labels ? labels + " " : ""}${serializeValue(block.attributes, indentation)}`;
|
|
146
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.client = exports.AI_LOGIC_TRIGGERS_TO_EVENTS = exports.AI_LOGIC_EVENTS_TO_TRIGGER = exports.API_VERSION = void 0;
|
|
4
|
+
exports.createTrigger = createTrigger;
|
|
5
|
+
exports.getTrigger = getTrigger;
|
|
6
|
+
exports.updateTrigger = updateTrigger;
|
|
7
|
+
exports.deleteTrigger = deleteTrigger;
|
|
8
|
+
exports.listTriggers = listTriggers;
|
|
9
|
+
exports.upsertBlockingFunction = upsertBlockingFunction;
|
|
10
|
+
exports.deleteBlockingFunction = deleteBlockingFunction;
|
|
11
|
+
const apiv2_1 = require("../apiv2");
|
|
12
|
+
const api_1 = require("../api");
|
|
13
|
+
const ailogic_1 = require("../deploy/functions/services/ailogic");
|
|
14
|
+
exports.API_VERSION = "v1beta";
|
|
15
|
+
exports.AI_LOGIC_EVENTS_TO_TRIGGER = {
|
|
16
|
+
[ailogic_1.AI_LOGIC_BEFORE_GENERATE_CONTENT]: "before-generate-content",
|
|
17
|
+
[ailogic_1.AI_LOGIC_AFTER_GENERATE_CONTENT]: "after-generate-content",
|
|
18
|
+
};
|
|
19
|
+
exports.AI_LOGIC_TRIGGERS_TO_EVENTS = {
|
|
20
|
+
"before-generate-content": ailogic_1.AI_LOGIC_BEFORE_GENERATE_CONTENT,
|
|
21
|
+
"after-generate-content": ailogic_1.AI_LOGIC_AFTER_GENERATE_CONTENT,
|
|
22
|
+
};
|
|
23
|
+
exports.client = new apiv2_1.Client({
|
|
24
|
+
urlPrefix: (0, api_1.aiLogicProxyOrigin)(),
|
|
25
|
+
auth: true,
|
|
26
|
+
apiVersion: exports.API_VERSION,
|
|
27
|
+
});
|
|
28
|
+
async function createTrigger(projectId, location, triggerId, trigger, validateOnly = false) {
|
|
29
|
+
const parent = `projects/${projectId}/locations/${location}`;
|
|
30
|
+
const res = await exports.client.post(`${parent}/triggers`, trigger, {
|
|
31
|
+
queryParams: {
|
|
32
|
+
triggerId,
|
|
33
|
+
validateOnly: validateOnly ? "true" : "false",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return res.body;
|
|
37
|
+
}
|
|
38
|
+
async function getTrigger(projectId, location, triggerId) {
|
|
39
|
+
const name = `projects/${projectId}/locations/${location}/triggers/${triggerId}`;
|
|
40
|
+
const res = await exports.client.get(name);
|
|
41
|
+
return res.body;
|
|
42
|
+
}
|
|
43
|
+
async function updateTrigger(projectId, location, triggerId, trigger, updateMask, allowMissing = false, validateOnly = false) {
|
|
44
|
+
const name = `projects/${projectId}/locations/${location}/triggers/${triggerId}`;
|
|
45
|
+
const queryParams = {
|
|
46
|
+
allowMissing: allowMissing ? "true" : "false",
|
|
47
|
+
validateOnly: validateOnly ? "true" : "false",
|
|
48
|
+
};
|
|
49
|
+
if (updateMask && updateMask.length > 0) {
|
|
50
|
+
queryParams.updateMask = updateMask.join(",");
|
|
51
|
+
}
|
|
52
|
+
const res = await exports.client.patch(name, trigger, { queryParams });
|
|
53
|
+
return res.body;
|
|
54
|
+
}
|
|
55
|
+
async function deleteTrigger(projectId, location, triggerId, allowMissing = false, validateOnly = false, etag) {
|
|
56
|
+
const name = `projects/${projectId}/locations/${location}/triggers/${triggerId}`;
|
|
57
|
+
const queryParams = {
|
|
58
|
+
allowMissing: allowMissing ? "true" : "false",
|
|
59
|
+
validateOnly: validateOnly ? "true" : "false",
|
|
60
|
+
};
|
|
61
|
+
if (etag) {
|
|
62
|
+
queryParams.etag = etag;
|
|
63
|
+
}
|
|
64
|
+
await exports.client.delete(name, { queryParams });
|
|
65
|
+
}
|
|
66
|
+
async function listTriggers(projectId, location, filter) {
|
|
67
|
+
const parent = `projects/${projectId}/locations/${location}`;
|
|
68
|
+
let pageToken;
|
|
69
|
+
const triggers = [];
|
|
70
|
+
do {
|
|
71
|
+
const queryParams = pageToken ? { pageToken } : {};
|
|
72
|
+
if (filter) {
|
|
73
|
+
queryParams.filter = filter;
|
|
74
|
+
}
|
|
75
|
+
const res = await exports.client.get(`${parent}/triggers`, { queryParams });
|
|
76
|
+
if (res.body.triggers) {
|
|
77
|
+
triggers.push(...res.body.triggers);
|
|
78
|
+
}
|
|
79
|
+
pageToken = res.body.nextPageToken;
|
|
80
|
+
} while (pageToken);
|
|
81
|
+
return triggers;
|
|
82
|
+
}
|
|
83
|
+
async function upsertBlockingFunction(endpoint) {
|
|
84
|
+
const eventType = endpoint.blockingTrigger.eventType;
|
|
85
|
+
const triggerId = exports.AI_LOGIC_EVENTS_TO_TRIGGER[eventType];
|
|
86
|
+
const location = endpoint.blockingTrigger.options?.regionalWebhook ? endpoint.region : "global";
|
|
87
|
+
const triggerBody = {
|
|
88
|
+
cloudFunction: {
|
|
89
|
+
id: endpoint.id,
|
|
90
|
+
locationId: endpoint.region,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
return await createTrigger(endpoint.project, location, triggerId, triggerBody);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
if (err && typeof err === "object" && "status" in err && err.status === 409) {
|
|
98
|
+
return await updateTrigger(endpoint.project, location, triggerId, triggerBody);
|
|
99
|
+
}
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function deleteBlockingFunction(endpoint) {
|
|
104
|
+
const eventType = endpoint.blockingTrigger.eventType;
|
|
105
|
+
const triggerId = exports.AI_LOGIC_EVENTS_TO_TRIGGER[eventType];
|
|
106
|
+
const location = endpoint.blockingTrigger.options?.regionalWebhook ? endpoint.region : "global";
|
|
107
|
+
await deleteTrigger(endpoint.project, location, triggerId, true);
|
|
108
|
+
}
|
package/lib/gcp/apphosting.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.createRollout = createRollout;
|
|
|
16
16
|
exports.listRollouts = listRollouts;
|
|
17
17
|
exports.updateTraffic = updateTraffic;
|
|
18
18
|
exports.listLocations = listLocations;
|
|
19
|
+
exports.listSupportedRuntimes = listSupportedRuntimes;
|
|
19
20
|
exports.ensureApiEnabled = ensureApiEnabled;
|
|
20
21
|
exports.getNextRolloutId = getNextRolloutId;
|
|
21
22
|
const proto = require("../gcp/proto");
|
|
@@ -176,6 +177,11 @@ async function listLocations(projectId) {
|
|
|
176
177
|
} while (pageToken);
|
|
177
178
|
return locations;
|
|
178
179
|
}
|
|
180
|
+
async function listSupportedRuntimes(projectId, location) {
|
|
181
|
+
const name = `projects/${projectId}/locations/${location}/supportedRuntimes`;
|
|
182
|
+
const res = await exports.client.get(name);
|
|
183
|
+
return res.body.supportedRuntimes || [];
|
|
184
|
+
}
|
|
179
185
|
async function ensureApiEnabled(options) {
|
|
180
186
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
181
187
|
return await (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.apphostingOrigin)(), "app hosting", true);
|
|
@@ -21,6 +21,8 @@ const utils = require("../utils");
|
|
|
21
21
|
const projectConfig = require("../functions/projectConfig");
|
|
22
22
|
const constants_1 = require("../functions/constants");
|
|
23
23
|
const cloudfunctions_1 = require("./cloudfunctions");
|
|
24
|
+
const ailogic_1 = require("./ailogic");
|
|
25
|
+
const ailogic_2 = require("../deploy/functions/services/ailogic");
|
|
24
26
|
const k8s_1 = require("./k8s");
|
|
25
27
|
exports.API_VERSION = "v2";
|
|
26
28
|
const DEFAULT_MAX_INSTANCE_COUNT = 100;
|
|
@@ -263,6 +265,13 @@ function functionFromEndpoint(endpoint) {
|
|
|
263
265
|
else if (backend.isDataConnectGraphqlTriggered(endpoint)) {
|
|
264
266
|
gcfFunction.labels = { ...gcfFunction.labels, "deployment-fdcgraphql": "true" };
|
|
265
267
|
}
|
|
268
|
+
else if ((0, ailogic_2.isAILogicEvent)(endpoint)) {
|
|
269
|
+
gcfFunction.labels = {
|
|
270
|
+
...gcfFunction.labels,
|
|
271
|
+
"ailogic-event-type": ailogic_1.AI_LOGIC_EVENTS_TO_TRIGGER[endpoint.blockingTrigger.eventType],
|
|
272
|
+
"ailogic-locality": endpoint.blockingTrigger.options?.regionalWebhook ? "regional" : "global",
|
|
273
|
+
};
|
|
274
|
+
}
|
|
266
275
|
else if (backend.isBlockingTriggered(endpoint)) {
|
|
267
276
|
gcfFunction.labels = {
|
|
268
277
|
...gcfFunction.labels,
|
|
@@ -310,6 +319,21 @@ function endpointFromFunction(gcfFunction) {
|
|
|
310
319
|
dataConnectGraphqlTrigger: {},
|
|
311
320
|
};
|
|
312
321
|
}
|
|
322
|
+
else if (gcfFunction.labels?.["ailogic-event-type"]) {
|
|
323
|
+
const triggerType = gcfFunction.labels["ailogic-event-type"];
|
|
324
|
+
const eventType = ailogic_1.AI_LOGIC_TRIGGERS_TO_EVENTS[triggerType];
|
|
325
|
+
if (!eventType) {
|
|
326
|
+
throw new error_1.FirebaseError(`Unrecognized ailogic-event-type label: ${triggerType}`);
|
|
327
|
+
}
|
|
328
|
+
trigger = {
|
|
329
|
+
blockingTrigger: {
|
|
330
|
+
eventType,
|
|
331
|
+
options: {
|
|
332
|
+
regionalWebhook: gcfFunction.labels["ailogic-locality"] === "regional",
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
}
|
|
313
337
|
else if (gcfFunction.labels?.[constants_1.BLOCKING_LABEL]) {
|
|
314
338
|
trigger = {
|
|
315
339
|
blockingTrigger: {
|
|
@@ -61,7 +61,7 @@ async function getInstance(projectId, instanceId) {
|
|
|
61
61
|
function instanceConsoleLink(projectId, instanceId) {
|
|
62
62
|
return `https://console.cloud.google.com/sql/instances/${instanceId}/overview?project=${projectId}`;
|
|
63
63
|
}
|
|
64
|
-
exports.DEFAULT_DATABASE_VERSION = "
|
|
64
|
+
exports.DEFAULT_DATABASE_VERSION = "POSTGRES_18";
|
|
65
65
|
async function createInstance(args) {
|
|
66
66
|
const databaseFlags = [{ name: "cloudsql.iam_authentication", value: "on" }];
|
|
67
67
|
if (args.enableGoogleMlIntegration) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.askQuestions = askQuestions;
|
|
4
|
+
exports.actuate = actuate;
|
|
5
|
+
const agentSkills_1 = require("../../agentSkills");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
7
|
+
const error_1 = require("../../error");
|
|
8
|
+
async function askQuestions(setup) {
|
|
9
|
+
try {
|
|
10
|
+
logger_1.logger.info("If you are using an AI coding agent, Firebase Agent Skills make it an expert at Firebase.");
|
|
11
|
+
const shouldInstall = await (0, agentSkills_1.promptForAgentSkills)();
|
|
12
|
+
setup.featureInfo = setup.featureInfo || {};
|
|
13
|
+
setup.featureInfo.agentSkills = { shouldInstall };
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
logger_1.logger.debug(`Could not prompt for agent skills: ${(0, error_1.getErrMsg)(err)}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function actuate(setup, config) {
|
|
20
|
+
const info = setup.featureInfo?.agentSkills;
|
|
21
|
+
if (!info || !info.shouldInstall) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const cwd = config.projectDir;
|
|
25
|
+
void (0, agentSkills_1.installAgentSkills)({ background: true, cwd });
|
|
26
|
+
}
|
|
@@ -16,7 +16,8 @@ const templates_1 = require("../../templates");
|
|
|
16
16
|
const utils = require("../../utils");
|
|
17
17
|
const utils_1 = require("../../utils");
|
|
18
18
|
const APPHOSTING_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/apphosting/apphosting.yaml");
|
|
19
|
-
async function doSetup(setup, config) {
|
|
19
|
+
async function doSetup(setup, config, options) {
|
|
20
|
+
const { dynamicImport } = eval("require")("../../dynamicImport");
|
|
20
21
|
const projectId = setup.projectId;
|
|
21
22
|
if (!(await (0, cloudbilling_1.isBillingEnabled)(setup))) {
|
|
22
23
|
throw new error_1.FirebaseError(`Firebase App Hosting requires billing to be enabled on your project. To upgrade, visit the following URL: https://console.firebase.google.com/project/${projectId}/usage/details`);
|
|
@@ -51,8 +52,16 @@ async function doSetup(setup, config) {
|
|
|
51
52
|
if (!webApp) {
|
|
52
53
|
utils.logWarning(`Firebase web app not set`);
|
|
53
54
|
}
|
|
55
|
+
const experiments = await dynamicImport("./experiments");
|
|
56
|
+
const prompts = await dynamicImport("./apphosting/prompts");
|
|
57
|
+
let runtime = experiments.isEnabled("abiu") ? prompts.DEFAULT_RUNTIME : undefined;
|
|
58
|
+
let automaticBaseImageUpdatesDisabled = experiments.isEnabled("abiu") ? false : undefined;
|
|
59
|
+
if (experiments.isEnabled("abiu") && !options.nonInteractive) {
|
|
60
|
+
runtime = await prompts.promptRuntime(projectId, location);
|
|
61
|
+
automaticBaseImageUpdatesDisabled = !(await prompts.promptAutomaticBaseImageUpdates());
|
|
62
|
+
}
|
|
54
63
|
const createBackendSpinner = ora("Creating your new backend...").start();
|
|
55
|
-
const backend = await (0, backend_1.createBackend)(projectId, location, backendId, null, undefined, webApp?.id);
|
|
64
|
+
const backend = await (0, backend_1.createBackend)(projectId, location, backendId, null, undefined, webApp?.id, "/", runtime, automaticBaseImageUpdatesDisabled);
|
|
56
65
|
createBackendSpinner.succeed(`Successfully created backend!\n\t${backend.name}\n`);
|
|
57
66
|
}
|
|
58
67
|
(0, utils_1.logBullet)(`${clc.yellow("===")} Deploy local source setup`);
|