@builder.io/ai-utils 0.95.0 → 0.97.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
@@ -62,6 +62,43 @@ export const matchesAgentNativeStarter = (repo) => {
62
62
  return true;
63
63
  return !!((_a = repo.templateRepoUrl) === null || _a === void 0 ? void 0 : _a.includes(AGENT_NATIVE_STARTER_REPO));
64
64
  };
65
+ function isStringRecord(value) {
66
+ return typeof value === "object" && value !== null && !Array.isArray(value);
67
+ }
68
+ export function getManagedDatabasePackageJsonError(content) {
69
+ let packageJson;
70
+ try {
71
+ packageJson = JSON.parse(content);
72
+ }
73
+ catch (_a) {
74
+ return "The managed database root package.json must remain valid JSON.";
75
+ }
76
+ if (!isStringRecord(packageJson)) {
77
+ return "The managed database root package.json must contain a JSON object.";
78
+ }
79
+ const dependencies = packageJson.dependencies;
80
+ const devDependencies = packageJson.devDependencies;
81
+ const hasDrizzleOrm = isStringRecord(dependencies) &&
82
+ typeof dependencies["drizzle-orm"] === "string";
83
+ const hasDrizzleKit = isStringRecord(devDependencies) &&
84
+ typeof devDependencies["drizzle-kit"] === "string";
85
+ if (hasDrizzleOrm && hasDrizzleKit) {
86
+ return undefined;
87
+ }
88
+ return ("Managed database projects require drizzle-orm in root dependencies and drizzle-kit " +
89
+ "in root devDependencies. Preserve both declarations when editing package.json.");
90
+ }
91
+ export function getAgentNativeRootPackageJsonWriteError(args) {
92
+ if (!matchesAgentNativeStarter(args.repo)) {
93
+ return undefined;
94
+ }
95
+ const normalizePath = (value) => value.replace(/\\/g, "/").replace(/\/$/, "");
96
+ const rootPackageJsonPath = `${normalizePath(args.repoPath)}/package.json`;
97
+ if (normalizePath(args.resolvedPath) !== rootPackageJsonPath) {
98
+ return undefined;
99
+ }
100
+ return getManagedDatabasePackageJsonError(args.content);
101
+ }
65
102
  export const EXAMPLE_OR_STARTER_REPOS = [
66
103
  ...EXAMPLE_REPOS,
67
104
  STARTER_REPO,
@@ -234,6 +271,55 @@ export const ListBranchesOptionsSchema = z.object({
234
271
  description: "Superuser-only: list branches for a different owner/org.",
235
272
  }),
236
273
  });
274
+ export const ShapeEffectSchema = z.discriminatedUnion("kind", [
275
+ z.object({
276
+ kind: z.literal("remove-env"),
277
+ scope: z.literal("hosting-prod"),
278
+ key: z.string(),
279
+ }),
280
+ z.object({
281
+ kind: z.literal("attach-design-system"),
282
+ designSystemId: z.string(),
283
+ }),
284
+ ]);
285
+ export const ShapeOptionEffectSchema = z.object({
286
+ instruction: z.string().optional(),
287
+ effects: z.array(ShapeEffectSchema).optional(),
288
+ });
289
+ export const ShapeOptionSchema = z.object({
290
+ id: z.string(),
291
+ label: z.string(),
292
+ effect: ShapeOptionEffectSchema.optional(),
293
+ });
294
+ export const ShapeQuestionSchema = z.object({
295
+ id: z.string(),
296
+ question: z.string(),
297
+ kind: z.enum(["select", "figma-upload"]),
298
+ options: z.array(ShapeOptionSchema),
299
+ guessOptionId: z.string().optional(),
300
+ });
301
+ export const ShapeAnswerSchema = z.object({
302
+ questionId: z.string(),
303
+ optionId: z.string().optional(),
304
+ designSystemId: z.string().optional(),
305
+ skipped: z.boolean(),
306
+ delegated: z.boolean(),
307
+ resolvedFrom: z.enum(["user", "llm"]),
308
+ llmOptionId: z.string().optional(),
309
+ guessOptionId: z.string().optional(),
310
+ });
311
+ export const ShapeSessionSchema = z.object({
312
+ questionnaireId: z.string(),
313
+ catalogVersion: z.string().regex(/^\d{4}-\d{2}-\d{2}\.\d+$/),
314
+ source: z.enum(["static", "agent"]),
315
+ status: z.enum(["assembling", "pending", "resolved"]),
316
+ selection: z.enum(["llm", "fallback"]),
317
+ questions: z.array(ShapeQuestionSchema),
318
+ initialPromptId: z.string(),
319
+ answers: z.array(ShapeAnswerSchema).optional(),
320
+ assembledAt: z.string().optional(),
321
+ resolvedAt: z.string().optional(),
322
+ });
237
323
  export const ProjectRolePermissionsSchema = z
