rivet-design 0.26.1 → 0.27.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.
Files changed (122) hide show
  1. package/bin/rivet.js +13 -0
  2. package/dist/agent-variants/PreviewRuntime.js +20 -7
  3. package/dist/agent-variants/WorkerExecutorService.d.ts +0 -2
  4. package/dist/agent-variants/WorkerExecutorService.js +0 -18
  5. package/dist/agent-variants/WorktreeOrchestrator.testHelpers.js +0 -8
  6. package/dist/agent-variants/contracts.d.ts +1001 -4868
  7. package/dist/agent-variants/contracts.js +1 -121
  8. package/dist/agent-variants/index.d.ts +1 -1
  9. package/dist/agent-variants/variantsTelemetry.d.ts +4 -8
  10. package/dist/agent-variants/variantsTelemetry.js +3 -0
  11. package/dist/agent-variants/workItemInput.d.ts +386 -386
  12. package/dist/cli/commands/contextRequest.js +1 -1
  13. package/dist/cli/commands/guidanceReferences.d.ts +2 -2
  14. package/dist/cli/commands/guidanceVerifierPackage.d.ts +2 -2
  15. package/dist/cli/commands/mcpServe.js +1 -0
  16. package/dist/cli/commands/serve.js +2 -0
  17. package/dist/cli/editorSession.d.ts +1 -13
  18. package/dist/cli/handoff.d.ts +1 -0
  19. package/dist/cli/handoff.js +20 -4
  20. package/dist/cli/router.js +1 -0
  21. package/dist/cli/runtimeInterruption.d.ts +2 -16
  22. package/dist/cli/telemetry.d.ts +10 -0
  23. package/dist/cli/telemetry.js +37 -1
  24. package/dist/config/pluginMetrics.js +36 -1
  25. package/dist/hosts/workerDefaults.d.ts +0 -11
  26. package/dist/hosts/workerDefaults.js +1 -30
  27. package/dist/index-core.d.ts +0 -1
  28. package/dist/index.d.ts +19 -0
  29. package/dist/index.js +15 -6
  30. package/dist/install/automaticCliUpdate.d.ts +1 -0
  31. package/dist/install/automaticCliUpdate.js +32 -22
  32. package/dist/install/channelCli.d.ts +1 -1
  33. package/dist/install/channelCli.js +11 -6
  34. package/dist/install/channelManager.d.ts +5 -2
  35. package/dist/install/globalBootstrap.d.ts +5 -3
  36. package/dist/install/globalBootstrap.js +21 -9
  37. package/dist/install/npmCommand.d.ts +15 -0
  38. package/dist/install/npmCommand.js +59 -0
  39. package/dist/routes/agentVariants.js +3 -14
  40. package/dist/routes/library/browserAccess.js +6 -2
  41. package/dist/routes/library/guidance.js +3 -1
  42. package/dist/routes/library/middleware.js +15 -9
  43. package/dist/routes/library/navigation.js +3 -1
  44. package/dist/routes/library/profiles.js +5 -5
  45. package/dist/routes/library/projects.js +17 -7
  46. package/dist/routes/library/referenceOnboarding.js +4 -2
  47. package/dist/routes/library/schemas.d.ts +2 -15
  48. package/dist/routes/telemetry.js +1 -1
  49. package/dist/routes/variantRequestSchema.d.ts +4 -4
  50. package/dist/routes/variantRequestSchema.js +7 -2
  51. package/dist/server.js +8 -0
  52. package/dist/services/AuthService.d.ts +3 -56
  53. package/dist/services/AuthService.js +0 -28
  54. package/dist/services/ConfigManager.d.ts +0 -2
  55. package/dist/services/ConfigManager.js +0 -14
  56. package/dist/services/DependencyPreparationService.js +57 -19
  57. package/dist/services/GuidanceVerifierRunner.js +4 -4
  58. package/dist/services/HubDiscovery.d.ts +1 -9
  59. package/dist/services/IntegrationsClient.d.ts +16 -16
  60. package/dist/services/MCPOnboardingTelemetry.d.ts +0 -14
  61. package/dist/services/MCPOnboardingTelemetry.js +0 -62
  62. package/dist/services/ProjectPackageManager.d.ts +5 -0
  63. package/dist/services/ProjectPackageManager.js +33 -11
  64. package/dist/services/ProjectRegistry.d.ts +5 -24
  65. package/dist/services/TelemetryService.d.ts +9 -64
  66. package/dist/services/TelemetryService.js +10 -113
  67. package/dist/services/TreeStore.d.ts +0 -2
  68. package/dist/services/TreeStore.js +0 -24
  69. package/dist/services/WorktreeManager.js +5 -0
  70. package/dist/services/profiles/DesignProfiles.d.ts +180 -125
  71. package/dist/services/profiles/DesignProfiles.js +16 -8
  72. package/dist/services/profiles/ProfilePlanning.d.ts +38 -38
  73. package/dist/services/profiles/ReferenceReader.d.ts +14 -14
  74. package/dist/services/profiles/modelContract.js +4 -4
  75. package/dist/storage/library/ProjectPreviewCache.d.ts +1 -13
  76. package/dist/storage/profiles/ProfilePlans.d.ts +137 -137
  77. package/dist/storage/profiles/ProfileRecords.d.ts +62 -37
  78. package/dist/storage/profiles/planSchema.d.ts +40 -40
  79. package/dist/storage/profiles/schema.d.ts +16 -16
  80. package/dist/types/api-responses.d.ts +174 -0
  81. package/dist/types/api-responses.js +108 -0
  82. package/dist/types/cosmos-profile.d.ts +17 -105
  83. package/dist/types/cosmos.d.ts +48 -266
  84. package/dist/types/design-library.d.ts +230 -61
  85. package/dist/types/design-library.js +38 -1
  86. package/dist/types/design-profile.d.ts +220 -529
  87. package/dist/types/design-profile.js +5 -1
  88. package/dist/types/guidance-references.d.ts +68 -316
  89. package/dist/types/guidance-verifier.d.ts +69 -560
  90. package/dist/types/guidance-verifier.js +15 -2
  91. package/dist/types/guidance.d.ts +182 -1643
  92. package/dist/types/guidance.js +4 -1
  93. package/dist/types/project-library.d.ts +60 -30
  94. package/dist/types/project-library.js +32 -1
  95. package/dist/types/reference-connectors.d.ts +38 -162
  96. package/dist/types/reference-onboarding.d.ts +144 -878
  97. package/dist/types/reference-pages.d.ts +27 -139
  98. package/dist/types/x-bookmarks.d.ts +40 -296
  99. package/dist/utils/devServerError.d.ts +5 -0
  100. package/dist/utils/devServerError.js +4 -0
  101. package/dist/utils/displayLocale.d.ts +0 -1
  102. package/dist/utils/displayLocale.js +1 -3
  103. package/dist/utils/failureReason.d.ts +16 -0
  104. package/dist/utils/failureReason.js +106 -0
  105. package/dist/utils/hostedLogPrivacy.d.ts +1 -0
  106. package/dist/utils/hostedLogPrivacy.js +10 -4
  107. package/dist/utils/skills/claude-skill.d.ts +1 -1
  108. package/dist/utils/skills/claude-skill.js +1 -1
  109. package/dist/utils/skills/cli-guidance.d.ts +1 -1
  110. package/dist/utils/skills/cli-guidance.js +3 -3
  111. package/dist/utils/skills/cursor-rules.d.ts +1 -1
  112. package/dist/utils/skills/cursor-rules.js +1 -1
  113. package/package.json +5 -5
  114. package/src/ui/dist/assets/LibraryEntry-RI9Lc7P3.js +37 -0
  115. package/src/ui/dist/assets/main-D0UmAaUe.css +1 -0
  116. package/src/ui/dist/assets/main-DgrLzS5j.js +497 -0
  117. package/src/ui/dist/index.html +2 -2
  118. package/dist/types/change-types.d.ts +0 -66
  119. package/dist/types/change-types.js +0 -3
  120. package/src/ui/dist/assets/LibraryEntry-Cr4GFYXW.js +0 -37
  121. package/src/ui/dist/assets/main-W3oTuTTl.css +0 -1
  122. package/src/ui/dist/assets/main-tPO1OCpZ.js +0 -439
