@builder.io/ai-utils 0.103.0 → 0.106.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/src/projects.js CHANGED
@@ -399,6 +399,14 @@ export const ShapeSessionSchema = z.object({
399
399
  assembledAt: z.string().optional(),
400
400
  resolvedAt: z.string().optional(),
401
401
  });
402
+ /**
403
+ * Stored shape of the top-level `shapeSessions/{projectId}` Firestore
404
+ * collection: a `ShapeSession` plus the `projectId` it belongs to, since the
405
+ * doc ID alone isn't visible once the doc is loaded into memory.
406
+ */
407
+ export const ShapeSessionDocSchema = ShapeSessionSchema.extend({
408
+ projectId: z.string(),
409
+ });
402
410
  export const InitialPromptSchema = z.object({
403
411
  id: z.string(),
404
412
  projectId: z.string(),
@@ -896,9 +904,6 @@ export const ProjectSettingsSchema = z
896
904
  })
897
905
  .optional()
898
906
  .meta({ description: "Password-protect the preview URL." }),
899
- shapeSession: ShapeSessionSchema.optional().meta({
900
- description: "@internal Guided-onboarding questionnaire issued for this project.",
901
- }),
902
907
  })
903
908
  .meta({ title: "ProjectSettings" });
904
909
  /**
@@ -922,7 +927,6 @@ const INTERNAL_PROJECT_SETTINGS_MASK = {
922
927
  commitInstructions: true,
923
928
  skipCommandSecurity: true,
924
929
  autoCloseBranchOnMerge: true,
925
- shapeSession: true,
926
930
  };
927
931
  /**
928
932
  * Runtime schema for the client-writable subset of {@link Project.settings},
@@ -2311,3 +2315,41 @@ export const CreateProjectTemplateFromProjectOptionsSchema = z
2311
2315
  export const CreateProjectTemplateFromProjectResponseSchema = z.object({
2312
2316
  template: ProjectTemplateSchema.pick({ id: true, name: true }),
2313
2317
  });
2318
+ export const ListProjectTemplatesOptionsSchema = z.object({
2319
+ id: z.string().min(1).optional(),
2320
+ });
2321
+ export const ListProjectTemplatesResponseSchema = z.object({
2322
+ templates: z.array(ProjectTemplateSchema),
2323
+ });
2324
+ export const UpdateProjectTemplateOptionsSchema = z.object({
2325
+ id: z.string().min(1),
2326
+ updates: ProjectTemplateOverridesSchema,
2327
+ });
2328
+ export const UpdateProjectTemplateResponseSchema = z.object({
2329
+ template: ProjectTemplateSchema,
2330
+ });
2331
+ export const DeleteProjectTemplateOptionsSchema = z.object({
2332
+ id: z.string().min(1),
2333
+ });
2334
+ export const DeleteProjectTemplateResponseSchema = z.object({
2335
+ deleted: z.boolean(),
2336
+ });
2337
+ export const ReorderProjectTemplatesOptionsSchema = z.object({
2338
+ orders: z
2339
+ .array(z.object({ id: z.string().min(1), order: z.number().int() }))
2340
+ .min(1),
2341
+ });
2342
+ export const ReorderProjectTemplatesResponseSchema = z.object({
2343
+ updatedIds: z.array(z.string()),
2344
+ });
2345
+ /**
2346
+ * `id` is omitted when a built-in (non-Firestore-backed) template becomes the
2347
+ * org default, so this just needs to clear `isDefault` on the owner's stored
2348
+ * templates without pointing it at a new one.
2349
+ */
2350
+ export const SetDefaultProjectTemplateOptionsSchema = z.object({
2351
+ id: z.string().min(1).optional(),
2352
+ });
2353
+ export const SetDefaultProjectTemplateResponseSchema = z.object({
2354
+ defaultId: z.string().nullable(),
2355
+ });
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { AGENT_NATIVE_STARTER_REPO, getAgentNativeRootPackageJsonWriteError, getManagedDatabasePackageJsonError, getProjectState, GetShapeQuestionnaireOptionsSchema, InitialPromptSchema, isProjectDeleted, matchesAgentNativeStarter, ProjectHostingExternalSchema, ProjectHostingSchema, ProjectSettingsExternalSchema, ProjectSettingsSchema, ProjectTemplateOverridesSchema, ShapeSessionSchema, SubmitShapeAnswersOptionsSchema, } from "./projects";
2
+ import { AGENT_NATIVE_STARTER_REPO, getAgentNativeRootPackageJsonWriteError, getManagedDatabasePackageJsonError, getProjectState, GetShapeQuestionnaireOptionsSchema, InitialPromptSchema, isProjectDeleted, matchesAgentNativeStarter, ProjectHostingExternalSchema, ProjectHostingSchema, ProjectSettingsExternalSchema, ProjectTemplateOverridesSchema, ShapeSessionSchema, SubmitShapeAnswersOptionsSchema, } from "./projects";
3
3
  describe("project hosting schemas", () => {
4
4
  it("accepts the canonical published branch route", () => {
5
5
  expect(ProjectHostingSchema.parse({ publishedBranchId: "branch-live" })).toEqual({ publishedBranchId: "branch-live" });
@@ -55,9 +55,6 @@ describe("guided onboarding project settings", () => {
55
55
  };
56
56
  it("parses a snapshotted questionnaire session", () => {
57
57
  expect(ShapeSessionSchema.parse(shapeSession)).toEqual(shapeSession);
58
- expect(ProjectSettingsSchema.parse({ shapeSession })).toEqual({
59
- shapeSession,
60
- });
61
58
  });
62
59
  it("requires a dated catalog version", () => {
63
60
  expect(() => ShapeSessionSchema.parse({
package/src/realtime.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { z } from "zod";
2
2
  export declare const BUILDER_REALTIME_MODEL: "gpt-live-1";
3
3
  export declare const BUILDER_REALTIME_LEGACY_MODEL: "gpt-realtime-2.1";
4
- export declare const BUILDER_REALTIME_DELEGATED_MODEL: "gpt-5.6-luna";
4
+ export declare const BUILDER_REALTIME_DELEGATED_MODEL: "gpt-6-luna";
5
+ export declare const BUILDER_REALTIME_DELEGATED_MODEL_LEGACY: "gpt-5.6-luna";
5
6
  export declare const BUILDER_REALTIME_MAX_SDP_LENGTH = 256000;
6
7
  export declare const BUILDER_REALTIME_MAX_SESSION_BYTES = 64000;
7
8
  export declare const OpenAIRealtimeFunctionToolSchema: z.ZodObject<{
@@ -153,7 +154,7 @@ export declare const OpenAILiveSessionConfigSchema: z.ZodObject<{
153
154
  delegation: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodObject<{
154
155
  type: z.ZodLiteral<"responses">;
155
156
  responses: z.ZodObject<{
156
- model: z.ZodLiteral<"gpt-5.6-luna">;
157
+ model: z.ZodUnion<readonly [z.ZodLiteral<"gpt-6-luna">, z.ZodLiteral<"gpt-5.6-luna">]>;
157
158
  instructions: z.ZodOptional<z.ZodString>;
158
159
  tools: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
159
160
  type: z.ZodLiteral<"function">;
@@ -212,7 +213,7 @@ export declare const BuilderRealtimeSessionRequestSchema: z.ZodObject<{
212
213
  delegation: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodObject<{
213
214
  type: z.ZodLiteral<"responses">;
214
215
  responses: z.ZodObject<{
215
- model: z.ZodLiteral<"gpt-5.6-luna">;
216
+ model: z.ZodUnion<readonly [z.ZodLiteral<"gpt-6-luna">, z.ZodLiteral<"gpt-5.6-luna">]>;
216
217
  instructions: z.ZodOptional<z.ZodString>;
217
218
  tools: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
218
219
  type: z.ZodLiteral<"function">;
package/src/realtime.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { z } from "zod";
2
2
  export const BUILDER_REALTIME_MODEL = "gpt-live-1";
3
3
  export const BUILDER_REALTIME_LEGACY_MODEL = "gpt-realtime-2.1";
4
- export const BUILDER_REALTIME_DELEGATED_MODEL = "gpt-5.6-luna";
4
+ export const BUILDER_REALTIME_DELEGATED_MODEL = "gpt-6-luna";
5
+ export const BUILDER_REALTIME_DELEGATED_MODEL_LEGACY = "gpt-5.6-luna";
5
6
  export const BUILDER_REALTIME_MAX_SDP_LENGTH = 256000;
6
7
  export const BUILDER_REALTIME_MAX_SESSION_BYTES = 64000;
7
8
  const utf8ByteLength = (value) => new TextEncoder().encode(value).length;
@@ -154,8 +155,16 @@ const OpenAILiveToolSchema = z.union([
154
155
  OpenAIRealtimeFunctionToolSchema,
155
156
  z.object({ type: z.literal("web_search") }),
156
157
  ]);
158
+ const RealtimeDelegatedModelSchema = z
159
+ .union([
160
+ z.literal(BUILDER_REALTIME_DELEGATED_MODEL),
161
+ z.literal(BUILDER_REALTIME_DELEGATED_MODEL_LEGACY),
162
+ ])
163
+ .overwrite((model) => model === BUILDER_REALTIME_DELEGATED_MODEL_LEGACY
164
+ ? BUILDER_REALTIME_DELEGATED_MODEL
165
+ : model);
157
166
  const OpenAILiveResponsesDelegationSchema = z.object({
158
- model: z.literal(BUILDER_REALTIME_DELEGATED_MODEL),
167
+ model: RealtimeDelegatedModelSchema,
159
168
  instructions: z.string().max(32000).optional(),
160
169
  tools: z.array(OpenAILiveToolSchema).max(32).optional(),
161
170
  tool_choice: z
@@ -17,7 +17,7 @@ describe("BuilderRealtimeSessionRequestSchema", () => {
17
17
  delegation: {
18
18
  type: "responses",
19
19
  responses: {
20
- model: "gpt-5.6-luna",
20
+ model: "gpt-6-luna",
21
21
  tools: [
22
22
  {
23
23
  type: "function",
@@ -32,12 +32,25 @@ describe("BuilderRealtimeSessionRequestSchema", () => {
32
32
  },
33
33
  });
34
34
  expect(result.session).toMatchObject({
35
+ model: "gpt-live-1",
36
+ delegation: {
37
+ type: "responses",
38
+ responses: { model: "gpt-6-luna" },
39
+ },
40
+ });
41
+ });
42
+ it("normalizes the legacy delegated model name", () => {
43
+ const result = OpenAILiveSessionConfigSchema.parse({
35
44
  model: "gpt-live-1",
36
45
  delegation: {
37
46
  type: "responses",
38
47
  responses: { model: "gpt-5.6-luna" },
39
48
  },
40
49
  });
50
+ expect(result.delegation).toEqual({
51
+ type: "responses",
52
+ responses: { model: "gpt-6-luna" },
53
+ });
41
54
  });
42
55
  it("accepts a bounded audio session with tools", () => {
43
56
  var _a;
@@ -149,6 +149,10 @@ export interface DesignSystem {
149
149
  * have no code to detect from, and whenever the agent couldn't tell.
150
150
  */
151
151
  framework?: DesignSystemFramework;
152
+ /**
153
+ * @deprecated Prefer checking DisplayDesignSystem.docCount instead of relying on
154
+ * "in-progress" or "completed".
155
+ */
152
156
  status: "in-progress" | "completed" | "failed";
153
157
  scope: DesignSystemScope;
154
158
  deprecated: boolean;
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ export declare const SYSTEM_ONE_DEFAULT_MODEL = "jev-latest";
3
+ export declare const SystemOneAvailabilityResponseSchema: z.ZodObject<{
4
+ enabled: z.ZodBoolean;
5
+ }, z.core.$strip>;
6
+ export type SystemOneAvailabilityResponse = z.infer<typeof SystemOneAvailabilityResponseSchema>;
7
+ export declare const SystemOneRequestSchema: z.ZodObject<{
8
+ state: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>;
9
+ model: z.ZodDefault<z.ZodString>;
10
+ questions: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
11
+ type: z.ZodLiteral<"noul">;
12
+ instructions: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>;
13
+ criteria: z.ZodOptional<z.ZodObject<{
14
+ true: z.ZodOptional<z.ZodString>;
15
+ false: z.ZodOptional<z.ZodString>;
16
+ }, z.core.$strip>>;
17
+ }, z.core.$loose>, z.ZodObject<{
18
+ type: z.ZodLiteral<"choice">;
19
+ instructions: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>;
20
+ criteria: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
21
+ }, z.core.$loose>, z.ZodObject<{
22
+ type: z.ZodLiteral<"score">;
23
+ instructions: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>;
24
+ criteria: z.ZodArray<z.ZodString>;
25
+ }, z.core.$loose>], "type">>;
26
+ }, z.core.$loose>;
27
+ export declare const SystemOneResponseSchema: z.ZodObject<{
28
+ model: z.ZodString;
29
+ answers: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
30
+ type: z.ZodLiteral<"noul">;
31
+ noul: z.ZodNumber;
32
+ }, z.core.$loose>, z.ZodObject<{
33
+ type: z.ZodLiteral<"choice">;
34
+ choice: z.ZodString;
35
+ probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
36
+ confidence: z.ZodNumber;
37
+ }, z.core.$loose>, z.ZodObject<{
38
+ type: z.ZodLiteral<"score">;
39
+ score: z.ZodNumber;
40
+ legend: z.ZodRecord<z.ZodString, z.ZodString>;
41
+ probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
42
+ confidence: z.ZodNumber;
43
+ }, z.core.$loose>], "type">>;
44
+ usage: z.ZodObject<{
45
+ input_tokens: z.ZodNumber;
46
+ output_tokens: z.ZodNumber;
47
+ }, z.core.$strip>;
48
+ }, z.core.$loose>;
49
+ export type SystemOneRequest = z.output<typeof SystemOneRequestSchema>;
50
+ export type SystemOneResponse = z.infer<typeof SystemOneResponseSchema>;
@@ -0,0 +1,102 @@
1
+ import { z } from "zod";
2
+ export const SYSTEM_ONE_DEFAULT_MODEL = "jev-latest";
3
+ export const SystemOneAvailabilityResponseSchema = z
4
+ .object({
5
+ enabled: z.boolean(),
6
+ })
7
+ .meta({
8
+ description: "Response for GET /agent-native/jev/v1/status.",
9
+ });
10
+ const SystemOneValueSchema = z.union([
11
+ z.string(),
12
+ z.record(z.string(), z.unknown()),
13
+ z.array(z.unknown()),
14
+ ]);
15
+ const NoulQuestionSchema = z
16
+ .object({
17
+ type: z.literal("noul"),
18
+ instructions: SystemOneValueSchema,
19
+ criteria: z
20
+ .object({
21
+ true: z.string().optional(),
22
+ false: z.string().optional(),
23
+ })
24
+ .optional(),
25
+ })
26
+ .passthrough();
27
+ const ChoiceQuestionSchema = z
28
+ .object({
29
+ type: z.literal("choice"),
30
+ instructions: SystemOneValueSchema,
31
+ criteria: z
32
+ .record(z.string(), z.string().nullable())
33
+ .refine((criteria) => Object.keys(criteria).length > 0, {
34
+ message: "At least one choice is required.",
35
+ }),
36
+ })
37
+ .passthrough();
38
+ const ScoreQuestionSchema = z
39
+ .object({
40
+ type: z.literal("score"),
41
+ instructions: SystemOneValueSchema,
42
+ criteria: z.array(z.string()).min(2),
43
+ })
44
+ .passthrough();
45
+ const SystemOneQuestionSchema = z.discriminatedUnion("type", [
46
+ NoulQuestionSchema,
47
+ ChoiceQuestionSchema,
48
+ ScoreQuestionSchema,
49
+ ]);
50
+ export const SystemOneRequestSchema = z
51
+ .object({
52
+ state: SystemOneValueSchema,
53
+ model: z.string().trim().min(1).default(SYSTEM_ONE_DEFAULT_MODEL),
54
+ questions: z
55
+ .record(z.string().min(1), SystemOneQuestionSchema)
56
+ .refine((questions) => Object.keys(questions).length > 0, {
57
+ message: "At least one question is required.",
58
+ }),
59
+ })
60
+ .passthrough()
61
+ .meta({
62
+ description: "Request body for POST /agent-native/jev/v1/system-one.",
63
+ });
64
+ const ProbabilitySchema = z.number().finite().min(0).max(1);
65
+ const NoulAnswerSchema = z
66
+ .object({
67
+ type: z.literal("noul"),
68
+ noul: ProbabilitySchema,
69
+ })
70
+ .passthrough();
71
+ const ChoiceAnswerSchema = z
72
+ .object({
73
+ type: z.literal("choice"),
74
+ choice: z.string(),
75
+ probabilities: z.record(z.string(), ProbabilitySchema),
76
+ confidence: ProbabilitySchema,
77
+ })
78
+ .passthrough();
79
+ const ScoreAnswerSchema = z
80
+ .object({
81
+ type: z.literal("score"),
82
+ score: z.number().finite(),
83
+ legend: z.record(z.string(), z.string()),
84
+ probabilities: z.record(z.string(), ProbabilitySchema),
85
+ confidence: ProbabilitySchema,
86
+ })
87
+ .passthrough();
88
+ const SystemOneAnswerSchema = z.discriminatedUnion("type", [
89
+ NoulAnswerSchema,
90
+ ChoiceAnswerSchema,
91
+ ScoreAnswerSchema,
92
+ ]);
93
+ export const SystemOneResponseSchema = z
94
+ .object({
95
+ model: z.string(),
96
+ answers: z.record(z.string(), SystemOneAnswerSchema),
97
+ usage: z.object({
98
+ input_tokens: z.number().int().nonnegative(),
99
+ output_tokens: z.number().int().nonnegative(),
100
+ }),
101
+ })
102
+ .passthrough();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { SYSTEM_ONE_DEFAULT_MODEL, SystemOneAvailabilityResponseSchema, SystemOneRequestSchema, SystemOneResponseSchema, } from "./system-one";
3
+ describe("System One schemas", () => {
4
+ it("validates Builder availability responses", () => {
5
+ expect(SystemOneAvailabilityResponseSchema.parse({ enabled: true })).toEqual({ enabled: true });
6
+ expect(() => SystemOneAvailabilityResponseSchema.parse({ enabled: "true" })).toThrow();
7
+ });
8
+ it("defaults the model and validates each question type", () => {
9
+ const request = SystemOneRequestSchema.parse({
10
+ state: { ticket: "export failed" },
11
+ questions: {
12
+ urgent: {
13
+ type: "noul",
14
+ instructions: "Is this urgent?",
15
+ },
16
+ team: {
17
+ type: "choice",
18
+ instructions: "Who owns this?",
19
+ criteria: { support: "Customer issue", engineering: null },
20
+ },
21
+ severity: {
22
+ type: "score",
23
+ instructions: "How severe is this?",
24
+ criteria: ["low", "high"],
25
+ },
26
+ },
27
+ });
28
+ expect(request.model).toBe(SYSTEM_ONE_DEFAULT_MODEL);
29
+ });
30
+ it("rejects a score question without two levels", () => {
31
+ expect(() => SystemOneRequestSchema.parse({
32
+ state: "ticket",
33
+ questions: {
34
+ severity: {
35
+ type: "score",
36
+ instructions: "How severe?",
37
+ criteria: ["low"],
38
+ },
39
+ },
40
+ })).toThrow();
41
+ });
42
+ it("validates the structured response", () => {
43
+ expect(SystemOneResponseSchema.parse({
44
+ model: "jev-1.13.0",
45
+ answers: {
46
+ urgent: { type: "noul", noul: 0.8 },
47
+ },
48
+ usage: { input_tokens: 10, output_tokens: 2 },
49
+ }).usage.input_tokens).toBe(10);
50
+ });
51
+ });