@builder.io/ai-utils 0.74.0 → 0.74.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.74.0",
3
+ "version": "0.74.1",
4
4
  "description": "Builder.io AI utils",
5
5
  "files": [
6
6
  "src"
@@ -18,11 +18,36 @@ export declare const BuilderConfigDatabaseSchema: z.ZodObject<{
18
18
  schemaDir: z.ZodDefault<z.ZodString>;
19
19
  }, z.core.$strip>;
20
20
  export type BuilderConfigDatabase = z.infer<typeof BuilderConfigDatabaseSchema>;
21
+ /** `hosting` block in `builder.config.json` — see First Class Hosting spec. */
22
+ export declare const BuilderConfigHostingEnvironmentSchema: z.ZodObject<{
23
+ build: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
24
+ prod: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
25
+ }, z.core.$strip>;
26
+ export type BuilderConfigHostingEnvironment = z.infer<typeof BuilderConfigHostingEnvironmentSchema>;
27
+ export declare const BuilderConfigHostingSchema: z.ZodObject<{
28
+ buildCommand: z.ZodOptional<z.ZodString>;
29
+ nodeVersion: z.ZodOptional<z.ZodString>;
30
+ buildOutputDir: z.ZodOptional<z.ZodString>;
31
+ environment: z.ZodOptional<z.ZodObject<{
32
+ build: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
33
+ prod: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
34
+ }, z.core.$strip>>;
35
+ }, z.core.$strip>;
36
+ export type BuilderConfigHosting = z.infer<typeof BuilderConfigHostingSchema>;
21
37
  export declare const BuilderConfigSchema: z.ZodObject<{
22
38
  database: z.ZodOptional<z.ZodObject<{
23
39
  kind: z.ZodLiteral<"postgres">;
24
40
  migrations: z.ZodLiteral<"drizzle">;
25
41
  schemaDir: z.ZodDefault<z.ZodString>;
26
42
  }, z.core.$strip>>;
43
+ hosting: z.ZodOptional<z.ZodObject<{
44
+ buildCommand: z.ZodOptional<z.ZodString>;
45
+ nodeVersion: z.ZodOptional<z.ZodString>;
46
+ buildOutputDir: z.ZodOptional<z.ZodString>;
47
+ environment: z.ZodOptional<z.ZodObject<{
48
+ build: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
49
+ prod: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
50
+ }, z.core.$strip>>;
51
+ }, z.core.$strip>>;
27
52
  }, z.core.$strip>;
28
53
  export type BuilderConfig = z.infer<typeof BuilderConfigSchema>;
@@ -17,6 +17,18 @@ export const BuilderConfigDatabaseSchema = z.object({
17
17
  migrations: z.literal("drizzle"),
18
18
  schemaDir: z.string().default("drizzle"),
19
19
  });
20
+ /** `hosting` block in `builder.config.json` — see First Class Hosting spec. */
21
+ export const BuilderConfigHostingEnvironmentSchema = z.object({
22
+ build: z.record(z.string(), z.string()).optional(),
23
+ prod: z.record(z.string(), z.string()).optional(),
24
+ });
25
+ export const BuilderConfigHostingSchema = z.object({
26
+ buildCommand: z.string().optional(),
27
+ nodeVersion: z.string().optional(),
28
+ buildOutputDir: z.string().optional(),
29
+ environment: BuilderConfigHostingEnvironmentSchema.optional(),
30
+ });
20
31
  export const BuilderConfigSchema = z.object({
21
32
  database: BuilderConfigDatabaseSchema.optional(),
33
+ hosting: BuilderConfigHostingSchema.optional(),
22
34
  });
package/src/codegen.d.ts CHANGED
@@ -4099,6 +4099,8 @@ export interface FusionConfig {
4099
4099
  checkCommand?: string;
4100
4100
  setupCommand?: string;
4101
4101
  validateCommand?: string;
4102
+ /** Production build command for hosting deploy pods (default: npm run build). */
4103
+ buildCommand?: string;
4102
4104
  fusionServerPort?: number;
4103
4105
  autoPush?: AutoPushMode;
4104
4106
  lockFile?: {
@@ -4584,6 +4586,22 @@ export interface ValidateCommandResultFailure {
4584
4586
  code: number | null;
4585
4587
  output: string;
4586
4588
  }
4589
+ export type BuildCommandState = ValidateCommandState;
4590
+ export type BuildCommandResult = BuildCommandResultSuccess | BuildCommandResultAborted | BuildCommandResultFailure;
4591
+ export interface BuildCommandResultSuccess {
4592
+ status: "success";
4593
+ command: string;
4594
+ }
4595
+ export interface BuildCommandResultAborted {
4596
+ status: "aborted";
4597
+ command: string | undefined;
4598
+ }
4599
+ export interface BuildCommandResultFailure {
4600
+ status: "failure";
4601
+ command: string;
4602
+ code?: number;
4603
+ output: string;
4604
+ }
4587
4605
  export interface ConfigureDevOrchestratorUpdates {
4588
4606
  devCommand: boolean;
4589
4607
  setupCommand: boolean;
package/src/events.d.ts CHANGED
@@ -1221,7 +1221,41 @@ export declare const ClientDevtoolsToolResultV1: {
1221
1221
  eventName: "client.devtools.tool.result";
1222
1222
  version: "1";
1223
1223
  };
1224
- export type FusionEvent = ClientDevtoolsSessionStartedEvent | ClientDevtoolsSessionIdleEventV1 | ClientDevtoolsToolCallRequestV1 | ClientDevtoolsToolCallV1 | ClientDevtoolsToolResultV1 | FusionProjectCreatedV1 | SetupAgentCompletedV1 | GitPrMergedV1 | GitPrCreatedV1 | GitPrClosedV1 | ForceSetupAgentV1 | ClawMessageSentV1 | CodegenCompletionV1 | CodegenUserPromptV1 | GitWebhooksRegisterV1 | FusionProjectSettingsUpdatedV1 | VideoRecordingCompletedV1 | TimelineRecordingReadyV1 | FusionBranchCreatedV1 | FusionContainerStartedV1 | FusionContainerFailedV1 | FusionBranchFailedV1 | BotMentionGitHubExternalPrV1 | BotMentionGitHubInternalPrV1 | BotMentionGitLabPrV1 | BotMentionBitbucketPrV1 | BotMentionAzurePrV1 | ReviewSubmittedV1 | PrReviewRequestedV1 | FigmaDecodeJobV1 | ProjectSnapshotRefreshV1 | ProjectSnapshotCapturedV1 | ProjectSnapshotCreatedV1 | ProjectSnapshotFailedV1 | ProjectSnapshotReadyCheckV1 | ProjectSnapshotPodWatchV1;
1224
+ export type ClientDevtoolsBuildCompletedV1 = FusionEventVariant<"client.devtools.build.completed", {
1225
+ deployId: string;
1226
+ projectId: string;
1227
+ }, {
1228
+ projectId: string;
1229
+ deployId: string;
1230
+ }, 1>;
1231
+ export declare const ClientDevtoolsBuildCompletedV1: {
1232
+ eventName: "client.devtools.build.completed";
1233
+ version: "1";
1234
+ };
1235
+ export type ClientDevtoolsBuildUploadedV1 = FusionEventVariant<"client.devtools.build.uploaded", {
1236
+ deployId: string;
1237
+ projectId: string;
1238
+ }, {
1239
+ projectId: string;
1240
+ deployId: string;
1241
+ }, 1>;
1242
+ export declare const ClientDevtoolsBuildUploadedV1: {
1243
+ eventName: "client.devtools.build.uploaded";
1244
+ version: "1";
1245
+ };
1246
+ export type ClientDevtoolsBuildFailedV1 = FusionEventVariant<"client.devtools.build.failed", {
1247
+ deployId: string;
1248
+ projectId: string;
1249
+ error: string;
1250
+ }, {
1251
+ projectId: string;
1252
+ deployId: string;
1253
+ }, 1>;
1254
+ export declare const ClientDevtoolsBuildFailedV1: {
1255
+ eventName: "client.devtools.build.failed";
1256
+ version: "1";
1257
+ };
1258
+ export type FusionEvent = ClientDevtoolsSessionStartedEvent | ClientDevtoolsSessionIdleEventV1 | ClientDevtoolsToolCallRequestV1 | ClientDevtoolsToolCallV1 | ClientDevtoolsToolResultV1 | ClientDevtoolsBuildCompletedV1 | ClientDevtoolsBuildUploadedV1 | ClientDevtoolsBuildFailedV1 | FusionProjectCreatedV1 | SetupAgentCompletedV1 | GitPrMergedV1 | GitPrCreatedV1 | GitPrClosedV1 | ForceSetupAgentV1 | ClawMessageSentV1 | CodegenCompletionV1 | CodegenUserPromptV1 | GitWebhooksRegisterV1 | FusionProjectSettingsUpdatedV1 | VideoRecordingCompletedV1 | TimelineRecordingReadyV1 | FusionBranchCreatedV1 | FusionContainerStartedV1 | FusionContainerFailedV1 | FusionBranchFailedV1 | BotMentionGitHubExternalPrV1 | BotMentionGitHubInternalPrV1 | BotMentionGitLabPrV1 | BotMentionBitbucketPrV1 | BotMentionAzurePrV1 | ReviewSubmittedV1 | PrReviewRequestedV1 | FigmaDecodeJobV1 | ProjectSnapshotRefreshV1 | ProjectSnapshotCapturedV1 | ProjectSnapshotCreatedV1 | ProjectSnapshotFailedV1 | ProjectSnapshotReadyCheckV1 | ProjectSnapshotPodWatchV1;
1225
1259
  export interface ModelPermissionRequiredEvent {
1226
1260
  type: "assistant.model.permission.required";
1227
1261
  data: {
package/src/events.js CHANGED
@@ -142,3 +142,15 @@ export const ClientDevtoolsToolResultV1 = {
142
142
  eventName: "client.devtools.tool.result",
143
143
  version: "1",
144
144
  };
145
+ export const ClientDevtoolsBuildCompletedV1 = {
146
+ eventName: "client.devtools.build.completed",
147
+ version: "1",
148
+ };
149
+ export const ClientDevtoolsBuildUploadedV1 = {
150
+ eventName: "client.devtools.build.uploaded",
151
+ version: "1",
152
+ };
153
+ export const ClientDevtoolsBuildFailedV1 = {
154
+ eventName: "client.devtools.build.failed",
155
+ version: "1",
156
+ };
package/src/projects.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import type { BuilderConfigHosting } from "./builder-config.js";
2
3
  import type { ConnectivityErrorCode, CheckType, LikelyCause } from "./connectivity/types.js";
3
4
  import { type EnvironmentVariable, type SetupDependency } from "./common-schemas";
4
5
  import type { FileOverride, LaunchServerState, LaunchServerStatus, BranchBackup, CommitMode, CustomInstruction, CustomAgentDefinition, GitSnapshot, AutoPushMode, GenerateUserMessage, CodeGenToolMap, GenerateCompletionStep, ReviewEffort } from "./codegen";
@@ -1294,8 +1295,11 @@ export declare const DeployStatusSchema: z.ZodEnum<{
1294
1295
  uploading: "uploading";
1295
1296
  }>;
1296
1297
  export type DeployStatus = z.infer<typeof DeployStatusSchema>;
1298
+ /** Deploy statuses that are terminal — never transitioned out of. */
1299
+ export declare const TERMINAL_DEPLOY_STATUSES: Set<"building" | "canceled" | "deploying" | "failed" | "live" | "queued" | "uploading">;
1297
1300
  export declare const ProjectHostingBuildConfigSchema: z.ZodObject<{
1298
1301
  buildCommand: z.ZodOptional<z.ZodString>;
1302
+ buildOutputDir: z.ZodOptional<z.ZodString>;
1299
1303
  nodeVersion: z.ZodOptional<z.ZodString>;
1300
1304
  }, z.core.$strip>;
1301
1305
  export type ProjectHostingBuildConfig = z.infer<typeof ProjectHostingBuildConfigSchema>;
@@ -1310,6 +1314,7 @@ export declare const ProjectHostingSchema: z.ZodObject<{
1310
1314
  url: z.ZodOptional<z.ZodString>;
1311
1315
  buildConfig: z.ZodOptional<z.ZodObject<{
1312
1316
  buildCommand: z.ZodOptional<z.ZodString>;
1317
+ buildOutputDir: z.ZodOptional<z.ZodString>;
1313
1318
  nodeVersion: z.ZodOptional<z.ZodString>;
1314
1319
  }, z.core.$strip>>;
1315
1320
  environment: z.ZodOptional<z.ZodObject<{
@@ -1353,6 +1358,7 @@ export declare const DeploySchema: z.ZodObject<{
1353
1358
  ownerId: z.ZodString;
1354
1359
  checkoutBranch: z.ZodOptional<z.ZodString>;
1355
1360
  deployBranchId: z.ZodOptional<z.ZodString>;
1361
+ deployBranchName: z.ZodOptional<z.ZodString>;
1356
1362
  devBranchId: z.ZodOptional<z.ZodString>;
1357
1363
  status: z.ZodEnum<{
1358
1364
  building: "building";
@@ -1445,4 +1451,142 @@ export declare const DeployArtifactManifestSchema: z.ZodObject<{
1445
1451
  functions: z.ZodRecord<z.ZodString, z.ZodString>;
1446
1452
  }, z.core.$strip>;
1447
1453
  export type DeployArtifactManifest = z.infer<typeof DeployArtifactManifestSchema>;
1454
+ /**
1455
+ * Per-deploy overrides passed from ai-services to the deploy pod's build-and-upload endpoint.
1456
+ */
1457
+ export declare const BuildConfigOverridesSchema: z.ZodObject<{
1458
+ buildCommand: z.ZodOptional<z.ZodString>;
1459
+ buildOutputDir: z.ZodOptional<z.ZodString>;
1460
+ nodeVersion: z.ZodOptional<z.ZodString>;
1461
+ environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1462
+ }, z.core.$strip>;
1463
+ export type BuildConfigOverrides = z.infer<typeof BuildConfigOverridesSchema>;
1464
+ /** Map a repo `builder.config.json` hosting block to deploy-pod overrides (build scope only). */
1465
+ export declare function builderConfigHostingToBuildOverrides(hosting: BuilderConfigHosting | undefined): BuildConfigOverrides;
1466
+ /**
1467
+ * Merge repo file config with Firestore/UI overrides. Firestore wins on key conflicts.
1468
+ */
1469
+ export declare function mergeBuildConfigOverrides(fromFile: BuildConfigOverrides, fromFirestore: BuildConfigOverrides | undefined): BuildConfigOverrides;
1470
+ /** True when merged hosting build config includes at least one build setting. */
1471
+ export declare function hasResolvableHostingBuildConfig(overrides?: BuildConfigOverrides): boolean;
1472
+ /**
1473
+ * Request body for `POST /_builder.io/api/build-and-upload` on the deploy pod.
1474
+ */
1475
+ export declare const BuildAndUploadRequestSchema: z.ZodObject<{
1476
+ projectId: z.ZodString;
1477
+ deployId: z.ZodString;
1478
+ gcsManifestUploadUrl: z.ZodString;
1479
+ gcsArtifactUploadUrl: z.ZodString;
1480
+ buildConfigOverrides: z.ZodOptional<z.ZodObject<{
1481
+ buildCommand: z.ZodOptional<z.ZodString>;
1482
+ buildOutputDir: z.ZodOptional<z.ZodString>;
1483
+ nodeVersion: z.ZodOptional<z.ZodString>;
1484
+ environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1485
+ }, z.core.$strip>>;
1486
+ }, z.core.$strip>;
1487
+ export type BuildAndUploadRequest = z.infer<typeof BuildAndUploadRequestSchema>;
1488
+ export declare const ReserveSlugRequestSchema: z.ZodObject<{
1489
+ projectId: z.ZodString;
1490
+ slug: z.ZodString;
1491
+ }, z.core.$strip>;
1492
+ export type ReserveSlugRequest = z.infer<typeof ReserveSlugRequestSchema>;
1493
+ export declare const ReserveSlugResponseSchema: z.ZodObject<{
1494
+ slug: z.ZodString;
1495
+ }, z.core.$strip>;
1496
+ export type ReserveSlugResponse = z.infer<typeof ReserveSlugResponseSchema>;
1497
+ export declare const DeployRequestSchema: z.ZodObject<{
1498
+ projectId: z.ZodString;
1499
+ checkoutBranch: z.ZodOptional<z.ZodString>;
1500
+ }, z.core.$strip>;
1501
+ export type DeployRequest = z.infer<typeof DeployRequestSchema>;
1502
+ export declare const DeployResponseSchema: z.ZodObject<{
1503
+ deployId: z.ZodString;
1504
+ status: z.ZodEnum<{
1505
+ building: "building";
1506
+ canceled: "canceled";
1507
+ deploying: "deploying";
1508
+ failed: "failed";
1509
+ live: "live";
1510
+ queued: "queued";
1511
+ uploading: "uploading";
1512
+ }>;
1513
+ }, z.core.$strip>;
1514
+ export type DeployResponse = z.infer<typeof DeployResponseSchema>;
1515
+ export declare const GetDeploysRequestSchema: z.ZodObject<{
1516
+ projectId: z.ZodString;
1517
+ deployId: z.ZodOptional<z.ZodString>;
1518
+ }, z.core.$strip>;
1519
+ export type GetDeploysRequest = z.infer<typeof GetDeploysRequestSchema>;
1520
+ export declare const GetDeploysResponseSchema: z.ZodObject<{
1521
+ deploys: z.ZodArray<z.ZodObject<{
1522
+ id: z.ZodString;
1523
+ status: z.ZodEnum<{
1524
+ building: "building";
1525
+ canceled: "canceled";
1526
+ deploying: "deploying";
1527
+ failed: "failed";
1528
+ live: "live";
1529
+ queued: "queued";
1530
+ uploading: "uploading";
1531
+ }>;
1532
+ url: z.ZodOptional<z.ZodString>;
1533
+ error: z.ZodOptional<z.ZodString>;
1534
+ createdAt: z.ZodNumber;
1535
+ completedAt: z.ZodOptional<z.ZodNumber>;
1536
+ }, z.core.$strip>>;
1537
+ }, z.core.$strip>;
1538
+ export type GetDeploysResponse = z.infer<typeof GetDeploysResponseSchema>;
1539
+ export declare const UpdateHostingRequestSchema: z.ZodObject<{
1540
+ projectId: z.ZodString;
1541
+ customDomain: z.ZodOptional<z.ZodString>;
1542
+ buildCommand: z.ZodOptional<z.ZodString>;
1543
+ autoDeploy: z.ZodOptional<z.ZodBoolean>;
1544
+ environment: z.ZodOptional<z.ZodObject<{
1545
+ build: z.ZodOptional<z.ZodArray<z.ZodObject<{
1546
+ key: z.ZodString;
1547
+ value: z.ZodString;
1548
+ isSecret: z.ZodBoolean;
1549
+ placeholder: z.ZodOptional<z.ZodBoolean>;
1550
+ explanation: z.ZodOptional<z.ZodString>;
1551
+ }, z.core.$strip>>>;
1552
+ prod: z.ZodOptional<z.ZodArray<z.ZodObject<{
1553
+ key: z.ZodString;
1554
+ value: z.ZodString;
1555
+ isSecret: z.ZodBoolean;
1556
+ placeholder: z.ZodOptional<z.ZodBoolean>;
1557
+ explanation: z.ZodOptional<z.ZodString>;
1558
+ }, z.core.$strip>>>;
1559
+ }, z.core.$strip>>;
1560
+ deleteEnvironmentVariableKeys: z.ZodOptional<z.ZodObject<{
1561
+ build: z.ZodOptional<z.ZodArray<z.ZodString>>;
1562
+ prod: z.ZodOptional<z.ZodArray<z.ZodString>>;
1563
+ }, z.core.$strip>>;
1564
+ }, z.core.$strip>;
1565
+ export type UpdateHostingRequest = z.infer<typeof UpdateHostingRequestSchema>;
1566
+ export declare const UpdateHostingResponseSchema: z.ZodObject<{
1567
+ slug: z.ZodOptional<z.ZodString>;
1568
+ customDomain: z.ZodOptional<z.ZodString>;
1569
+ buildConfig: z.ZodOptional<z.ZodObject<{
1570
+ buildCommand: z.ZodOptional<z.ZodString>;
1571
+ buildOutputDir: z.ZodOptional<z.ZodString>;
1572
+ nodeVersion: z.ZodOptional<z.ZodString>;
1573
+ }, z.core.$strip>>;
1574
+ environment: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1575
+ build: z.ZodOptional<z.ZodArray<z.ZodObject<{
1576
+ key: z.ZodString;
1577
+ value: z.ZodString;
1578
+ isSecret: z.ZodBoolean;
1579
+ placeholder: z.ZodOptional<z.ZodBoolean>;
1580
+ explanation: z.ZodOptional<z.ZodString>;
1581
+ }, z.core.$strip>>>;
1582
+ prod: z.ZodOptional<z.ZodArray<z.ZodObject<{
1583
+ key: z.ZodString;
1584
+ value: z.ZodString;
1585
+ isSecret: z.ZodBoolean;
1586
+ placeholder: z.ZodOptional<z.ZodBoolean>;
1587
+ explanation: z.ZodOptional<z.ZodString>;
1588
+ }, z.core.$strip>>>;
1589
+ }, z.core.$strip>>>;
1590
+ }, z.core.$strip>;
1591
+ export type UpdateHostingResponse = z.infer<typeof UpdateHostingResponseSchema>;
1448
1592
  export {};
package/src/projects.js CHANGED
@@ -200,8 +200,15 @@ export const DeployStatusSchema = z.enum([
200
200
  "failed",
201
201
  "canceled",
202
202
  ]);
203
+ /** Deploy statuses that are terminal — never transitioned out of. */
204
+ export const TERMINAL_DEPLOY_STATUSES = new Set([
205
+ "live",
206
+ "failed",
207
+ "canceled",
208
+ ]);
203
209
  export const ProjectHostingBuildConfigSchema = z.object({
204
210
  buildCommand: z.string().optional(),
211
+ buildOutputDir: z.string().optional(),
205
212
  nodeVersion: z.string().optional(),
206
213
  });
207
214
  /**
@@ -271,6 +278,9 @@ export const DeploySchema = z.object({
271
278
  deployBranchId: z.string().optional().meta({
272
279
  description: 'Fusion branch id of the ephemeral hidden deploy branch (`type: "deploy"`) that ran the build.',
273
280
  }),
281
+ deployBranchName: z.string().optional().meta({
282
+ description: 'Fusion branch name of the ephemeral hidden deploy branch (`type: "deploy"`) that ran the build.',
283
+ }),
274
284
  devBranchId: z.string().optional().meta({
275
285
  description: "Fusion dev branch's id (unset if we are deploying project default branch)",
276
286
  }),
@@ -357,3 +367,153 @@ export const DeployArtifactManifestSchema = z.object({
357
367
  description: "serverless function name → sha256 hash",
358
368
  }),
359
369
  });
370
+ /**
371
+ * Per-deploy overrides passed from ai-services to the deploy pod's build-and-upload endpoint.
372
+ */
373
+ export const BuildConfigOverridesSchema = z.object({
374
+ buildCommand: z.string().optional(),
375
+ buildOutputDir: z.string().optional(),
376
+ nodeVersion: z.string().optional(),
377
+ /**
378
+ * Flat key-value map for the deploy pod. Firestore/API layers store
379
+ * `EnvironmentVariable[]`; convert at the boundary before building overrides.
380
+ */
381
+ environment: z.record(z.string(), z.string()).optional(),
382
+ });
383
+ function trimOptionalString(value) {
384
+ if (value === undefined) {
385
+ return undefined;
386
+ }
387
+ const trimmed = value.trim();
388
+ return trimmed || undefined;
389
+ }
390
+ /** Pick a string override: Firestore wins when the key is present (including ""). */
391
+ function pickBuildConfigString(firestore, file) {
392
+ if (firestore !== undefined) {
393
+ return trimOptionalString(firestore);
394
+ }
395
+ return trimOptionalString(file);
396
+ }
397
+ /** Map a repo `builder.config.json` hosting block to deploy-pod overrides (build scope only). */
398
+ export function builderConfigHostingToBuildOverrides(hosting) {
399
+ var _a;
400
+ if (!hosting) {
401
+ return {};
402
+ }
403
+ const buildEnv = (_a = hosting.environment) === null || _a === void 0 ? void 0 : _a.build;
404
+ const buildCommand = trimOptionalString(hosting.buildCommand);
405
+ const buildOutputDir = trimOptionalString(hosting.buildOutputDir);
406
+ const nodeVersion = trimOptionalString(hosting.nodeVersion);
407
+ return {
408
+ ...(buildCommand ? { buildCommand } : {}),
409
+ ...(buildOutputDir ? { buildOutputDir } : {}),
410
+ ...(nodeVersion ? { nodeVersion } : {}),
411
+ ...(buildEnv && Object.keys(buildEnv).length > 0
412
+ ? { environment: buildEnv }
413
+ : {}),
414
+ };
415
+ }
416
+ /**
417
+ * Merge repo file config with Firestore/UI overrides. Firestore wins on key conflicts.
418
+ */
419
+ export function mergeBuildConfigOverrides(fromFile, fromFirestore) {
420
+ const firestore = fromFirestore !== null && fromFirestore !== void 0 ? fromFirestore : {};
421
+ const merged = {};
422
+ const buildCommand = pickBuildConfigString(firestore.buildCommand, fromFile.buildCommand);
423
+ if (buildCommand) {
424
+ merged.buildCommand = buildCommand;
425
+ }
426
+ const buildOutputDir = pickBuildConfigString(firestore.buildOutputDir, fromFile.buildOutputDir);
427
+ if (buildOutputDir) {
428
+ merged.buildOutputDir = buildOutputDir;
429
+ }
430
+ const nodeVersion = pickBuildConfigString(firestore.nodeVersion, fromFile.nodeVersion);
431
+ if (nodeVersion) {
432
+ merged.nodeVersion = nodeVersion;
433
+ }
434
+ const fileEnv = fromFile.environment;
435
+ const firestoreEnv = firestore.environment;
436
+ if (fileEnv !== undefined || firestoreEnv !== undefined) {
437
+ const environment = { ...fileEnv, ...firestoreEnv };
438
+ if (Object.keys(environment).length > 0) {
439
+ merged.environment = environment;
440
+ }
441
+ }
442
+ return merged;
443
+ }
444
+ /** True when merged hosting build config includes at least one build setting. */
445
+ export function hasResolvableHostingBuildConfig(overrides) {
446
+ var _a, _b, _c;
447
+ if (!overrides) {
448
+ return false;
449
+ }
450
+ if ((_a = overrides.buildCommand) === null || _a === void 0 ? void 0 : _a.trim()) {
451
+ return true;
452
+ }
453
+ if ((_b = overrides.buildOutputDir) === null || _b === void 0 ? void 0 : _b.trim()) {
454
+ return true;
455
+ }
456
+ if ((_c = overrides.nodeVersion) === null || _c === void 0 ? void 0 : _c.trim()) {
457
+ return true;
458
+ }
459
+ if (overrides.environment && Object.keys(overrides.environment).length > 0) {
460
+ return true;
461
+ }
462
+ return false;
463
+ }
464
+ /**
465
+ * Request body for `POST /_builder.io/api/build-and-upload` on the deploy pod.
466
+ */
467
+ export const BuildAndUploadRequestSchema = z.object({
468
+ projectId: z.string(),
469
+ deployId: z.string(),
470
+ gcsManifestUploadUrl: z.string().url(),
471
+ gcsArtifactUploadUrl: z.string().url(),
472
+ buildConfigOverrides: BuildConfigOverridesSchema.optional(),
473
+ });
474
+ export const ReserveSlugRequestSchema = z.object({
475
+ projectId: z.string(),
476
+ slug: z.string(),
477
+ });
478
+ export const ReserveSlugResponseSchema = z.object({
479
+ slug: z.string(),
480
+ });
481
+ export const DeployRequestSchema = z.object({
482
+ projectId: z.string(),
483
+ checkoutBranch: z.string().optional(),
484
+ });
485
+ export const DeployResponseSchema = z.object({
486
+ deployId: z.string(),
487
+ status: DeployStatusSchema,
488
+ });
489
+ export const GetDeploysRequestSchema = z.object({
490
+ projectId: z.string(),
491
+ deployId: z.string().optional(),
492
+ });
493
+ export const GetDeploysResponseSchema = z.object({
494
+ deploys: z.array(DeployListItemSchema),
495
+ });
496
+ export const UpdateHostingRequestSchema = z.object({
497
+ projectId: z.string(),
498
+ customDomain: z.string().optional(),
499
+ buildCommand: z.string().optional(),
500
+ autoDeploy: z.boolean().optional(),
501
+ environment: z
502
+ .object({
503
+ build: z.array(EnvironmentVariableSchema).optional(),
504
+ prod: z.array(EnvironmentVariableSchema).optional(),
505
+ })
506
+ .optional(),
507
+ deleteEnvironmentVariableKeys: z
508
+ .object({
509
+ build: z.array(z.string()).optional(),
510
+ prod: z.array(z.string()).optional(),
511
+ })
512
+ .optional(),
513
+ });
514
+ export const UpdateHostingResponseSchema = z.object({
515
+ slug: z.string().optional(),
516
+ customDomain: z.string().optional(),
517
+ buildConfig: ProjectHostingBuildConfigSchema.optional(),
518
+ environment: ProjectHostingSchema.shape.environment.optional(),
519
+ });