@builder.io/ai-utils 0.101.0 → 0.105.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.101.0",
3
+ "version": "0.105.0",
4
4
  "description": "Builder.io AI utils",
5
5
  "files": [
6
6
  "src"
package/src/codegen.d.ts CHANGED
@@ -2317,6 +2317,7 @@ export declare const PublishAgentMessageRequestSchema: z.ZodObject<{
2317
2317
  tag: z.ZodOptional<z.ZodString>;
2318
2318
  ephemeral: z.ZodOptional<z.ZodBoolean>;
2319
2319
  }, z.core.$strip>]>>>;
2320
+ requireConfirmation: z.ZodOptional<z.ZodBoolean>;
2320
2321
  skippedMCPs: z.ZodOptional<z.ZodArray<z.ZodString>>;
2321
2322
  }, z.core.$strip>;
2322
2323
  export type PublishAgentMessageRequest = z.infer<typeof PublishAgentMessageRequestSchema>;
@@ -4324,6 +4325,12 @@ export interface WorkspaceFolder {
4324
4325
  templateRepoUrl?: string;
4325
4326
  repoName?: string;
4326
4327
  resetGit?: boolean;
4328
+ /**
4329
+ * The project's configured base/default branch (e.g. "main", "master"),
4330
+ * distinct from `branchName` (the feature branch this folder checks out).
4331
+ * Used when seeding or checking the base branch on the real remote.
4332
+ */
4333
+ mainBranchName?: string;
4327
4334
  branchName?: string;
4328
4335
  backupMetadata?: BackupMetadata;
4329
4336
  initializationCommand?: string;
@@ -4542,6 +4549,11 @@ export interface FusionConfig {
4542
4549
  /** If true, nuke and re-clone the git repo during init, overwriting the existing repo */
4543
4550
  rebuildGit?: boolean;
4544
4551
  mode?: Mode;
4552
+ /**
4553
+ * Combines with the backup modes: try to repair a corrupt git object database
4554
+ * before backing up, instead of failing on the first unreadable object.
4555
+ */
4556
+ attemptCorruptGitRecovery?: boolean;
4545
4557
  autoDetectDevServer?: boolean;
4546
4558
  autoDetectDevServerPatterns?: string[];
4547
4559
  /**
@@ -4670,7 +4682,7 @@ export interface LoadHistoryResult {
4670
4682
  updatedUnixTime: number;
4671
4683
  turns: CodegenTurn[];
4672
4684
  }
4673
- export type InitStateStep = "initial" | "init" | "validation" | "check-directories" | "create-directories" | "configure-git-repos" | "check-existing-git" | "update-remote-url" | "clone-repo" | "apply-partial-backup" | "configure-git-user" | "stash-changes" | "collect-repo-info" | "init-success" | "init-command" | "init-failed" | "snapshot-git-sync" | "snapshot-backup-restore";
4685
+ export type InitStateStep = "initial" | "init" | "validation" | "check-directories" | "create-directories" | "configure-git-repos" | "check-existing-git" | "update-remote-url" | "clone-repo" | "apply-partial-backup" | "configure-git-user" | "stash-changes" | "collect-repo-info" | "init-success" | "init-command" | "init-failed" | "snapshot-git-sync" | "snapshot-backup-restore" | "git-corruption-recovery" | "seed-base-branch";
4674
4686
  export interface InitStatusLog {
4675
4687
  id: number;
4676
4688
  timestamp: string;
@@ -5125,6 +5137,35 @@ export type MessageUpdateOptions = {
5125
5137
  type: "delete";
5126
5138
  idempotencyKey: string;
5127
5139
  };
5140
+ /**
5141
+ * Args for the `writeFile` launch-server RPC.
5142
+ *
5143
+ * A named-args object because the RPC applies arguments by position and the
5144
+ * container's pinned `dev-tools` rarely matches the caller's, so new fields
5145
+ * have to be additive rather than order-sensitive.
5146
+ */
5147
+ export interface WriteFileOptions {
5148
+ /** Workspace-relative, e.g. `docs/NOTES.md`. */
5149
+ path: string;
5150
+ contents: string;
5151
+ }
5152
+ /**
5153
+ * Discriminated rather than a nullable path, so a caller that gates behaviour
5154
+ * on the write can tell a refusal from a write that never happened, instead of
5155
+ * reading `null` as both.
5156
+ *
5157
+ * Gate on `success`, not on parsing `error`. Only an ACL denial is reported
5158
+ * distinctly; a blocked `package.json`, a path outside the workspace and a
5159
+ * filesystem error all share one generic message, their reason reaching only
5160
+ * Sentry.
5161
+ */
5162
+ export type WriteFileResult = {
5163
+ success: true;
5164
+ path: string;
5165
+ } | {
5166
+ success: false;
5167
+ error: string;
5168
+ };
5128
5169
  export interface LaunchInitializeSessionOptions {
5129
5170
  sessionId?: string;
5130
5171
  customInstructions?: CustomInstruction[];
package/src/codegen.js CHANGED
@@ -1818,6 +1818,9 @@ export const PublishAgentMessageRequestSchema = z
1818
1818
  attachments: z.array(AttachmentSchema).optional(),
1819
1819
  toolResults: z.array(ContentMessageItemToolResultSchema).optional(),
1820
1820
  systemReminders: z.array(SystemReminderSchema).optional(),
1821
+ requireConfirmation: z.boolean().optional().meta({
1822
+ description: "Ask before high-impact MCP tool calls; the turn emits confirmation_required and waits.",
1823
+ }),
1821
1824
  skippedMCPs: z.array(z.string()).optional().meta({
1822
1825
  description: "Per-message denylist of MCP server ids to skip, e.g. a 'disable for this session' UI toggle.",
1823
1826
  }),
@@ -266,3 +266,13 @@ export declare const listPublicSourceFilesQuerySchema: z.ZodObject<{
266
266
  ref: z.ZodOptional<z.ZodString>;
267
267
  }, z.core.$strip>;
268
268
  export type ListPublicSourceFilesQuery = z.infer<typeof listPublicSourceFilesQuerySchema>;
269
+ export type DSITier = "free" | "pro" | "team" | "enterprise";
270
+ export interface DSITierLimitResponse {
271
+ tier: DSITier;
272
+ /** Whether this org can index via the web (Figma/.md) flow at its tier. */
273
+ enabled: boolean;
274
+ /** Every active design system the org has, regardless of how it was created. */
275
+ current: number;
276
+ /** `null` is unlimited. */
277
+ max: number | null;
278
+ }
package/src/events.d.ts CHANGED
@@ -16,6 +16,7 @@ export interface AssistantCompletionResultEvent {
16
16
  resolveId?: string;
17
17
  }
18
18
  export interface AssistantError {
19
+ code?: string;
19
20
  message: string;
20
21
  status?: number;
21
22
  actions?: AssistantMessageAction[];
package/src/index.d.ts CHANGED
@@ -23,4 +23,6 @@ export * from "./design-systems.js";
23
23
  export * from "./editor-ai.js";
24
24
  export * from "./realtime.js";
25
25
  export * from "./embeddings.js";
26
+ export * from "./system-one.js";
27
+ export * from "./mcp-servers.js";
26
28
  export { connectivityErrorCodeToLikelyCause, mapConnectivityErrorMessage, } from "./connectivity/error-codes.js";
package/src/index.js CHANGED
@@ -23,4 +23,6 @@ export * from "./design-systems.js";
23
23
  export * from "./editor-ai.js";
24
24
  export * from "./realtime.js";
25
25
  export * from "./embeddings.js";
26
+ export * from "./system-one.js";
27
+ export * from "./mcp-servers.js";
26
28
  export { connectivityErrorCodeToLikelyCause, mapConnectivityErrorMessage, } from "./connectivity/error-codes.js";
@@ -0,0 +1,55 @@
1
+ import { z } from "zod";
2
+ export declare const McpServerRecordSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ ownerId: z.ZodString;
5
+ type: z.ZodLiteral<"url">;
6
+ url: z.ZodString;
7
+ name: z.ZodString;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ provider: z.ZodOptional<z.ZodString>;
10
+ clientName: z.ZodOptional<z.ZodString>;
11
+ createDate: z.ZodNumber;
12
+ updatedAt: z.ZodOptional<z.ZodNumber>;
13
+ tokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
14
+ requiresOAuth: z.ZodOptional<z.ZodBoolean>;
15
+ disabled: z.ZodOptional<z.ZodBoolean>;
16
+ isBuiltinConfiguration: z.ZodOptional<z.ZodBoolean>;
17
+ }, z.core.$strip>;
18
+ export type McpServerRecord = z.infer<typeof McpServerRecordSchema>;
19
+ export declare const McpServersListResponseSchema: z.ZodObject<{
20
+ servers: z.ZodArray<z.ZodObject<{
21
+ id: z.ZodString;
22
+ ownerId: z.ZodString;
23
+ type: z.ZodLiteral<"url">;
24
+ url: z.ZodString;
25
+ name: z.ZodString;
26
+ description: z.ZodOptional<z.ZodString>;
27
+ provider: z.ZodOptional<z.ZodString>;
28
+ clientName: z.ZodOptional<z.ZodString>;
29
+ createDate: z.ZodNumber;
30
+ updatedAt: z.ZodOptional<z.ZodNumber>;
31
+ tokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
32
+ requiresOAuth: z.ZodOptional<z.ZodBoolean>;
33
+ disabled: z.ZodOptional<z.ZodBoolean>;
34
+ isBuiltinConfiguration: z.ZodOptional<z.ZodBoolean>;
35
+ }, z.core.$strip>>;
36
+ }, z.core.$strip>;
37
+ export type McpServersListResponse = z.infer<typeof McpServersListResponseSchema>;
38
+ export declare const McpServersDeleteRequestSchema: z.ZodObject<{
39
+ serverIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
40
+ serverUrl: z.ZodOptional<z.ZodString>;
41
+ }, z.core.$strip>;
42
+ export type McpServersDeleteRequest = z.infer<typeof McpServersDeleteRequestSchema>;
43
+ export declare const McpServersDeleteResponseSchema: z.ZodObject<{
44
+ deletedServerIds: z.ZodArray<z.ZodString>;
45
+ }, z.core.$strip>;
46
+ export type McpServersDeleteResponse = z.infer<typeof McpServersDeleteResponseSchema>;
47
+ export declare const McpServersDisableRequestSchema: z.ZodObject<{
48
+ serverIds: z.ZodArray<z.ZodString>;
49
+ disabled: z.ZodBoolean;
50
+ }, z.core.$strip>;
51
+ export type McpServersDisableRequest = z.infer<typeof McpServersDisableRequestSchema>;
52
+ export declare const McpServersDisableResponseSchema: z.ZodObject<{
53
+ updatedServerIds: z.ZodArray<z.ZodString>;
54
+ }, z.core.$strip>;
55
+ export type McpServersDisableResponse = z.infer<typeof McpServersDisableResponseSchema>;
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ // Deliberately excludes authorizationToken, refreshToken, tokenType, and oauthMetadata:
3
+ // this is a general-purpose management API any org member can call, so credentials
4
+ // that could be replayed against the third-party server never leave the backend.
5
+ export const McpServerRecordSchema = z
6
+ .object({
7
+ id: z.string(),
8
+ ownerId: z.string(),
9
+ type: z.literal("url"),
10
+ url: z.string(),
11
+ name: z.string(),
12
+ description: z.string().optional(),
13
+ provider: z.string().optional(),
14
+ clientName: z.string().optional(),
15
+ createDate: z.number(),
16
+ updatedAt: z.number().optional(),
17
+ tokenExpiresAt: z.number().nullish(),
18
+ requiresOAuth: z.boolean().optional(),
19
+ disabled: z.boolean().optional(),
20
+ isBuiltinConfiguration: z.boolean().optional(),
21
+ })
22
+ .meta({ title: "McpServerRecord" });
23
+ export const McpServersListResponseSchema = z
24
+ .object({
25
+ servers: z.array(McpServerRecordSchema),
26
+ })
27
+ .meta({ title: "McpServersListResponse" });
28
+ // `serverUrl` mirrors the legacy disconnect-by-url Firestore query.
29
+ export const McpServersDeleteRequestSchema = z
30
+ .object({
31
+ serverIds: z.array(z.string()).optional(),
32
+ serverUrl: z.string().optional(),
33
+ })
34
+ .meta({ title: "McpServersDeleteRequest" });
35
+ export const McpServersDeleteResponseSchema = z
36
+ .object({
37
+ deletedServerIds: z.array(z.string()),
38
+ })
39
+ .meta({ title: "McpServersDeleteResponse" });
40
+ export const McpServersDisableRequestSchema = z
41
+ .object({
42
+ serverIds: z.array(z.string()).min(1),
43
+ disabled: z.boolean(),
44
+ })
45
+ .meta({ title: "McpServersDisableRequest" });
46
+ export const McpServersDisableResponseSchema = z
47
+ .object({
48
+ updatedServerIds: z.array(z.string()),
49
+ })
50
+ .meta({ title: "McpServersDisableResponse" });
package/src/projects.d.ts CHANGED
@@ -334,6 +334,23 @@ export interface CodegenSetLastCommit {
334
334
  lastCommitHash: GitSnapshot;
335
335
  clearSecondaryVolumeId: boolean;
336
336
  }
337
+ /**
338
+ * A run that ended on an unreadable git object database.
339
+ *
340
+ * Reported by the container rather than inferred by the service: a backup-mode
341
+ * launch is only ever observed as a machine that started and exited, so from
342
+ * the outside a corrupt repo and a clean backup look the same.
343
+ */
344
+ export declare const GitCorruptionReportSchema: z.ZodObject<{
345
+ at: z.ZodNumber;
346
+ error: z.ZodString;
347
+ repoPath: z.ZodOptional<z.ZodString>;
348
+ emptyObjects: z.ZodOptional<z.ZodNumber>;
349
+ recoveryAttempted: z.ZodOptional<z.ZodBoolean>;
350
+ recoveryRefetched: z.ZodOptional<z.ZodBoolean>;
351
+ devToolsVersion: z.ZodOptional<z.ZodString>;
352
+ }, z.core.$strip>;
353
+ export type GitCorruptionReport = z.infer<typeof GitCorruptionReportSchema>;
337
354
  export interface CodegenRuntimeStatus {
338
355
  projectId: string;
339
356
  branchName: string;
@@ -341,6 +358,7 @@ export interface CodegenRuntimeStatus {
341
358
  clearSecondaryVolumeId?: boolean;
342
359
  lastServerState?: LaunchServerState;
343
360
  lastServerVersion?: string;
361
+ gitCorruption?: GitCorruptionReport;
344
362
  }
345
363
  export interface BackupGitRepoResultValid {
346
364
  success: true;
@@ -587,6 +605,12 @@ export interface BranchSharedData {
587
605
  lastServerState?: LaunchServerState | null;
588
606
  lastServerStateDate?: number | null;
589
607
  lastServerVersion?: string | null;
608
+ /**
609
+ * Last run that died on a corrupt git object database, cleared the next time
610
+ * the branch initializes cleanly. A volume in this state can never produce a
611
+ * deletion-safe backup, so the cleanup cron will never reclaim it.
612
+ */
613
+ gitCorruption?: GitCorruptionReport | null;
590
614
  name?: string;
591
615
  hidden?: boolean;
592
616
  createdBy?: string;
@@ -2413,6 +2437,9 @@ export interface MemorySummary extends Pick<MemoryData, (typeof MEMORY_SUMMARY_F
2413
2437
  export interface GetProjectMemoriesResult {
2414
2438
  memories: MemorySummary[];
2415
2439
  }
2440
+ export interface GetFusionPrivateKeyResult {
2441
+ id: string;
2442
+ }
2416
2443
  interface BaseSendMessageMessage {
2417
2444
  }
2418
2445
  export interface ValidatingBranchMessage extends BaseSendMessageMessage {
@@ -3417,6 +3444,14 @@ export declare const ReserveSlugResponseSchema: z.ZodObject<{
3417
3444
  slug: z.ZodString;
3418
3445
  }, z.core.$strip>;
3419
3446
  export type ReserveSlugResponse = z.infer<typeof ReserveSlugResponseSchema>;
3447
+ export declare const CheckOrgSuffixAvailableRequestSchema: z.ZodObject<{
3448
+ suffix: z.ZodString;
3449
+ }, z.core.$strip>;
3450
+ export type CheckOrgSuffixAvailableRequest = z.infer<typeof CheckOrgSuffixAvailableRequestSchema>;
3451
+ export declare const CheckOrgSuffixAvailableResponseSchema: z.ZodObject<{
3452
+ available: z.ZodBoolean;
3453
+ }, z.core.$strip>;
3454
+ export type CheckOrgSuffixAvailableResponse = z.infer<typeof CheckOrgSuffixAvailableResponseSchema>;
3420
3455
  export declare const GoldenSnapshotRefreshRequestSchema: z.ZodObject<{
3421
3456
  sourceCommitSha: z.ZodString;
3422
3457
  }, z.core.$strict>;
package/src/projects.js CHANGED
@@ -107,6 +107,23 @@ export const EXAMPLE_OR_STARTER_REPOS = [
107
107
  AGENT_NATIVE_STARTER_REPO,
108
108
  ];
109
109
  export const EXAMPLE_OR_STARTER_REPOS_URLS = EXAMPLE_OR_STARTER_REPOS.map((repo) => `https://github.com/${repo}`);
110
+ /**
111
+ * A run that ended on an unreadable git object database.
112
+ *
113
+ * Reported by the container rather than inferred by the service: a backup-mode
114
+ * launch is only ever observed as a machine that started and exited, so from
115
+ * the outside a corrupt repo and a clean backup look the same.
116
+ */
117
+ export const GitCorruptionReportSchema = z.object({
118
+ /** When the run failed — not when the objects were damaged. */
119
+ at: z.number(),
120
+ error: z.string().max(2000),
121
+ repoPath: z.string().max(500).optional(),
122
+ emptyObjects: z.number().int().nonnegative().max(1000000).optional(),
123
+ recoveryAttempted: z.boolean().optional(),
124
+ recoveryRefetched: z.boolean().optional(),
125
+ devToolsVersion: z.string().max(100).optional(),
126
+ });
110
127
  /** Fields shared by every {@link ProjectSkill} variant. */
111
128
  const ProjectSkillBaseShape = {
112
129
  key: z.string().meta({
@@ -1787,6 +1804,12 @@ export const ReserveSlugRequestSchema = z.object({
1787
1804
  export const ReserveSlugResponseSchema = z.object({
1788
1805
  slug: z.string(),
1789
1806
  });
1807
+ export const CheckOrgSuffixAvailableRequestSchema = z.object({
1808
+ suffix: z.string().min(1),
1809
+ });
1810
+ export const CheckOrgSuffixAvailableResponseSchema = z.object({
1811
+ available: z.boolean(),
1812
+ });
1790
1813
  const gitCommitHashSchema = z
1791
1814
  .string()
1792
1815
  .regex(/^[0-9a-f]{7,40}$/i, "Must be a valid git commit hash (7–40 hex chars)");
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ export declare const SYSTEM_ONE_DEFAULT_MODEL = "jev-latest";
3
+ export declare const SystemOneRequestSchema: z.ZodObject<{
4
+ state: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>;
5
+ model: z.ZodDefault<z.ZodString>;
6
+ questions: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
7
+ type: z.ZodLiteral<"noul">;
8
+ instructions: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>;
9
+ criteria: z.ZodOptional<z.ZodObject<{
10
+ true: z.ZodOptional<z.ZodString>;
11
+ false: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strip>>;
13
+ }, z.core.$loose>, z.ZodObject<{
14
+ type: z.ZodLiteral<"choice">;
15
+ instructions: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>;
16
+ criteria: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
17
+ }, z.core.$loose>, z.ZodObject<{
18
+ type: z.ZodLiteral<"score">;
19
+ instructions: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodUnknown>]>;
20
+ criteria: z.ZodArray<z.ZodString>;
21
+ }, z.core.$loose>], "type">>;
22
+ }, z.core.$loose>;
23
+ export declare const SystemOneResponseSchema: z.ZodObject<{
24
+ model: z.ZodString;
25
+ answers: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
26
+ type: z.ZodLiteral<"noul">;
27
+ noul: z.ZodNumber;
28
+ }, z.core.$loose>, z.ZodObject<{
29
+ type: z.ZodLiteral<"choice">;
30
+ choice: z.ZodString;
31
+ probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
32
+ confidence: z.ZodNumber;
33
+ }, z.core.$loose>, z.ZodObject<{
34
+ type: z.ZodLiteral<"score">;
35
+ score: z.ZodNumber;
36
+ legend: z.ZodRecord<z.ZodString, z.ZodString>;
37
+ probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
38
+ confidence: z.ZodNumber;
39
+ }, z.core.$loose>], "type">>;
40
+ usage: z.ZodObject<{
41
+ input_tokens: z.ZodNumber;
42
+ output_tokens: z.ZodNumber;
43
+ }, z.core.$strip>;
44
+ }, z.core.$loose>;
45
+ export type SystemOneRequest = z.output<typeof SystemOneRequestSchema>;
46
+ export type SystemOneResponse = z.infer<typeof SystemOneResponseSchema>;
@@ -0,0 +1,95 @@
1
+ import { z } from "zod";
2
+ export const SYSTEM_ONE_DEFAULT_MODEL = "jev-latest";
3
+ const SystemOneValueSchema = z.union([
4
+ z.string(),
5
+ z.record(z.string(), z.unknown()),
6
+ z.array(z.unknown()),
7
+ ]);
8
+ const NoulQuestionSchema = z
9
+ .object({
10
+ type: z.literal("noul"),
11
+ instructions: SystemOneValueSchema,
12
+ criteria: z
13
+ .object({
14
+ true: z.string().optional(),
15
+ false: z.string().optional(),
16
+ })
17
+ .optional(),
18
+ })
19
+ .passthrough();
20
+ const ChoiceQuestionSchema = z
21
+ .object({
22
+ type: z.literal("choice"),
23
+ instructions: SystemOneValueSchema,
24
+ criteria: z
25
+ .record(z.string(), z.string().nullable())
26
+ .refine((criteria) => Object.keys(criteria).length > 0, {
27
+ message: "At least one choice is required.",
28
+ }),
29
+ })
30
+ .passthrough();
31
+ const ScoreQuestionSchema = z
32
+ .object({
33
+ type: z.literal("score"),
34
+ instructions: SystemOneValueSchema,
35
+ criteria: z.array(z.string()).min(2),
36
+ })
37
+ .passthrough();
38
+ const SystemOneQuestionSchema = z.discriminatedUnion("type", [
39
+ NoulQuestionSchema,
40
+ ChoiceQuestionSchema,
41
+ ScoreQuestionSchema,
42
+ ]);
43
+ export const SystemOneRequestSchema = z
44
+ .object({
45
+ state: SystemOneValueSchema,
46
+ model: z.string().trim().min(1).default(SYSTEM_ONE_DEFAULT_MODEL),
47
+ questions: z
48
+ .record(z.string().min(1), SystemOneQuestionSchema)
49
+ .refine((questions) => Object.keys(questions).length > 0, {
50
+ message: "At least one question is required.",
51
+ }),
52
+ })
53
+ .passthrough()
54
+ .meta({
55
+ description: "Request body for POST /agent-native/jev/v1/system-one.",
56
+ });
57
+ const ProbabilitySchema = z.number().finite().min(0).max(1);
58
+ const NoulAnswerSchema = z
59
+ .object({
60
+ type: z.literal("noul"),
61
+ noul: ProbabilitySchema,
62
+ })
63
+ .passthrough();
64
+ const ChoiceAnswerSchema = z
65
+ .object({
66
+ type: z.literal("choice"),
67
+ choice: z.string(),
68
+ probabilities: z.record(z.string(), ProbabilitySchema),
69
+ confidence: ProbabilitySchema,
70
+ })
71
+ .passthrough();
72
+ const ScoreAnswerSchema = z
73
+ .object({
74
+ type: z.literal("score"),
75
+ score: z.number().finite(),
76
+ legend: z.record(z.string(), z.string()),
77
+ probabilities: z.record(z.string(), ProbabilitySchema),
78
+ confidence: ProbabilitySchema,
79
+ })
80
+ .passthrough();
81
+ const SystemOneAnswerSchema = z.discriminatedUnion("type", [
82
+ NoulAnswerSchema,
83
+ ChoiceAnswerSchema,
84
+ ScoreAnswerSchema,
85
+ ]);
86
+ export const SystemOneResponseSchema = z
87
+ .object({
88
+ model: z.string(),
89
+ answers: z.record(z.string(), SystemOneAnswerSchema),
90
+ usage: z.object({
91
+ input_tokens: z.number().int().nonnegative(),
92
+ output_tokens: z.number().int().nonnegative(),
93
+ }),
94
+ })
95
+ .passthrough();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { SYSTEM_ONE_DEFAULT_MODEL, SystemOneRequestSchema, SystemOneResponseSchema, } from "./system-one";
3
+ describe("System One schemas", () => {
4
+ it("defaults the model and validates each question type", () => {
5
+ const request = SystemOneRequestSchema.parse({
6
+ state: { ticket: "export failed" },
7
+ questions: {
8
+ urgent: {
9
+ type: "noul",
10
+ instructions: "Is this urgent?",
11
+ },
12
+ team: {
13
+ type: "choice",
14
+ instructions: "Who owns this?",
15
+ criteria: { support: "Customer issue", engineering: null },
16
+ },
17
+ severity: {
18
+ type: "score",
19
+ instructions: "How severe is this?",
20
+ criteria: ["low", "high"],
21
+ },
22
+ },
23
+ });
24
+ expect(request.model).toBe(SYSTEM_ONE_DEFAULT_MODEL);
25
+ });
26
+ it("rejects a score question without two levels", () => {
27
+ expect(() => SystemOneRequestSchema.parse({
28
+ state: "ticket",
29
+ questions: {
30
+ severity: {
31
+ type: "score",
32
+ instructions: "How severe?",
33
+ criteria: ["low"],
34
+ },
35
+ },
36
+ })).toThrow();
37
+ });
38
+ it("validates the structured response", () => {
39
+ expect(SystemOneResponseSchema.parse({
40
+ model: "jev-1.13.0",
41
+ answers: {
42
+ urgent: { type: "noul", noul: 0.8 },
43
+ },
44
+ usage: { input_tokens: 10, output_tokens: 2 },
45
+ }).usage.input_tokens).toBe(10);
46
+ });
47
+ });