@builder.io/ai-utils 0.72.0 → 0.73.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.72.0",
3
+ "version": "0.73.0",
4
4
  "description": "Builder.io AI utils",
5
5
  "files": [
6
6
  "src"
package/src/codegen.d.ts CHANGED
@@ -3560,12 +3560,10 @@ export interface UserInput {
3560
3560
  /** @deprecated */
3561
3561
  repair?: boolean;
3562
3562
  }
3563
- export interface CodegenTurn {
3564
- state: "running" | "done" | "error";
3563
+ interface CodegenTurnBase {
3565
3564
  unixTime: number;
3566
3565
  completionId: string;
3567
3566
  title: string;
3568
- nextUrl: string | undefined;
3569
3567
  user: UserSource;
3570
3568
  creditsUsed: number;
3571
3569
  actions: ActionItem[];
@@ -3577,7 +3575,34 @@ export interface CodegenTurn {
3577
3575
  lastCommit: GitSnapshot | undefined;
3578
3576
  cachedToolResults?: ContentMessageItemToolResult[];
3579
3577
  autoContinue: boolean;
3578
+ /**
3579
+ * Only set on synthetic per-user-message checkpoints (the non-linear
3580
+ * `getSessionTurns` result). `completionId` always stays the checkpoint's
3581
+ * own identity — for these synthetic turns, the user message's id — which is
3582
+ * exactly what restoring "before this point" needs (the factual commit at
3583
+ * that moment). `finalCompletionId` separately carries the last agent turn in
3584
+ * the message's range that holds the post-message commit (`afterCommit`), for
3585
+ * callers that want to restore to the "after" state. Undefined for ordinary
3586
+ * (linear) turns.
3587
+ */
3588
+ finalCompletionId?: string;
3589
+ }
3590
+ /**
3591
+ * A completed turn. Invariant: a `done` turn ALWAYS has a `nextUrl` (the
3592
+ * continuation pointer the server emits on the `done` event / persists as the
3593
+ * session's last completion). Encoded in the type so `state === "done"` narrows
3594
+ * `nextUrl` to `string` — restore/anchor logic can rely on it.
3595
+ */
3596
+ export interface CodegenTurnDone extends CodegenTurnBase {
3597
+ state: "done";
3598
+ nextUrl: string;
3599
+ }
3600
+ /** A turn that is still running, or errored before completing. */
3601
+ export interface CodegenTurnPending extends CodegenTurnBase {
3602
+ state: "running" | "error";
3603
+ nextUrl: string | undefined;
3580
3604
  }
3605
+ export type CodegenTurn = CodegenTurnDone | CodegenTurnPending;
3581
3606
  export interface GetSessionTurnsResult {
3582
3607
  turns: CodegenTurn[];
3583
3608
  allIds: string[];
@@ -4656,3 +4681,4 @@ export interface SessionData {
4656
4681
  numNormalUserMessages: number;
4657
4682
  metadata?: Record<string, any>;
4658
4683
  }
4684
+ export {};
@@ -35,10 +35,6 @@ export interface GenerateDesignSystemFormFields {
35
35
  */
36
36
  export declare const GITHUB_REPO_URL_REGEX: RegExp;
37
37
  export interface GenerateDesignSystemRequest extends GenerateDesignSystemFormFields {
38
- /**
39
- * Mixed list of uploaded files in any order. Sent as repeated
40
- * `attachments` fields in the multipart body.
41
- */
42
38
  attachments: File[];
43
39
  }
44
40
  export interface GenerateDesignSystemResponse {
@@ -58,18 +54,75 @@ export interface GenerateDesignSystemErrorResponse {
58
54
  export declare const GENERATE_DESIGN_SYSTEM_MAX_FILE_BYTES: number;
59
55
  export declare const GENERATE_DESIGN_SYSTEM_MAX_ATTACHMENTS = 50;
60
56
  export declare const GENERATE_DESIGN_SYSTEM_MIN_ATTACHMENTS = 1;
57
+ export declare const generateDesignSystemBodySchema: z.ZodObject<{
58
+ projectName: z.ZodOptional<z.ZodString>;
59
+ devToolsVersion: z.ZodOptional<z.ZodString>;
60
+ selection: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>>;
61
+ githubRepoUrl: z.ZodOptional<z.ZodString>;
62
+ connectedProjectId: z.ZodOptional<z.ZodString>;
63
+ }, z.core.$strip>;
64
+ export type GenerateDesignSystemBody = z.infer<typeof generateDesignSystemBodySchema>;
61
65
  /**
62
- * Validation for non-file fields posted alongside the multipart upload.
63
- * Files are parsed out of the body by multer before this schema runs.
66
+ * Signed-URL upload flow.
64
67
  *
65
- * The inferred type matches `GenerateDesignSystemFormFields` so the wire
66
- * contract stays in lockstep with the shared type.
68
+ * Clients no longer post `.fig` bytes through the service (Cloud Run caps
69
+ * request bodies at 32 MiB). Instead they call `upload/start` to get a
70
+ * temporary signed resumable-upload URL per attachment, stream the bytes
71
+ * directly to GCS, then call `/generate` with the returned upload tokens.
72
+ * See `tech-specs/signed-url-figma-upload`.
67
73
  */
68
- export declare const generateDesignSystemBodySchema: z.ZodObject<{
74
+ /** A single attachment the client declares when starting an upload. */
75
+ export declare const uploadStartAttachmentSchema: z.ZodObject<{
76
+ name: z.ZodString;
77
+ mimetype: z.ZodString;
78
+ declaredSize: z.ZodNumber;
79
+ }, z.core.$strip>;
80
+ export type UploadStartAttachment = z.infer<typeof uploadStartAttachmentSchema>;
81
+ /** Request body for `POST /design-systems/v1/upload/start`. */
82
+ export declare const uploadStartBodySchema: z.ZodObject<{
83
+ attachments: z.ZodArray<z.ZodObject<{
84
+ name: z.ZodString;
85
+ mimetype: z.ZodString;
86
+ declaredSize: z.ZodNumber;
87
+ }, z.core.$strip>>;
88
+ }, z.core.$strip>;
89
+ export type UploadStartBody = z.infer<typeof uploadStartBodySchema>;
90
+ /**
91
+ * Claims encoded inside a signed `uploadToken`. Bound to the GCS object at
92
+ * `upload/start` and verified at `/generate`, so a client cannot point the
93
+ * decode worker at an object it did not upload.
94
+ */
95
+ export declare const uploadTokenPayloadSchema: z.ZodObject<{
96
+ jobId: z.ZodString;
97
+ gcsObject: z.ZodString;
98
+ ownerId: z.ZodString;
99
+ mimetype: z.ZodString;
100
+ originalName: z.ZodString;
101
+ idx: z.ZodNumber;
102
+ }, z.core.$strip>;
103
+ export type UploadTokenPayload = z.infer<typeof uploadTokenPayloadSchema>;
104
+ export interface UploadStartResponseItem {
105
+ idx: number;
106
+ /** Signed URL the client POSTs to (with `x-goog-resumable: start`) to begin the resumable upload. */
107
+ uploadUrl: string;
108
+ /** Opaque signed token the client passes back to `/generate`. */
109
+ uploadToken: string;
110
+ }
111
+ export interface UploadStartResponse {
112
+ jobId: string;
113
+ uploads: UploadStartResponseItem[];
114
+ }
115
+ /**
116
+ * Request body for the signed-URL variant of `POST /design-systems/v1/generate`.
117
+ * Same non-file fields as the legacy multipart form, plus the `uploads`
118
+ * tokens returned by `upload/start` (one per attachment).
119
+ */
120
+ export declare const generateDesignSystemRequestSchema: z.ZodObject<{
69
121
  projectName: z.ZodOptional<z.ZodString>;
70
122
  devToolsVersion: z.ZodOptional<z.ZodString>;
71
123
  selection: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>>;
72
124
  githubRepoUrl: z.ZodOptional<z.ZodString>;
73
125
  connectedProjectId: z.ZodOptional<z.ZodString>;
126
+ uploads: z.ZodArray<z.ZodString>;
74
127
  }, z.core.$strip>;
75
- export type GenerateDesignSystemBody = z.infer<typeof generateDesignSystemBodySchema>;
128
+ export type GenerateDesignSystemRequestBody = z.infer<typeof generateDesignSystemRequestSchema>;
@@ -8,13 +8,6 @@ export const GITHUB_REPO_URL_REGEX = /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[
8
8
  export const GENERATE_DESIGN_SYSTEM_MAX_FILE_BYTES = 2 * 1024 * 1024 * 1024;
9
9
  export const GENERATE_DESIGN_SYSTEM_MAX_ATTACHMENTS = 50;
10
10
  export const GENERATE_DESIGN_SYSTEM_MIN_ATTACHMENTS = 1;
11
- /**
12
- * Validation for non-file fields posted alongside the multipart upload.
13
- * Files are parsed out of the body by multer before this schema runs.
14
- *
15
- * The inferred type matches `GenerateDesignSystemFormFields` so the wire
16
- * contract stays in lockstep with the shared type.
17
- */
18
11
  export const generateDesignSystemBodySchema = z.object({
19
12
  projectName: z.string().trim().min(1).max(200).optional(),
20
13
  devToolsVersion: z.string().trim().min(1).max(64).optional(),
@@ -40,3 +33,54 @@ export const generateDesignSystemBodySchema = z.object({
40
33
  .optional(),
41
34
  connectedProjectId: z.string().trim().min(1).max(128).optional(),
42
35
  });
36
+ /**
37
+ * Signed-URL upload flow.
38
+ *
39
+ * Clients no longer post `.fig` bytes through the service (Cloud Run caps
40
+ * request bodies at 32 MiB). Instead they call `upload/start` to get a
41
+ * temporary signed resumable-upload URL per attachment, stream the bytes
42
+ * directly to GCS, then call `/generate` with the returned upload tokens.
43
+ * See `tech-specs/signed-url-figma-upload`.
44
+ */
45
+ /** A single attachment the client declares when starting an upload. */
46
+ export const uploadStartAttachmentSchema = z.object({
47
+ name: z.string().trim().min(1).max(512),
48
+ mimetype: z.string().trim().min(1).max(255),
49
+ declaredSize: z
50
+ .number()
51
+ .int()
52
+ .positive()
53
+ .max(GENERATE_DESIGN_SYSTEM_MAX_FILE_BYTES),
54
+ });
55
+ /** Request body for `POST /design-systems/v1/upload/start`. */
56
+ export const uploadStartBodySchema = z.object({
57
+ attachments: z
58
+ .array(uploadStartAttachmentSchema)
59
+ .min(GENERATE_DESIGN_SYSTEM_MIN_ATTACHMENTS)
60
+ .max(GENERATE_DESIGN_SYSTEM_MAX_ATTACHMENTS),
61
+ });
62
+ /**
63
+ * Claims encoded inside a signed `uploadToken`. Bound to the GCS object at
64
+ * `upload/start` and verified at `/generate`, so a client cannot point the
65
+ * decode worker at an object it did not upload.
66
+ */
67
+ export const uploadTokenPayloadSchema = z.object({
68
+ jobId: z.string().min(1),
69
+ gcsObject: z.string().min(1),
70
+ ownerId: z.string().min(1),
71
+ mimetype: z.string().min(1),
72
+ originalName: z.string().min(1),
73
+ idx: z.number().int().nonnegative(),
74
+ });
75
+ /**
76
+ * Request body for the signed-URL variant of `POST /design-systems/v1/generate`.
77
+ * Same non-file fields as the legacy multipart form, plus the `uploads`
78
+ * tokens returned by `upload/start` (one per attachment).
79
+ */
80
+ export const generateDesignSystemRequestSchema = z.object({
81
+ ...generateDesignSystemBodySchema.shape,
82
+ uploads: z
83
+ .array(z.string().min(1))
84
+ .min(GENERATE_DESIGN_SYSTEM_MIN_ATTACHMENTS)
85
+ .max(GENERATE_DESIGN_SYSTEM_MAX_ATTACHMENTS),
86
+ });
package/src/events.d.ts CHANGED
@@ -1039,6 +1039,8 @@ export type FigmaDecodeJobV1 = FusionEventVariant<"figma.decode.job", {
1039
1039
  projectId: string;
1040
1040
  projectName: string;
1041
1041
  figmaName: string;
1042
+ /** Design-system record this job feeds; updated with the branch once created. */
1043
+ designSystemId?: string;
1042
1044
  /**
1043
1045
  * GCS object paths (relative to the configured bucket) of every attachment
1044
1046
  * uploaded for this job. The worker streams these back down, runs