238
324
  .object({
239
325
  view: z.boolean().optional(),
@@ -721,6 +807,9 @@ export const ProjectSettingsSchema = z
721
807
  })
722
808
  .optional()
723
809
  .meta({ description: "Password-protect the preview URL." }),
810
+ shapeSession: ShapeSessionSchema.optional().meta({
811
+ description: "@internal Guided-onboarding questionnaire issued for this project.",
812
+ }),
724
813
  })
725
814
  .meta({ title: "ProjectSettings" });
726
815
  /**
@@ -744,6 +833,7 @@ const INTERNAL_PROJECT_SETTINGS_MASK = {
744
833
  commitInstructions: true,
745
834
  skipCommandSecurity: true,
746
835
  autoCloseBranchOnMerge: true,
836
+ shapeSession: true,
747
837
  };
748
838
  /**
749
839
  * Runtime schema for the client-writable subset of {@link Project.settings},
@@ -848,6 +938,13 @@ export const CreateProjectRequestSchema = z.object({
848
938
  /** Design system ids to seed into project settings at creation. */
849
939
  designSystems: z.array(z.string()).optional(),
850
940
  });
941
+ export function resolveBranchIsPublic(isPublic, defaultBranchType) {
942
+ if (isPublic !== undefined)
943
+ return isPublic;
944
+ if (defaultBranchType === undefined)
945
+ return true;
946
+ return defaultBranchType === "shared";
947
+ }
851
948
  export const MEMORY_PICKED_FIELDS = [
852
949
  "id",
853
950
  "updatedAt",
@@ -1193,6 +1290,44 @@ export const UpdateProjectOptionsSchema = z.object({
1193
1290
  /**
1194
1291
  * A single deploy record, stored at `deploys/{deployId}`. The Deploy.id is the document key.
1195
1292
  */
1293
+ /**
1294
+ * Pipeline step a deploy died at. Set by the pod, the only place that still
1295
+ * knows, so the server can attribute the failure without reading log text.
1296
+ */
1297
+ export const DeployFailureStageSchema = z.enum([
1298
+ "init",
1299
+ "setup",
1300
+ "migrate",
1301
+ "build",
1302
+ "package",
1303
+ "upload",
1304
+ ]);
1305
+ /** `app` is the only value that reaches the agent, so unknowns resolve away from it. */
1306
+ export const DeployFailureOwnerSchema = z.enum(["app", "platform", "unknown"]);
1307
+ /** What the deploy pod reports about a failure. All optional: older pods send none of it. */
1308
+ export const DeployFailureReportSchema = z.object({
1309
+ stage: DeployFailureStageSchema.optional(),
1310
+ exitCode: z.number().optional(),
1311
+ signal: z.string().optional(),
1312
+ excerpt: z.string().optional().meta({
1313
+ description: "Head-and-tail excerpt of the failing output, cut on line boundaries. Event only, never persisted.",
1314
+ }),
1315
+ });
1316
+ export const DeployFailureSchema = z.object({
1317
+ stage: DeployFailureStageSchema.optional(),
1318
+ owner: DeployFailureOwnerSchema,
1319
+ code: z.string().meta({
1320
+ description: "Classifier rule that produced the verdict, e.g. build-command-failed, build-killed, install-network.",
1321
+ }),
1322
+ summary: z.string().meta({
1323
+ description: "One line naming the failure, safe to render in a list row.",
1324
+ }),
1325
+ exitCode: z.number().optional(),
1326
+ signal: z.string().optional(),
1327
+ fixRequested: z.boolean().optional().meta({
1328
+ description: "Whether a Fusion agent fix was dispatched for this failure.",
1329
+ }),
1330
+ });
1196
1331
  export const DeploySchema = z.object({
1197
1332
  id: z.string(),
1198
1333
  projectId: z.string(),
@@ -1247,7 +1382,10 @@ export const DeploySchema = z.object({
1247
1382
  description: "Whether Drizzle migrations were applied during this deploy. Absent when no migration ran.",
1248
1383
  }),
1249
1384
  error: z.string().optional().meta({
1250
- description: "Single human-readable line on failure; raw build logs not surfaced in v0",
1385
+ description: "Head-and-tail excerpt of the failing step's output, ANSI stripped. Bounded because it rides in every deploy-list response.",
1386
+ }),
1387
+ failure: DeployFailureSchema.optional().meta({
1388
+ description: "Structured verdict for a failed deploy: which stage failed and whether the failure is the app's or ours. Absent on deploys from pods that predate it.",
1251
1389
  }),
1252
1390
  createdAt: z.number(),
1253
1391
  completedAt: z.number().optional(),
@@ -1255,6 +1393,19 @@ export const DeploySchema = z.object({
1255
1393
  description: 'user ID for manual publish, or "auto-deploy" (v1)',
1256
1394
  }),
1257
1395
  });
1396
+ /** Values of `Deploy.triggeredBy` that name no real user. */
1397
+ const UNATTENDED_DEPLOY_TRIGGERS = new Set(["auto-deploy", "unknown"]);
1398
+ /**
1399
+ * The user who asked for this deploy, or `undefined` when nobody did. Lives
1400
+ * with the schema so every caller that needs a real user agrees on what counts.
1401
+ */
1402
+ export function deployTriggeringUser(deploy) {
1403
+ var _a;
1404
+ const triggered = (_a = deploy.triggeredBy) === null || _a === void 0 ? void 0 : _a.trim();
1405
+ return triggered && !UNATTENDED_DEPLOY_TRIGGERS.has(triggered)
1406
+ ? triggered
1407
+ : undefined;
1408
+ }
1258
1409
  /**
1259
1410
  * Permanent slug reservation, stored at `hosting-slugs/{slug}` (slug is the document key).
1260
1411
  *
@@ -1348,6 +1499,7 @@ export const DeployListItemSchema = DeploySchema.pick({
1348
1499
  createdAt: true,
1349
1500
  completedAt: true,
1350
1501
  error: true,
1502
+ failure: true,
1351
1503
  checkoutBranch: true,
1352
1504
  checkoutCommit: true,
1353
1505
  builtCommit: true,
@@ -1482,6 +1634,60 @@ export function hasResolvableHostingBuildConfig(overrides) {
1482
1634
  }
1483
1635
  return false;
1484
1636
  }
1637
+ /**
1638
+ * Env vars every hosted deploy gets unless the project sets them itself.
1639
+ *
1640
+ * Recurring jobs default off because Agent Native ships a Netlify scheduled function
1641
+ * that wakes a background sweep every minute for the life of the deploy, even when the
1642
+ * app defines no jobs — enough to keep a scale-to-zero database from ever suspending.
1643
+ * Set `AGENT_NATIVE_DISABLE_RECURRING_JOBS=false` in the build env to opt back in.
1644
+ */
1645
+ export const HOSTED_DEPLOY_ENV_DEFAULTS = {
1646
+ AGENT_NATIVE_DISABLE_RECURRING_JOBS: "true",
1647
+ };
1648
+ /**
1649
+ * Layer `HOSTED_DEPLOY_ENV_DEFAULTS` under a build config's env, project values winning.
1650
+ *
1651
+ * Call only after `hasResolvableHostingBuildConfig` — the defaults would otherwise make
1652
+ * a project with no hosting config look deployable. Keys are trimmed so a padded project
1653
+ * key still wins instead of sitting beside the default the build actually reads.
1654
+ */
1655
+ export function applyHostedBuildEnvDefaults(overrides) {
1656
+ return {
1657
+ ...overrides,
1658
+ environment: {
1659
+ ...HOSTED_DEPLOY_ENV_DEFAULTS,
1660
+ ...normalizeEnvRecordKeys(overrides.environment),
1661
+ },
1662
+ };
1663
+ }
1664
+ /** Trim env keys and drop blank ones, so both env scopes compare keys the same way. */
1665
+ function normalizeEnvRecordKeys(environment) {
1666
+ const normalized = {};
1667
+ for (const [key, value] of Object.entries(environment !== null && environment !== void 0 ? environment : {})) {
1668
+ const trimmed = key.trim();
1669
+ if (trimmed) {
1670
+ normalized[trimmed] = value;
1671
+ }
1672
+ }
1673
+ return normalized;
1674
+ }
1675
+ /**
1676
+ * What a build env resolved each `HOSTED_DEPLOY_ENV_DEFAULTS` key to. The deploy pod
1677
+ * sends this to the service so the runtime env matches what the build compiled against.
1678
+ *
1679
+ * Keys outside `HOSTED_DEPLOY_ENV_DEFAULTS` are dropped, so this is safe to call on an
1680
+ * env record that arrived in an event payload.
1681
+ */
1682
+ export function resolveHostedEnvDefaults(environment) {
1683
+ const resolved = {};
1684
+ for (const [key, value] of Object.entries(normalizeEnvRecordKeys(environment))) {
1685
+ if (Object.hasOwn(HOSTED_DEPLOY_ENV_DEFAULTS, key)) {
1686
+ resolved[key] = value;
1687
+ }
1688
+ }
1689
+ return resolved;
1690
+ }
1485
1691
  /**
1486
1692
  * Request body for `POST /_builder.io/api/build-and-upload` on the deploy pod.
1487
1693
  */
@@ -1751,6 +1957,24 @@ export const CloneProjectOptionsSchema = z.object({
1751
1957
  description: "Whether to provision on cloud-v2 (Kubernetes). Defaults to false.",
1752
1958
  }),
1753
1959
  });
1960
+ export const GetPreferredProjectForRepoOptionsSchema = z.object({
1961
+ repoUrl: z.string().min(1).meta({
1962
+ description: "Full clone URL of the repository to look up.",
1963
+ }),
1964
+ repoFullName: z.string().optional().meta({
1965
+ description: 'Repo in "owner/repo" form; derived from `repoUrl` when omitted.',
1966
+ }),
1967
+ });
1968
+ /** Identity only — this powers a "currently preferred: X" label, not a project read. */
1969
+ export const GetPreferredProjectForRepoResultSchema = z.object({
1970
+ status: z.literal("success"),
1971
+ project: z
1972
+ .object({
1973
+ id: z.string(),
1974
+ name: z.string(),
1975
+ })
1976
+ .nullable(),
1977
+ });
1754
1978
  /**
1755
1979
  * Write-time contract for a single hosted-site access rule. Mirrors the stored
1756
1980
  * {@link SiteAccessRule} in `organization.ts`, except a password rule carries a
@@ -1893,6 +2117,7 @@ export const ProjectTemplateOverridesSchema = z.object({
1893
2117
  sourceProjectId: true,
1894
2118
  sourceBranchName: true,
1895
2119
  }).partial().shape,
2120
+ settings: ProjectSettingsExternalSchema.partial().optional(),
1896
2121
  hosting: ProjectHostingExternalSchema.optional(),
1897
2122
  });
1898
2123
  export const CreateProjectTemplateFromProjectOptionsSchema = z.object({
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { AGENT_NATIVE_STARTER_REPO, matchesAgentNativeStarter, ProjectHostingExternalSchema, ProjectHostingSchema, } from "./projects";
2
+ import { AGENT_NATIVE_STARTER_REPO, getAgentNativeRootPackageJsonWriteError, getManagedDatabasePackageJsonError, matchesAgentNativeStarter, ProjectHostingExternalSchema, ProjectHostingSchema, ProjectSettingsExternalSchema, ProjectSettingsSchema, ProjectTemplateOverridesSchema, ShapeSessionSchema, } 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" });
@@ -11,6 +11,55 @@ describe("project hosting schemas", () => {
11
11
  })).toEqual({ enabled: true });
12
12
  });
13
13
  });
14
+ describe("guided onboarding project settings", () => {
15
+ const shapeSession = {
16
+ questionnaireId: "questionnaire-1",
17
+ catalogVersion: "2026-09-03.1",
18
+ source: "static",
19
+ status: "pending",
20
+ selection: "llm",
21
+ questions: [
22
+ {
23
+ id: "authentication",
24
+ question: "Will users need to login to use your app?",
25
+ kind: "select",
26
+ options: [
27
+ {
28
+ id: "required",
29
+ label: "Yes",
30
+ effect: {
31
+ instruction: "Require users to sign in.",
32
+ effects: [
33
+ {
34
+ kind: "remove-env",
35
+ scope: "hosting-prod",
36
+ key: "AUTH_DISABLED",
37
+ },
38
+ ],
39
+ },
40
+ },
41
+ ],
42
+ },
43
+ ],
44
+ initialPromptId: "prompt-1",
45
+ };
46
+ it("parses a snapshotted questionnaire session", () => {
47
+ expect(ShapeSessionSchema.parse(shapeSession)).toEqual(shapeSession);
48
+ expect(ProjectSettingsSchema.parse({ shapeSession })).toEqual({
49
+ shapeSession,
50
+ });
51
+ });
52
+ it("requires a dated catalog version", () => {
53
+ expect(() => ShapeSessionSchema.parse({
54
+ ...shapeSession,
55
+ catalogVersion: "v1",
56
+ })).toThrow();
57
+ });
58
+ it("does not allow clients to write a shape session", () => {
59
+ expect(ProjectSettingsExternalSchema.parse({ shapeSession })).toEqual({});
60
+ expect(ProjectTemplateOverridesSchema.parse({ settings: { shapeSession } })).toEqual({ settings: {} });
61
+ });
62
+ });
14
63
  describe("matchesAgentNativeStarter", () => {
15
64
  it("matches when repoName is the starter", () => {
16
65
  expect(matchesAgentNativeStarter({ repoName: AGENT_NATIVE_STARTER_REPO })).toBe(true);
@@ -31,3 +80,59 @@ describe("matchesAgentNativeStarter", () => {
31
80
  expect(matchesAgentNativeStarter({})).toBe(false);
32
81
  });
33
82
  });
83
+ describe("getManagedDatabasePackageJsonError", () => {
84
+ it("accepts the required root Drizzle dependencies", () => {
85
+ expect(getManagedDatabasePackageJsonError(JSON.stringify({
86
+ dependencies: { "drizzle-orm": "0.45.2" },
87
+ devDependencies: { "drizzle-kit": "0.31.10" },
88
+ }))).toBeUndefined();
89
+ });
90
+ it.each([
91
+ {
92
+ dependencies: {},
93
+ devDependencies: { "drizzle-kit": "0.31.10" },
94
+ },
95
+ {
96
+ dependencies: { "drizzle-orm": "0.45.2", "drizzle-kit": "0.31.10" },
97
+ devDependencies: {},
98
+ },
99
+ {
100
+ dependencies: {},
101
+ devDependencies: {
102
+ "drizzle-orm": "0.45.2",
103
+ "drizzle-kit": "0.31.10",
104
+ },
105
+ },
106
+ ])("rejects missing or misplaced dependencies", (packageJson) => {
107
+ expect(getManagedDatabasePackageJsonError(JSON.stringify(packageJson))).toContain("Preserve both declarations");
108
+ });
109
+ it("rejects invalid package.json content", () => {
110
+ expect(getManagedDatabasePackageJsonError("not json")).toContain("valid JSON");
111
+ });
112
+ });
113
+ describe("getAgentNativeRootPackageJsonWriteError", () => {
114
+ const repo = { repoName: AGENT_NATIVE_STARTER_REPO };
115
+ const invalidManifest = JSON.stringify({ dependencies: {} });
116
+ it("rejects an invalid resolved root manifest", () => {
117
+ expect(getAgentNativeRootPackageJsonWriteError({
118
+ repo,
119
+ repoPath: "/workspace",
120
+ resolvedPath: "/workspace/package.json",
121
+ content: invalidManifest,
122
+ })).toContain("drizzle-orm");
123
+ });
124
+ it("allows nested and unrelated repository manifests", () => {
125
+ expect(getAgentNativeRootPackageJsonWriteError({
126
+ repo,
127
+ repoPath: "/workspace",
128
+ resolvedPath: "/workspace/apps/web/package.json",
129
+ content: invalidManifest,
130
+ })).toBeUndefined();
131
+ expect(getAgentNativeRootPackageJsonWriteError({
132
+ repo: { repoName: "acme/dashboard" },
133
+ repoPath: "/workspace",
134
+ resolvedPath: "/workspace/package.json",
135
+ content: invalidManifest,
136
+ })).toBeUndefined();
137
+ });
138
+ });
@@ -0,0 +1,149 @@
1
+ import { z } from "zod";
2
+ export declare const PublishAgentSessionCursorSchema: z.ZodObject<{
3
+ updatedAt: z.ZodNumber;
4
+ id: z.ZodString;
5
+ }, z.core.$strip>;
6
+ export type PublishAgentSessionCursor = z.infer<typeof PublishAgentSessionCursorSchema>;
7
+ export declare const PublishAgentSessionsQuerySchema: z.ZodObject<{
8
+ apiKey: z.ZodString;
9
+ sessionId: z.ZodOptional<z.ZodString>;
10
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
11
+ cursor: z.ZodOptional<z.ZodString>;
12
+ completionIdCursor: z.ZodOptional<z.ZodString>;
13
+ archived: z.ZodDefault<z.ZodCodec<z.ZodString, z.ZodBoolean>>;
14
+ }, z.core.$strip>;
15
+ export type PublishAgentSessionsQuery = z.infer<typeof PublishAgentSessionsQuerySchema>;
16
+ /**
17
+ * Body of a session rename and/or archive. The space stays in `?apiKey=` /
18
+ * `x-builder-api-key`, where the request middleware binds it from.
19
+ */
20
+ export declare const PublishAgentSessionUpdateRequestSchema: z.ZodObject<{
21
+ sessionId: z.ZodString;
22
+ title: z.ZodOptional<z.ZodString>;
23
+ archived: z.ZodOptional<z.ZodBoolean>;
24
+ }, z.core.$strip>;
25
+ export type PublishAgentSessionUpdateRequest = z.infer<typeof PublishAgentSessionUpdateRequestSchema>;
26
+ export declare const PublishAgentAttachmentReferenceSchema: z.ZodObject<{
27
+ id: z.ZodOptional<z.ZodString>;
28
+ type: z.ZodString;
29
+ name: z.ZodOptional<z.ZodString>;
30
+ size: z.ZodOptional<z.ZodNumber>;
31
+ }, z.core.$strip>;
32
+ export type PublishAgentAttachmentReference = z.infer<typeof PublishAgentAttachmentReferenceSchema>;
33
+ export declare const PublishAgentToolReferenceSchema: z.ZodObject<{
34
+ id: z.ZodOptional<z.ZodString>;
35
+ name: z.ZodString;
36
+ status: z.ZodEnum<{
37
+ completed: "completed";
38
+ requested: "requested";
39
+ }>;
40
+ }, z.core.$strip>;
41
+ export type PublishAgentToolReference = z.infer<typeof PublishAgentToolReferenceSchema>;
42
+ export declare const PublishAgentSessionMessageSchema: z.ZodObject<{
43
+ id: z.ZodString;
44
+ role: z.ZodEnum<{
45
+ assistant: "assistant";
46
+ user: "user";
47
+ }>;
48
+ senderId: z.ZodOptional<z.ZodString>;
49
+ content: z.ZodOptional<z.ZodString>;
50
+ createdAt: z.ZodNumber;
51
+ status: z.ZodEnum<{
52
+ completed: "completed";
53
+ error: "error";
54
+ running: "running";
55
+ }>;
56
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
57
+ id: z.ZodOptional<z.ZodString>;
58
+ type: z.ZodString;
59
+ name: z.ZodOptional<z.ZodString>;
60
+ size: z.ZodOptional<z.ZodNumber>;
61
+ }, z.core.$strip>>>;
62
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
63
+ id: z.ZodOptional<z.ZodString>;
64
+ name: z.ZodString;
65
+ status: z.ZodEnum<{
66
+ completed: "completed";
67
+ requested: "requested";
68
+ }>;
69
+ }, z.core.$strip>>>;
70
+ }, z.core.$strip>;
71
+ export type PublishAgentSessionMessage = z.infer<typeof PublishAgentSessionMessageSchema>;
72
+ export declare const PublishAgentSessionSummarySchema: z.ZodObject<{
73
+ id: z.ZodString;
74
+ spaceId: z.ZodString;
75
+ createdBy: z.ZodString;
76
+ title: z.ZodNullable<z.ZodString>;
77
+ preview: z.ZodNullable<z.ZodString>;
78
+ archived: z.ZodBoolean;
79
+ createdAt: z.ZodNumber;
80
+ updatedAt: z.ZodNumber;
81
+ lastCompletionId: z.ZodNullable<z.ZodString>;
82
+ totalCompletions: z.ZodNumber;
83
+ numUserMessages: z.ZodNumber;
84
+ }, z.core.$strip>;
85
+ export type PublishAgentSessionSummary = z.infer<typeof PublishAgentSessionSummarySchema>;
86
+ export declare const PublishAgentSessionListResponseSchema: z.ZodObject<{
87
+ sessions: z.ZodArray<z.ZodObject<{
88
+ id: z.ZodString;
89
+ spaceId: z.ZodString;
90
+ createdBy: z.ZodString;
91
+ title: z.ZodNullable<z.ZodString>;
92
+ preview: z.ZodNullable<z.ZodString>;
93
+ archived: z.ZodBoolean;
94
+ createdAt: z.ZodNumber;
95
+ updatedAt: z.ZodNumber;
96
+ lastCompletionId: z.ZodNullable<z.ZodString>;
97
+ totalCompletions: z.ZodNumber;
98
+ numUserMessages: z.ZodNumber;
99
+ }, z.core.$strip>>;
100
+ nextCursor: z.ZodNullable<z.ZodString>;
101
+ }, z.core.$strip>;
102
+ export type PublishAgentSessionListResponse = z.infer<typeof PublishAgentSessionListResponseSchema>;
103
+ export declare const PublishAgentSessionDetailResponseSchema: z.ZodObject<{
104
+ session: z.ZodObject<{
105
+ id: z.ZodString;
106
+ spaceId: z.ZodString;
107
+ createdBy: z.ZodString;
108
+ title: z.ZodNullable<z.ZodString>;
109
+ preview: z.ZodNullable<z.ZodString>;
110
+ archived: z.ZodBoolean;
111
+ createdAt: z.ZodNumber;
112
+ updatedAt: z.ZodNumber;
113
+ lastCompletionId: z.ZodNullable<z.ZodString>;
114
+ totalCompletions: z.ZodNumber;
115
+ numUserMessages: z.ZodNumber;
116
+ }, z.core.$strip>;
117
+ messages: z.ZodArray<z.ZodObject<{
118
+ id: z.ZodString;
119
+ role: z.ZodEnum<{
120
+ assistant: "assistant";
121
+ user: "user";
122
+ }>;
123
+ senderId: z.ZodOptional<z.ZodString>;
124
+ content: z.ZodOptional<z.ZodString>;
125
+ createdAt: z.ZodNumber;
126
+ status: z.ZodEnum<{
127
+ completed: "completed";
128
+ error: "error";
129
+ running: "running";
130
+ }>;
131
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
132
+ id: z.ZodOptional<z.ZodString>;
133
+ type: z.ZodString;
134
+ name: z.ZodOptional<z.ZodString>;
135
+ size: z.ZodOptional<z.ZodNumber>;
136
+ }, z.core.$strip>>>;
137
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
138
+ id: z.ZodOptional<z.ZodString>;
139
+ name: z.ZodString;
140
+ status: z.ZodEnum<{
141
+ completed: "completed";
142
+ requested: "requested";
143
+ }>;
144
+ }, z.core.$strip>>>;
145
+ }, z.core.$strip>>;
146
+ messagesCanLoadMore: z.ZodBoolean;
147
+ messagesNextCursor: z.ZodNullable<z.ZodString>;
148
+ }, z.core.$strip>;
149
+ export type PublishAgentSessionDetailResponse = z.infer<typeof PublishAgentSessionDetailResponseSchema>;
@@ -0,0 +1,88 @@
1
+ import { z } from "zod";
2
+ export const PublishAgentSessionCursorSchema = z
3
+ .object({
4
+ updatedAt: z.number().int(),
5
+ id: z.string().min(1),
6
+ })
7
+ .meta({ title: "PublishAgentSessionCursor" });
8
+ export const PublishAgentSessionsQuerySchema = z
9
+ .object({
10
+ apiKey: z.string().min(1).max(256),
11
+ sessionId: z.string().min(1).max(256).optional(),
12
+ limit: z.coerce.number().int().min(1).max(50).default(20),
13
+ cursor: z.string().min(1).max(2048).optional(),
14
+ completionIdCursor: z.string().min(1).max(256).optional(),
15
+ /** Lists archived sessions instead of active ones. Ignored for a detail read. */
16
+ archived: z.stringbool().default(false),
17
+ })
18
+ .meta({ title: "PublishAgentSessionsQuery" });
19
+ /**
20
+ * Body of a session rename and/or archive. The space stays in `?apiKey=` /
21
+ * `x-builder-api-key`, where the request middleware binds it from.
22
+ */
23
+ export const PublishAgentSessionUpdateRequestSchema = z
24
+ .object({
25
+ sessionId: z.string().min(1).max(256),
26
+ title: z.string().trim().min(1).max(200).optional(),
27
+ archived: z.boolean().optional(),
28
+ })
29
+ .refine((body) => body.title !== undefined || body.archived !== undefined, {
30
+ message: "Provide title, archived, or both.",
31
+ })
32
+ .meta({ title: "PublishAgentSessionUpdateRequest" });
33
+ export const PublishAgentAttachmentReferenceSchema = z
34
+ .object({
35
+ id: z.string().optional(),
36
+ type: z.string(),
37
+ name: z.string().optional(),
38
+ size: z.number().optional(),
39
+ })
40
+ .meta({ title: "PublishAgentAttachmentReference" });
41
+ export const PublishAgentToolReferenceSchema = z
42
+ .object({
43
+ id: z.string().optional(),
44
+ name: z.string(),
45
+ status: z.enum(["requested", "completed"]),
46
+ })
47
+ .meta({ title: "PublishAgentToolReference" });
48
+ export const PublishAgentSessionMessageSchema = z
49
+ .object({
50
+ id: z.string(),
51
+ role: z.enum(["user", "assistant"]),
52
+ senderId: z.string().optional(),
53
+ content: z.string().optional(),
54
+ createdAt: z.number(),
55
+ status: z.enum(["completed", "running", "error"]),
56
+ attachments: z.array(PublishAgentAttachmentReferenceSchema).optional(),
57
+ tools: z.array(PublishAgentToolReferenceSchema).optional(),
58
+ })
59
+ .meta({ title: "PublishAgentSessionMessage" });
60
+ export const PublishAgentSessionSummarySchema = z
61
+ .object({
62
+ id: z.string(),
63
+ spaceId: z.string(),
64
+ createdBy: z.string(),
65
+ title: z.string().nullable(),
66
+ preview: z.string().nullable(),
67
+ archived: z.boolean(),
68
+ createdAt: z.number(),
69
+ updatedAt: z.number(),
70
+ lastCompletionId: z.string().nullable(),
71
+ totalCompletions: z.number(),
72
+ numUserMessages: z.number(),
73
+ })
74
+ .meta({ title: "PublishAgentSessionSummary" });
75
+ export const PublishAgentSessionListResponseSchema = z
76
+ .object({
77
+ sessions: z.array(PublishAgentSessionSummarySchema),
78
+ nextCursor: z.string().nullable(),
79
+ })
80
+ .meta({ title: "PublishAgentSessionListResponse" });
81
+ export const PublishAgentSessionDetailResponseSchema = z
82
+ .object({
83
+ session: PublishAgentSessionSummarySchema,
84
+ messages: z.array(PublishAgentSessionMessageSchema),
85
+ messagesCanLoadMore: z.boolean(),
86
+ messagesNextCursor: z.string().nullable(),
87
+ })
88
+ .meta({ title: "PublishAgentSessionDetailResponse" });
@@ -132,6 +132,8 @@ export type LastIndexInput = {
132
132
  export interface DesignSystem {
133
133
  id: string;
134
134
  spaceId: string;
135
+ /** Additional spaces a space-scoped design system is shared with, beyond spaceId. */
136
+ spaceIds?: string[];
135
137
  rootOrgId: string;
136
138
  createdDate: Date;
137
139
  createdByUserId: string;