@@ -9,8 +9,8 @@ const os_1 = __importDefault(require("os"));
9
9
  const subprocessEnvironment_1 = require("../utils/subprocessEnvironment");
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const channelManager_1 = require("./channelManager");
12
+ const npmCommand_1 = require("./npmCommand");
12
13
  const errorMessage_1 = require("../utils/errorMessage");
13
- const packageManagerProcess_1 = require("../services/packageManagerProcess");
14
14
  const CHANNEL_USAGE = `Rivet channel QA
15
15
 
16
16
  Usage:
@@ -22,8 +22,11 @@ Usage:
22
22
 
23
23
  Hosts: claude, claude-desktop, cursor, codex, all
24
24
  `;
25
- const resolveGlobalPrefix = () => {
26
- const result = (0, packageManagerProcess_1.spawnProcessSync)({ packageManager: 'npm', args: ['prefix', '--global'] }, { env: (0, subprocessEnvironment_1.subprocessEnvironment)('packageManager') });
25
+ const resolveGlobalPrefix = async () => {
26
+ const result = await (0, npmCommand_1.runNpm)({
27
+ args: ['prefix', '--global'],
28
+ env: (0, subprocessEnvironment_1.subprocessEnvironment)('packageManager'),
29
+ });
27
30
  if (result.error || result.status !== 0 || !result.stdout.trim()) {
28
31
  throw new Error('Could not resolve the global npm prefix');
29
32
  }
@@ -37,11 +40,11 @@ const printStatus = (channels) => {
37
40
  console.log(`Local: ${status.local.isAvailable ? (status.local.version ?? 'unknown version') : 'not built'} (${status.local.revision ?? 'unknown revision'})`);
38
41
  console.log(`Production: ${status.production.isAvailable ? (status.production.version ?? 'unknown version') : 'not installed'}`);
39
42
  };
40
- const runChannelCli = (args) => {
43
+ const runChannelCli = async (args) => {
41
44
  try {
42
45
  const repoRoot = path_1.default.resolve(__dirname, '..', '..');
43
46
  const channels = new channelManager_1.RivetChannels({
44
- globalPrefix: resolveGlobalPrefix(),
47
+ globalPrefix: await resolveGlobalPrefix(),
45
48
  homeDirectory: os_1.default.homedir(),
46
49
  repoRoot,
47
50
  });
@@ -92,6 +95,8 @@ const runChannelCli = (args) => {
92
95
  };
93
96
  exports.runChannelCli = runChannelCli;
94
97
  if (require.main === module) {
95
- process.exitCode = (0, exports.runChannelCli)(process.argv.slice(2));
98
+ void (0, exports.runChannelCli)(process.argv.slice(2)).then((exitCode) => {
99
+ process.exitCode = exitCode;
100
+ });
96
101
  }
97
102
  //# sourceMappingURL=channelCli.js.map
@@ -1,8 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import { type ProcessCommand } from '../services/packageManagerProcess';
3
- declare const RivetChannelSchema: z.ZodEnum<["local", "production"]>;
3
+ declare const RivetChannelSchema: z.ZodEnum<{
4
+ production: "production";
5
+ local: "local";
6
+ }>;
4
7
  export type RivetChannel = z.infer<typeof RivetChannelSchema>;
5
- export type ChannelCommandOptions = {
8
+ type ChannelCommandOptions = {
6
9
  cwd?: string;
7
10
  env?: NodeJS.ProcessEnv;
8
11
  };
@@ -1,10 +1,11 @@
1
1
  import { type ProcessCommand } from '../services/packageManagerProcess';
2
2
  export type BootstrapExec = (command: ProcessCommand, options: {
3
+ env: NodeJS.ProcessEnv;
3
4
  stdio: 'inherit' | 'pipe';
4
- }) => {
5
+ }) => Promise<{
5
6
  status: number | null;
6
7
  stdout?: string;
7
- };
8
+ }>;
8
9
  export type BootstrapResult = {
9
10
  action: 'not_needed';
10
11
  } | {
@@ -17,7 +18,8 @@ export type BootstrapResult = {
17
18
  export declare const bootstrapGlobalInstall: (installArgs: string[], options?: {
18
19
  exec?: BootstrapExec;
19
20
  binPath?: string;
21
+ env?: NodeJS.ProcessEnv;
20
22
  version?: string;
21
- }) => BootstrapResult;
23
+ }) => Promise<BootstrapResult>;
22
24
  export declare const bootstrapFailureAdvisory: (reason: string) => string;
23
25
  //# sourceMappingURL=globalBootstrap.d.ts.map
@@ -8,36 +8,48 @@ const fs_1 = __importDefault(require("fs"));
8
8
  const subprocessEnvironment_1 = require("../utils/subprocessEnvironment");
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const mcpRegistration_1 = require("./mcpRegistration");
11
+ const npmCommand_1 = require("./npmCommand");
11
12
  const telemetry_1 = require("../config/telemetry");
12
13
  const errorMessage_1 = require("../utils/errorMessage");
13
14
  const packageManagerProcess_1 = require("../services/packageManagerProcess");
14
- const defaultExec = (command, options) => {
15
+ const defaultExec = async (command, { env, stdio }) => {
16
+ if ('packageManager' in command && command.packageManager === 'npm') {
17
+ const result = await (0, npmCommand_1.runNpm)({
18
+ args: command.args,
19
+ env: (0, subprocessEnvironment_1.subprocessEnvironment)('packageManager', env),
20
+ stdio,
21
+ });
22
+ if (result.error)
23
+ throw result.error;
24
+ return { status: result.status, stdout: result.stdout };
25
+ }
15
26
  const result = (0, packageManagerProcess_1.spawnProcessSync)(command, {
16
- ...options,
17
- env: (0, subprocessEnvironment_1.subprocessEnvironment)('packageManager' in command ? 'packageManager' : 'rivetRuntime'),
27
+ stdio,
28
+ env: (0, subprocessEnvironment_1.subprocessEnvironment)('packageManager' in command ? 'packageManager' : 'rivetRuntime', env),
18
29
  });
19
30
  if (result.error)
20
31
  throw result.error;
21
32
  return { status: result.status, stdout: result.stdout ?? undefined };
22
33
  };
23
- const bootstrapGlobalInstall = (installArgs, options) => {
34
+ const bootstrapGlobalInstall = async (installArgs, options) => {
24
35
  const exec = options?.exec ?? defaultExec;
36
+ const env = options?.env ?? process.env;
25
37
  if (!(0, mcpRegistration_1.isEphemeralNpxInstall)(options?.binPath)) {
26
38
  return { action: 'not_needed' };
27
39
  }
28
- const spec = process.env.RIVET_GLOBAL_INSTALL_SPEC ??
40
+ const spec = env.RIVET_GLOBAL_INSTALL_SPEC ??
29
41
  `rivet-design@${options?.version ?? telemetry_1.RIVET_VERSION}`;
30
42
  console.log(`Rivet is running from npx's temporary cache — installing ${spec} globally first so ` +
31
43
  'MCP registrations and `rivet` commands keep working...\n');
32
44
  try {
33
- const installResult = exec({ packageManager: 'npm', args: ['install', '-g', spec] }, { stdio: 'inherit' });
45
+ const installResult = await exec({ packageManager: 'npm', args: ['install', '-g', spec] }, { env, stdio: 'inherit' });
34
46
  if (installResult.status !== 0) {
35
47
  return {
36
48
  action: 'failed',
37
49
  reason: `npm install -g exited ${installResult.status}`,
38
50
  };
39
51
  }
40
- const rootResult = exec({ packageManager: 'npm', args: ['root', '-g'] }, { stdio: 'pipe' });
52
+ const rootResult = await exec({ packageManager: 'npm', args: ['root', '-g'] }, { env, stdio: 'pipe' });
41
53
  const globalRoot = String(rootResult.stdout ?? '').trim();
42
54
  const globalBin = path_1.default.join(globalRoot, 'rivet-design', 'bin', 'rivet.js');
43
55
  if (!globalRoot || !fs_1.default.existsSync(globalBin)) {
@@ -46,10 +58,10 @@ const bootstrapGlobalInstall = (installArgs, options) => {
46
58
  reason: `global install not found at ${globalBin || 'npm root -g'}`,
47
59
  };
48
60
  }
49
- const rerun = exec({
61
+ const rerun = await exec({
50
62
  executable: process.execPath,
51
63
  args: [globalBin, 'install', ...installArgs],
52
- }, { stdio: 'inherit' });
64
+ }, { env, stdio: 'inherit' });
53
65
  return { action: 'reexeced', exitCode: rerun.status ?? 0 };
54
66
  }
55
67
  catch (error) {
@@ -0,0 +1,15 @@
1
+ export type NpmCommandResult = {
2
+ error?: Error;
3
+ isTimedOut: boolean;
4
+ status: number | null;
5
+ stderr: string;
6
+ stdout: string;
7
+ };
8
+ export declare const runNpm: ({ args, env, onStarted, stdio, timeoutMs, }: {
9
+ args: string[];
10
+ env: NodeJS.ProcessEnv;
11
+ onStarted?: (processId: number) => void;
12
+ stdio?: "inherit" | "pipe";
13
+ timeoutMs?: number;
14
+ }) => Promise<NpmCommandResult>;
15
+ //# sourceMappingURL=npmCommand.d.ts.map
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runNpm = void 0;
4
+ const OperatingSystemServices_1 = require("../services/OperatingSystemServices");
5
+ const packageManagerProcess_1 = require("../services/packageManagerProcess");
6
+ const runNpm = ({ args, env, onStarted, stdio = 'pipe', timeoutMs, }) => new Promise((resolve) => {
7
+ const { operatingSystemFamily, projectProcesses } = OperatingSystemServices_1.selectedOperatingSystemServices;
8
+ const isProcessGroupLeader = timeoutMs !== undefined && operatingSystemFamily === 'posix';
9
+ let stdout = '';
10
+ let stderr = '';
11
+ let isTimedOut = false;
12
+ let spawnError;
13
+ const child = (0, packageManagerProcess_1.spawnProcess)({ packageManager: 'npm', args }, {
14
+ detached: isProcessGroupLeader,
15
+ env,
16
+ stdio: stdio === 'inherit' ? 'inherit' : ['ignore', 'pipe', 'pipe'],
17
+ });
18
+ if (child.pid !== undefined)
19
+ onStarted?.(child.pid);
20
+ child.stdout?.setEncoding('utf8');
21
+ child.stdout?.on('data', (chunk) => {
22
+ stdout += chunk;
23
+ });
24
+ child.stderr?.setEncoding('utf8');
25
+ child.stderr?.on('data', (chunk) => {
26
+ stderr += chunk;
27
+ });
28
+ child.on('error', (error) => {
29
+ spawnError = error;
30
+ stderr += error.message;
31
+ });
32
+ const stopProcessTree = async () => {
33
+ if (isProcessGroupLeader && child.pid !== undefined) {
34
+ process.kill(-child.pid, 'SIGTERM');
35
+ return;
36
+ }
37
+ await projectProcesses.terminate(child, { isForceful: false, env });
38
+ };
39
+ const timeout = timeoutMs === undefined
40
+ ? undefined
41
+ : setTimeout(() => {
42
+ isTimedOut = true;
43
+ stopProcessTree().catch((error) => {
44
+ stderr += String(error);
45
+ });
46
+ }, timeoutMs);
47
+ child.once('close', (status) => {
48
+ clearTimeout(timeout);
49
+ resolve({
50
+ error: spawnError,
51
+ isTimedOut,
52
+ status: isTimedOut ? null : status,
53
+ stderr,
54
+ stdout,
55
+ });
56
+ });
57
+ });
58
+ exports.runNpm = runNpm;
59
+ //# sourceMappingURL=npmCommand.js.map
@@ -21,6 +21,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
21
21
  const path_1 = __importDefault(require("path"));
22
22
  const express_1 = require("express");
23
23
  const v3_1 = require("zod/v3");
24
+ const api_responses_1 = require("../types/api-responses");
24
25
  const logger_1 = require("../utils/logger");
25
26
  const agent_variants_1 = require("../agent-variants");
26
27
  const changeBatchClassification_1 = require("../mcp/changeBatchClassification");
@@ -154,22 +155,10 @@ const renameRunBody = v3_1.z.object({
154
155
  label: renameLabelSchema,
155
156
  projectPath: v3_1.z.string().optional(),
156
157
  });
157
- const uiStateKeySchema = v3_1.z.string().min(1).max(500);
158
- const uiStateSchema = v3_1.z.object({
159
- pinned: v3_1.z.array(uiStateKeySchema).max(1000),
160
- order: v3_1.z.object({
161
- groups: v3_1.z.array(uiStateKeySchema).max(1000),
162
- rows: v3_1.z.record(v3_1.z.array(uiStateKeySchema).max(1000)),
163
- }),
164
- });
165
158
  const EMPTY_UI_STATE = {
166
159
  pinned: [],
167
160
  order: { groups: [], rows: {} },
168
161
  };
169
- const uiStatePutBody = v3_1.z.object({
170
- uiState: uiStateSchema,
171
- projectPath: v3_1.z.string().optional(),
172
- });
173
162
  const HISTORY_STATUSES = new Set([
174
163
  'completed',
175
164
  'committed',
@@ -1218,7 +1207,7 @@ const createAgentVariantsRouter = (orchestrator, bridge, telemetry, variantHisto
1218
1207
  }
1219
1208
  catch { }
1220
1209
  }
1221
- const parsed = uiStateSchema.safeParse(stored);
1210
+ const parsed = api_responses_1.VariantsUiStateSchema.safeParse(stored);
1222
1211
  res.json({
1223
1212
  projectPath,
1224
1213
  uiState: parsed.success ? parsed.data : EMPTY_UI_STATE,
@@ -1231,7 +1220,7 @@ const createAgentVariantsRouter = (orchestrator, bridge, telemetry, variantHisto
1231
1220
  router.put('/variants/ui-state', async (req, res) => {
1232
1221
  if (rejectNonLocalRequest(req, res))
1233
1222
  return;
1234
- const parsed = uiStatePutBody.safeParse(req.body);
1223
+ const parsed = api_responses_1.VariantsUiStateUpdateSchema.safeParse(req.body);
1235
1224
  if (!parsed.success) {
1236
1225
  res.status(400).json({
1237
1226
  errorCode: 'SCHEMA_VALIDATION_FAILED',
@@ -28,7 +28,9 @@ const createBrowserAccessRouter = ({ token, sessions, telemetry, }) => {
28
28
  profile = await (0, AuthService_1.validateAccessToken)(sessions.config.getProxyUrl(), parsed.data.token);
29
29
  }
30
30
  catch {
31
- return res.status(502).json({ error: 'Could not verify Google sign-in' });
31
+ return res.status(502).json({
32
+ error: 'Could not verify Google sign-in',
33
+ });
32
34
  }
33
35
  if (!profile)
34
36
  return res.sendStatus(401);
@@ -68,7 +70,9 @@ const createBrowserAccessRouter = ({ token, sessions, telemetry, }) => {
68
70
  });
69
71
  const handleError = (error, _req, res, _next) => {
70
72
  if (error instanceof BrowserAuthorizationRecords_1.AuthorizationChanged)
71
- return res.status(409).json({ error: error.message });
73
+ return res
74
+ .status(409)
75
+ .json({ error: error.message });
72
76
  res.status(503).json({
73
77
  error: 'Browser authorization is unavailable. Please retry or sign in again.',
74
78
  });
@@ -59,7 +59,9 @@ const createGuidanceRoutes = (profiles, telemetry) => {
59
59
  .json({ guidance, ...(guidanceWarning ? { guidanceWarning } : {}) });
60
60
  });
61
61
  router.post('/guidance/resolutions', async (req, res) => {
62
- const { accountId, ...input } = zod_1.z.record(zod_1.z.unknown()).parse(req.body);
62
+ const { accountId, ...input } = zod_1.z
63
+ .record(zod_1.z.string(), zod_1.z.unknown())
64
+ .parse(req.body);
63
65
  const selection = guidance_1.GuidanceSelectionSchema.parse(input);
64
66
  const headerAccountId = callerAccount(req);
65
67
  const bodyAccountId = zod_1.z.string().min(1).optional().parse(accountId);
@@ -37,9 +37,7 @@ const authenticateLibrary = (token, sessions) => (req, res, next) => {
37
37
  }
38
38
  }
39
39
  catch {
40
- res
41
- .status(503)
42
- .json({
40
+ res.status(503).json({
43
41
  error: 'Browser authorization is unavailable. Please retry or sign in again.',
44
42
  });
45
43
  return;
@@ -47,13 +45,18 @@ const authenticateLibrary = (token, sessions) => (req, res, next) => {
47
45
  next();
48
46
  };
49
47
  exports.authenticateLibrary = authenticateLibrary;
48
+ const HANDLED_ERROR_KEY = 'libraryError';
50
49
  const trackLibraryOperation = (telemetry) => (operation) => (_req, res, next) => {
51
50
  const startedAt = Date.now();
52
- res.once('finish', () => telemetry?.trackLibraryOperation({
53
- operation,
54
- outcome: res.statusCode < 400 ? 'completed' : 'failed',
55
- durationMs: Date.now() - startedAt,
56
- }));
51
+ res.once('finish', () => {
52
+ const isCompleted = res.statusCode < 400;
53
+ telemetry?.trackLibraryOperation({
54
+ operation,
55
+ outcome: isCompleted ? 'completed' : 'failed',
56
+ durationMs: Date.now() - startedAt,
57
+ error: isCompleted ? undefined : res.locals[HANDLED_ERROR_KEY],
58
+ });
59
+ });
57
60
  next();
58
61
  };
59
62
  exports.trackLibraryOperation = trackLibraryOperation;
@@ -75,9 +78,12 @@ const libraryErrorStatus = (code) => {
75
78
  }
76
79
  };
77
80
  const handleLibraryError = (error, _req, res, _next) => {
81
+ res.locals[HANDLED_ERROR_KEY] = error;
78
82
  const message = (0, errorMessage_1.errorMessage)(error);
79
83
  if (error instanceof libraryErrors_1.LibraryError) {
80
- res.status(libraryErrorStatus(error.code)).json({ error: message });
84
+ res
85
+ .status(libraryErrorStatus(error.code))
86
+ .json({ error: message });
81
87
  return;
82
88
  }
83
89
  if (error instanceof zod_1.z.ZodError) {
@@ -22,7 +22,9 @@ const createNavigationRoutes = ({ library, navigation, track, }) => {
22
22
  router.put('/views/:viewId', (req, res) => {
23
23
  const body = zod_1.z.object({ isFocused: zod_1.z.boolean() }).parse(req.body);
24
24
  navigation.connect({ viewId: req.params.viewId, ...body });
25
- res.json({ navigations: navigation.pending(req.params.viewId) });
25
+ res.json({
26
+ navigations: navigation.pending(req.params.viewId),
27
+ });
26
28
  });
27
29
  router.post('/views/:viewId/acknowledgements', (req, res) => {
28
30
  const { sequence } = zod_1.z
@@ -65,7 +65,7 @@ const createProfileRoutes = (profiles, telemetry) => {
65
65
  next();
66
66
  });
67
67
  router.get('/profile', async (_req, res) => {
68
- res.json(await profiles.status());
68
+ res.json((await profiles.status()));
69
69
  });
70
70
  router.get('/profile/diagnostics', async (_req, res) => {
71
71
  res.json(await profiles.diagnostics());
@@ -127,11 +127,11 @@ const createProfileRoutes = (profiles, telemetry) => {
127
127
  if (input.isEnabled) {
128
128
  res
129
129
  .status(202)
130
- .json(await profiles.enable(design_profile_1.ProfileRuntimeSchema.parse(input.runtime)));
130
+ .json((await profiles.enable(design_profile_1.ProfileRuntimeSchema.parse(input.runtime))));
131
131
  return;
132
132
  }
133
133
  await profiles.disable();
134
- res.json(await profiles.status());
134
+ res.json((await profiles.status()));
135
135
  });
136
136
  router.get('/profile/references', async (req, res) => {
137
137
  res.json({
@@ -140,11 +140,11 @@ const createProfileRoutes = (profiles, telemetry) => {
140
140
  });
141
141
  router.get('/profile/library', async (_req, res) => {
142
142
  res.setHeader('Cache-Control', 'private, no-store');
143
- res.json(await profiles.library());
143
+ res.json((await profiles.library()));
144
144
  });
145
145
  router.post('/profile/search', async (req, res) => {
146
146
  res.setHeader('Cache-Control', 'private, no-store');
147
- res.json(await profiles.search(design_library_1.DesignReferenceSearchRequestSchema.parse(req.body)));
147
+ res.json((await profiles.search(design_library_1.DesignReferenceSearchRequestSchema.parse(req.body))));
148
148
  });
149
149
  router.post('/profile/reference-contexts', async (req, res) => {
150
150
  res.setHeader('Cache-Control', 'private, no-store');
@@ -10,12 +10,16 @@ const WorkspaceSchema = zod_1.z.object({ projectPath: zod_1.z.string().min(1) })
10
10
  const ProjectUpdateSchema = zod_1.z.object({ name: ProjectRegistry_1.ProjectNameSchema }).strict();
11
11
  const createProjectRoutes = ({ library, runtime, cardPreviews, folderPicker = new ProjectFolderPicker_1.ProjectFolderPicker(), track, }) => {
12
12
  const router = (0, express_1.Router)();
13
- router.get('/', async (_req, res) => res.json(await library.snapshot()));
14
- router.get('/projects', (_req, res) => res.json({ projects: library.listProjects() }));
13
+ router.get('/', async (_req, res) => res.json((await library.snapshot())));
14
+ router.get('/projects', (_req, res) => res.json({
15
+ projects: library.listProjects(),
16
+ }));
15
17
  router.patch('/projects/:projectId', track('project_rename'), (req, res) => {
16
18
  const { projectId } = schemas_1.ProjectParamsSchema.parse(req.params);
17
19
  const { name } = ProjectUpdateSchema.parse(req.body);
18
- res.json({ project: library.registry.rename({ projectId, name }) });
20
+ res.json({
21
+ project: library.registry.rename({ projectId, name }),
22
+ });
19
23
  });
20
24
  router.put('/projects/:projectId/pin', track('project_pin'), (req, res) => {
21
25
  const { projectId } = schemas_1.ProjectParamsSchema.parse(req.params);
@@ -38,14 +42,20 @@ const createProjectRoutes = ({ library, runtime, cardPreviews, folderPicker = ne
38
42
  const { projectId } = schemas_1.ProjectParamsSchema.parse(req.params);
39
43
  library.registry.get(projectId);
40
44
  res.setHeader('Cache-Control', 'no-store');
41
- res.json({ preview: (await cardPreviews?.get(projectId)) ?? null });
45
+ res.json({
46
+ preview: (await cardPreviews?.get(projectId)) ?? null,
47
+ });
42
48
  });
43
49
  router.post('/folder-selections', track('folder_select'), async (_req, res) => {
44
- res.json({ projectPath: await folderPicker.pick() });
50
+ res.json({
51
+ projectPath: await folderPicker.pick(),
52
+ });
45
53
  });
46
54
  router.post('/projects', track('project_open'), async (req, res) => {
47
55
  const body = WorkspaceSchema.parse(req.body);
48
- res.status(201).json(await library.prepare(body.projectPath));
56
+ res
57
+ .status(201)
58
+ .json((await library.prepare(body.projectPath)));
49
59
  });
50
60
  router.patch('/projects/:projectId/workspace', track('project_open'), async (req, res) => {
51
61
  const body = WorkspaceSchema.parse(req.body);
@@ -57,7 +67,7 @@ const createProjectRoutes = ({ library, runtime, cardPreviews, folderPicker = ne
57
67
  });
58
68
  });
59
69
  router.post('/projects/:projectId/runtime', track('workspace_open'), async (req, res) => {
60
- res.json(await runtime.activate(schemas_1.ProjectParamsSchema.parse(req.params).projectId));
70
+ res.json((await runtime.activate(schemas_1.ProjectParamsSchema.parse(req.params).projectId)));
61
71
  });
62
72
  return router;
63
73
  };
@@ -48,7 +48,7 @@ const createReferenceOnboardingRoutes = (profiles, telemetry) => {
48
48
  });
49
49
  res
50
50
  .status(201)
51
- .json(await profiles.planReferences(input, controller.signal));
51
+ .json((await profiles.planReferences(input, controller.signal)));
52
52
  });
53
53
  router.get('/profile/import-plans/:id', async (req, res) => {
54
54
  res.json(await profiles.referencePlan(zod_1.z.string().uuid().parse(req.params.id)));
@@ -58,7 +58,9 @@ const createReferenceOnboardingRoutes = (profiles, telemetry) => {
58
58
  ...req.body,
59
59
  id: req.params.id,
60
60
  });
61
- res.status(202).json(await profiles.importReferences(input));
61
+ res
62
+ .status(202)
63
+ .json((await profiles.importReferences(input)));
62
64
  });
63
65
  router.get('/profile/onboarding', async (req, res) => {
64
66
  const { provider } = zod_1.z
@@ -1,23 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  export declare const ProjectParamsSchema: z.ZodObject<{
3
3
  projectId: z.ZodString;
4
- }, "strip", z.ZodTypeAny, {
5
- projectId: string;
6
- }, {
7
- projectId: string;
8
- }>;
4
+ }, z.core.$strip>;
9
5
  export declare const VariantParamsSchema: z.ZodObject<{
10
6
  projectId: z.ZodString;
11
- } & {
12
7
  sessionId: z.ZodString;
13
8
  variantId: z.ZodString;
14
- }, "strip", z.ZodTypeAny, {
15
- projectId: string;
16
- sessionId: string;
17
- variantId: string;
18
- }, {
19
- projectId: string;
20
- sessionId: string;
21
- variantId: string;
22
- }>;
9
+ }, z.core.$strip>;
23
10
  //# sourceMappingURL=schemas.d.ts.map
@@ -9,7 +9,7 @@ const telemetryPolicy_1 = require("../config/telemetryPolicy");
9
9
  const ConfigManager_1 = require("../services/ConfigManager");
10
10
  const metricBody = zod_1.z.object({
11
11
  event: zod_1.z.string(),
12
- properties: zod_1.z.record(zod_1.z.unknown()),
12
+ properties: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
13
13
  });
14
14
  const createTelemetryRouter = (telemetry) => {
15
15
  const router = (0, express_1.Router)();
@@ -98,13 +98,13 @@ export declare const inlineVariantRequestSchema: z.ZodEffects<z.ZodObject<{
98
98
  }, "strip", z.ZodTypeAny, {
99
99
  count: number;
100
100
  mode?: "zero_to_one" | "existing" | undefined;
101
+ profile?: "off" | "auto" | undefined;
101
102
  contextAssets?: {
102
103
  path: string;
103
104
  label?: string | undefined;
104
105
  }[] | undefined;
105
106
  runLabel?: string | undefined;
106
107
  fidelity?: "high" | "medium" | "low" | undefined;
107
- profile?: "off" | "auto" | undefined;
108
108
  briefs?: {
109
109
  label: string;
110
110
  body: string;
@@ -126,13 +126,13 @@ export declare const inlineVariantRequestSchema: z.ZodEffects<z.ZodObject<{
126
126
  }, {
127
127
  count: number;
128
128
  mode?: "zero_to_one" | "existing" | undefined;
129
+ profile?: "off" | "auto" | undefined;
129
130
  contextAssets?: {
130
131
  path: string;
131
132
  label?: string | undefined;
132
133
  }[] | undefined;
133
134
  runLabel?: string | undefined;
134
135
  fidelity?: "high" | "medium" | "low" | undefined;
135
- profile?: "off" | "auto" | undefined;
136
136
  briefs?: {
137
137
  label: string;
138
138
  body: string;
@@ -151,13 +151,13 @@ export declare const inlineVariantRequestSchema: z.ZodEffects<z.ZodObject<{
151
151
  }>, {
152
152
  count: number;
153
153
  mode?: "zero_to_one" | "existing" | undefined;
154
+ profile?: "off" | "auto" | undefined;
154
155
  contextAssets?: {
155
156
  path: string;
156
157
  label?: string | undefined;
157
158
  }[] | undefined;
158
159
  runLabel?: string | undefined;
159
160
  fidelity?: "high" | "medium" | "low" | undefined;
160
- profile?: "off" | "auto" | undefined;
161
161
  briefs?: {
162
162
  label: string;
163
163
  body: string;
@@ -179,13 +179,13 @@ export declare const inlineVariantRequestSchema: z.ZodEffects<z.ZodObject<{
179
179
  }, {
180
180
  count: number;
181
181
  mode?: "zero_to_one" | "existing" | undefined;
182
+ profile?: "off" | "auto" | undefined;
182
183
  contextAssets?: {
183
184
  path: string;
184
185
  label?: string | undefined;
185
186
  }[] | undefined;
186
187
  runLabel?: string | undefined;
187
188
  fidelity?: "high" | "medium" | "low" | undefined;
188
- profile?: "off" | "auto" | undefined;
189
189
  briefs?: {
190
190
  label: string;
191
191
  body: string;
@@ -42,8 +42,13 @@ const guidanceSelectionSchema = v3_1.z
42
42
  const parsed = guidance_1.GuidanceSelectionSchema.safeParse(value);
43
43
  if (parsed.success)
44
44
  return parsed.data;
45
- for (const issue of parsed.error.issues)
46
- context.addIssue(issue);
45
+ for (const { message, path } of parsed.error.issues) {
46
+ context.addIssue({
47
+ code: v3_1.z.ZodIssueCode.custom,
48
+ message,
49
+ path: path.filter((key) => typeof key !== 'symbol'),
50
+ });
51
+ }
47
52
  return v3_1.z.NEVER;
48
53
  });
49
54
  exports.inlineVariantRequestSchema = v3_1.z
package/dist/server.js CHANGED
@@ -370,6 +370,14 @@ const startServer = async (options) => {
370
370
  app.get('/rivet/favicon.ico', (_req, res) => {
371
371
  res.sendFile('favicon.ico', { root: exports.DIST_UI_PATH });
372
372
  });
373
+ app.get(/^\/rivet\/library(?:\/.*)?$/, (req, res) => {
374
+ const resolvedLibraryOrigin = options.resolveLibraryOrigin?.();
375
+ if (!resolvedLibraryOrigin) {
376
+ res.sendStatus(404);
377
+ return;
378
+ }
379
+ res.redirect(302, `${new URL(resolvedLibraryOrigin).origin}${req.path}`);
380
+ });
373
381
  app.get(/^\/rivet(?:\/.*)?$/, (req, res, next) => {
374
382
  if ((0, exports.isRivetUiStaticAssetPath)(req.path)) {
375
383
  next();