@builder.io/ai-utils 0.85.3 → 0.86.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.85.3",
3
+ "version": "0.86.1",
4
4
  "description": "Builder.io AI utils",
5
5
  "files": [
6
6
  "src"
package/src/codegen.d.ts CHANGED
@@ -2911,7 +2911,7 @@ export type CodeGenInputOptions = z.infer<typeof CodeGenInputOptionsSchema> & {
2911
2911
  */
2912
2912
  _mcpClientWrapperFactory?: (realClient: any) => any;
2913
2913
  };
2914
- export type CodeGenErrorCodes = "credits-limit-daily" | "credits-limit-monthly" | "credits-limit-user" | "credits-limit-other" | "cli-genetic-error" | "git-update-error" | "prompt-too-long" | "context-too-long" | "abrupt-end" | "unknown" | "failed-recover-state" | "completion-expired" | "ask-to-continue" | "bad-initial-url" | "bad-smart-export-payload" | "invalid-last-message" | "corrupted-session" | "privacy-mode-key-required" | "privacy-mode-key-invalid" | "privacy-mode-key-mismatch" | "cli-network-error" | "invalid-credentials" | "model-restricted-too-large" | "org-no-models-enabled" | "assertion" | "rate-limit" | "unknown-design-system";
2914
+ export type CodeGenErrorCodes = "credits-limit-daily" | "credits-limit-monthly" | "credits-limit-user" | "credits-limit-other" | "cli-genetic-error" | "git-update-error" | "prompt-too-long" | "context-too-long" | "abrupt-end" | "unknown" | "failed-recover-state" | "completion-expired" | "ask-to-continue" | "bad-initial-url" | "bad-smart-export-payload" | "invalid-last-message" | "corrupted-session" | "privacy-mode-key-required" | "privacy-mode-key-invalid" | "privacy-mode-key-mismatch" | "privacy-mode-validation-unavailable" | "cli-network-error" | "invalid-credentials" | "model-restricted-too-large" | "org-no-models-enabled" | "assertion" | "rate-limit" | "unknown-design-system";
2915
2915
  export interface CodegenUsage {
2916
2916
  total: number;
2917
2917
  fast: number;
@@ -3845,6 +3845,30 @@ export interface GenerateCodeEventError {
3845
3845
  message: string;
3846
3846
  usage?: CodegenUsage;
3847
3847
  }
3848
+ /**
3849
+ * Wire schema for the pre-stream error protocol on `/codegen/completion`:
3850
+ * middlewares that reject a request before the stream starts (credit limits,
3851
+ * privacy mode) respond with an error status whose body is a single
3852
+ * {@link GenerateCodeEventError} JSONL line. Loose so servers can attach
3853
+ * extra fields (e.g. `usageInfo`), and `code` stays an open string so newer
3854
+ * server codes pass through older clients.
3855
+ */
3856
+ export declare const GenerateCodeEventErrorBodySchema: z.ZodObject<{
3857
+ type: z.ZodLiteral<"error">;
3858
+ stopReason: z.ZodEnum<{
3859
+ error: "error";
3860
+ limit: "limit";
3861
+ }>;
3862
+ code: z.ZodString;
3863
+ id: z.ZodString;
3864
+ message: z.ZodString;
3865
+ }, z.core.$loose>;
3866
+ /**
3867
+ * Decode a non-OK `/codegen/completion` response body as a structured error
3868
+ * event. Returns undefined for anything else (auth failures, proxy errors,
3869
+ * plain-text bodies), letting transport-level status handling take over.
3870
+ */
3871
+ export declare function parseGenerateCodeEventErrorBody(body: string): GenerateCodeEventError | undefined;
3848
3872
  export interface GenerateCodeEventPagination {
3849
3873
  type: "pagination";
3850
3874
  pop: number;
package/src/codegen.js CHANGED
@@ -2017,6 +2017,37 @@ export const CodegenSettingsRequestSchema = z
2017
2017
  repoHash: z.string().optional(),
2018
2018
  })
2019
2019
  .meta({ title: "CodegenSettingsRequest" });
2020
+ /**
2021
+ * Wire schema for the pre-stream error protocol on `/codegen/completion`:
2022
+ * middlewares that reject a request before the stream starts (credit limits,
2023
+ * privacy mode) respond with an error status whose body is a single
2024
+ * {@link GenerateCodeEventError} JSONL line. Loose so servers can attach
2025
+ * extra fields (e.g. `usageInfo`), and `code` stays an open string so newer
2026
+ * server codes pass through older clients.
2027
+ */
2028
+ export const GenerateCodeEventErrorBodySchema = z.looseObject({
2029
+ type: z.literal("error"),
2030
+ stopReason: z.enum(["error", "limit"]),
2031
+ code: z.string(),
2032
+ id: z.string(),
2033
+ message: z.string(),
2034
+ });
2035
+ /**
2036
+ * Decode a non-OK `/codegen/completion` response body as a structured error
2037
+ * event. Returns undefined for anything else (auth failures, proxy errors,
2038
+ * plain-text bodies), letting transport-level status handling take over.
2039
+ */
2040
+ export function parseGenerateCodeEventErrorBody(body) {
2041
+ try {
2042
+ const parsed = GenerateCodeEventErrorBodySchema.safeParse(JSON.parse(body.trim().split("\n")[0]));
2043
+ return parsed.success
2044
+ ? parsed.data
2045
+ : undefined;
2046
+ }
2047
+ catch (_a) {
2048
+ return undefined;
2049
+ }
2050
+ }
2020
2051
  /**
2021
2052
  * Request for generating a commit message via LLM
2022
2053
  */
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { DEFAULT_QUEUE_BEHAVIOR, isInterruptSchedule, normalizeQueueMode, } from "./codegen";
2
+ import { DEFAULT_QUEUE_BEHAVIOR, isInterruptSchedule, normalizeQueueMode, parseGenerateCodeEventErrorBody, } from "./codegen";
3
3
  describe("normalizeQueueMode", () => {
4
4
  it("returns the default behavior when input is undefined", () => {
5
5
  expect(normalizeQueueMode(undefined)).toEqual(DEFAULT_QUEUE_BEHAVIOR);
@@ -56,3 +56,38 @@ describe("isInterruptSchedule", () => {
56
56
  expect(isInterruptSchedule("until-idle")).toBe(false);
57
57
  });
58
58
  });
59
+ describe("parseGenerateCodeEventErrorBody", () => {
60
+ it("decodes a structured error-event body", () => {
61
+ const body = JSON.stringify({
62
+ type: "error",
63
+ stopReason: "error",
64
+ code: "privacy-mode-key-required",
65
+ id: "abc",
66
+ message: "no key",
67
+ }) + "\n";
68
+ expect(parseGenerateCodeEventErrorBody(body)).toMatchObject({
69
+ code: "privacy-mode-key-required",
70
+ message: "no key",
71
+ });
72
+ });
73
+ it("preserves extra fields like usageInfo and decodes only the first line", () => {
74
+ const body = JSON.stringify({
75
+ type: "error",
76
+ stopReason: "limit",
77
+ code: "credits-limit-monthly",
78
+ id: "abc",
79
+ message: "limit reached",
80
+ usageInfo: { plan: "free" },
81
+ }) + "\nnot-json-second-line";
82
+ expect(parseGenerateCodeEventErrorBody(body)).toMatchObject({
83
+ code: "credits-limit-monthly",
84
+ usageInfo: { plan: "free" },
85
+ });
86
+ });
87
+ it("returns undefined for non-event bodies", () => {
88
+ expect(parseGenerateCodeEventErrorBody("Forbidden")).toBeUndefined();
89
+ expect(parseGenerateCodeEventErrorBody('{"error":"invalid token"}')).toBeUndefined();
90
+ expect(parseGenerateCodeEventErrorBody(JSON.stringify({ type: "error", code: 42, message: "bad shape" }))).toBeUndefined();
91
+ expect(parseGenerateCodeEventErrorBody("")).toBeUndefined();
92
+ });
93
+ });
@@ -11,6 +11,22 @@ export interface FigmaHydrationResponse {
11
11
  manifest: import("./events.js").FigmaFrameManifest | null;
12
12
  files: FigmaHydrationFile[];
13
13
  }
14
+ export declare const figmaDecodeJobStatusParamsSchema: z.ZodObject<{
15
+ jobId: z.ZodString;
16
+ }, z.core.$strip>;
17
+ export type FigmaDecodeJobStatusParams = z.infer<typeof figmaDecodeJobStatusParamsSchema>;
18
+ export interface FigmaDecodeJobStatusResponse {
19
+ jobId: string;
20
+ status: "pending" | "processing" | "complete" | "error";
21
+ framesProcessed: number;
22
+ totalFrames: number;
23
+ branchName: string | null;
24
+ branchUrl: string | null;
25
+ error: string | null;
26
+ partialFailure?: boolean;
27
+ createdAt: number;
28
+ updatedAt: number;
29
+ }
14
30
  /**
15
31
  * Accepts `https://github.com/<owner>/<repo>` (optionally with a trailing
16
32
  * `.git` or path segments). Used to gate public-repo inputs before cloning.
@@ -1,4 +1,7 @@
1
1
  import { z } from "zod";
2
+ export const figmaDecodeJobStatusParamsSchema = z.object({
3
+ jobId: z.string().min(1),
4
+ });
2
5
  /**
3
6
  * Accepts `https://github.com/<owner>/<repo>` (optionally with a trailing
4
7
  * `.git` or path segments). Used to gate public-repo inputs before cloning.
package/src/events.d.ts CHANGED
@@ -1316,6 +1316,20 @@ export declare const HostingCustomDomainCertCheckV1: {
1316
1316
  eventName: "hosting.custom-domain.cert-check";
1317
1317
  version: "1";
1318
1318
  };
1319
+ export type HostingCustomDomainServingCheckV1 = FusionEventVariant<"hosting.custom-domain.serving-check", {
1320
+ domain: string;
1321
+ projectId: string;
1322
+ certId: string;
1323
+ attemptId: string;
1324
+ startedAtMs: number;
1325
+ timeoutMs: number;
1326
+ }, {
1327
+ projectId: string;
1328
+ }, 1>;
1329
+ export declare const HostingCustomDomainServingCheckV1: {
1330
+ eventName: "hosting.custom-domain.serving-check";
1331
+ version: "1";
1332
+ };
1319
1333
  export type HostingCustomDomainDelegationCheckV1 = FusionEventVariant<"hosting.custom-domain.delegation-check", {
1320
1334
  domain: string;
1321
1335
  projectId: string;
@@ -1329,7 +1343,7 @@ export declare const HostingCustomDomainDelegationCheckV1: {
1329
1343
  eventName: "hosting.custom-domain.delegation-check";
1330
1344
  version: "1";
1331
1345
  };
1332
- export type FusionEvent = ClientDevtoolsSessionStartedEvent | ClientDevtoolsSessionIdleEventV1 | ClientDevtoolsToolCallRequestV1 | ClientDevtoolsToolCallV1 | ClientDevtoolsToolResultV1 | ClientDevtoolsBuildMigratedV1 | 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 | McpPrototypePulledV1 | HostingCustomDomainCertCheckV1 | HostingCustomDomainDelegationCheckV1;
1346
+ export type FusionEvent = ClientDevtoolsSessionStartedEvent | ClientDevtoolsSessionIdleEventV1 | ClientDevtoolsToolCallRequestV1 | ClientDevtoolsToolCallV1 | ClientDevtoolsToolResultV1 | ClientDevtoolsBuildMigratedV1 | 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 | McpPrototypePulledV1 | HostingCustomDomainCertCheckV1 | HostingCustomDomainServingCheckV1 | HostingCustomDomainDelegationCheckV1;
1333
1347
  export interface ModelPermissionRequiredEvent {
1334
1348
  type: "assistant.model.permission.required";
1335
1349
  data: {
package/src/events.js CHANGED
@@ -166,6 +166,10 @@ export const HostingCustomDomainCertCheckV1 = {
166
166
  eventName: "hosting.custom-domain.cert-check",
167
167
  version: "1",
168
168
  };
169
+ export const HostingCustomDomainServingCheckV1 = {
170
+ eventName: "hosting.custom-domain.serving-check",
171
+ version: "1",
172
+ };
169
173
  export const HostingCustomDomainDelegationCheckV1 = {
170
174
  eventName: "hosting.custom-domain.delegation-check",
171
175
  version: "1",
package/src/projects.d.ts CHANGED
@@ -1888,6 +1888,9 @@ export declare const HostingDomainSchema: z.ZodObject<{
1888
1888
  dns: "dns";
1889
1889
  https: "https";
1890
1890
  }>>;
1891
+ routeError: z.ZodOptional<z.ZodString>;
1892
+ routeErrorAt: z.ZodOptional<z.ZodNumber>;
1893
+ servingConfirmedAt: z.ZodOptional<z.ZodNumber>;
1891
1894
  createdBy: z.ZodString;
1892
1895
  }, z.core.$strip>;
1893
1896
  export type HostingDomain = z.infer<typeof HostingDomainSchema>;
@@ -1946,6 +1949,22 @@ export declare const RemoveDomainResponseSchema: z.ZodObject<{
1946
1949
  success: z.ZodLiteral<true>;
1947
1950
  }, z.core.$strip>;
1948
1951
  export type RemoveDomainResponse = z.infer<typeof RemoveDomainResponseSchema>;
1952
+ export declare const RepairDomainRequestSchema: z.ZodObject<{
1953
+ projectId: z.ZodString;
1954
+ domain: z.ZodString;
1955
+ }, z.core.$strip>;
1956
+ export type RepairDomainRequest = z.infer<typeof RepairDomainRequestSchema>;
1957
+ export declare const RepairDomainResponseSchema: z.ZodObject<{
1958
+ status: z.ZodEnum<{
1959
+ active: "active";
1960
+ failed: "failed";
1961
+ pending: "pending";
1962
+ provisioning: "provisioning";
1963
+ verifying: "verifying";
1964
+ }>;
1965
+ routeError: z.ZodOptional<z.ZodString>;
1966
+ }, z.core.$strip>;
1967
+ export type RepairDomainResponse = z.infer<typeof RepairDomainResponseSchema>;
1949
1968
  export declare const CloneProjectOptionsSchema: z.ZodObject<{
1950
1969
  sourceProjectId: z.ZodString;
1951
1970
  sourceBranchName: z.ZodDefault<z.ZodString>;
package/src/projects.js CHANGED
@@ -842,6 +842,15 @@ export const HostingDomainSchema = z.object({
842
842
  failedStep: z.enum(["dns", "https"]).optional().meta({
843
843
  description: "Which setup step failed, set alongside `status: failed` so the UI can attribute the failure. `dns` = delegation verification, `https` = cert/route provisioning.",
844
844
  }),
845
+ routeError: z.string().optional().meta({
846
+ description: "Non-fatal health signal on an otherwise verified (`provisioning`/`active`) domain: set when re-creating the Envoy HTTPRoute failed on republish, so the site's cert is valid but the custom domain has no live route (bare 404). `status` stays `active`; this drives a degraded banner + Fix action. Cleared once the route is recreated.",
847
+ }),
848
+ routeErrorAt: z.number().optional().meta({
849
+ description: "When `routeError` was last set.",
850
+ }),
851
+ servingConfirmedAt: z.number().optional().meta({
852
+ description: "When the domain was confirmed serving over HTTPS: stamped by the serving-check loop once `https://<domain>/` answers over TLS through a Builder route (or by a healthy route recreate on deploy/repair). Definitive 'serving confirmed' signal for the UI's third setup step, distinct from cert issuance (`status: active`).",
853
+ }),
845
854
  createdBy: z.string(),
846
855
  });
847
856
  export const AddDomainRequestSchema = z.object({
@@ -875,6 +884,14 @@ export const RemoveDomainRequestSchema = z.object({
875
884
  export const RemoveDomainResponseSchema = z.object({
876
885
  success: z.literal(true),
877
886
  });
887
+ export const RepairDomainRequestSchema = z.object({
888
+ projectId: z.string(),
889
+ domain: z.string(),
890
+ });
891
+ export const RepairDomainResponseSchema = z.object({
892
+ status: HostingDomainStatusSchema,
893
+ routeError: z.string().optional(),
894
+ });
878
895
  export const CloneProjectOptionsSchema = z.object({
879
896
  sourceProjectId: z.string().min(1).meta({
880
897
  description: "Project to clone from.",