@builder.io/ai-utils 0.86.0 → 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.86.0",
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.