Skip to content

Commit c8f7588

Browse files
authored
🪄 feat: Customize Sandpack bundlerURL for Artifacts (#6191)
1 parent 00b2d02 commit c8f7588

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

api/server/routes/config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ router.get('/', async function (req, res) {
4747
githubLoginEnabled: !!process.env.GITHUB_CLIENT_ID && !!process.env.GITHUB_CLIENT_SECRET,
4848
googleLoginEnabled: !!process.env.GOOGLE_CLIENT_ID && !!process.env.GOOGLE_CLIENT_SECRET,
4949
appleLoginEnabled:
50-
!!process.env.APPLE_CLIENT_ID &&
51-
!!process.env.APPLE_TEAM_ID &&
52-
!!process.env.APPLE_KEY_ID &&
53-
!!process.env.APPLE_PRIVATE_KEY_PATH,
50+
!!process.env.APPLE_CLIENT_ID &&
51+
!!process.env.APPLE_TEAM_ID &&
52+
!!process.env.APPLE_KEY_ID &&
53+
!!process.env.APPLE_PRIVATE_KEY_PATH,
5454
openidLoginEnabled:
5555
!!process.env.OPENID_CLIENT_ID &&
5656
!!process.env.OPENID_CLIENT_SECRET &&
@@ -80,6 +80,7 @@ router.get('/', async function (req, res) {
8080
publicSharedLinksEnabled,
8181
analyticsGtmId: process.env.ANALYTICS_GTM_ID,
8282
instanceProjectId: instanceProject._id.toString(),
83+
bundlerURL: process.env.SANDPACK_BUNDLER_URL,
8384
};
8485

8586
if (ldap) {

client/src/components/Artifacts/ArtifactCodeEditor.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
import { SandpackProviderProps } from '@codesandbox/sandpack-react/unstyled';
99
import type { CodeEditorRef } from '@codesandbox/sandpack-react';
1010
import type { ArtifactFiles, Artifact } from '~/common';
11+
import { useEditArtifact, useGetStartupConfig } from '~/data-provider';
1112
import { sharedFiles, sharedOptions } from '~/utils/artifacts';
12-
import { useEditArtifact } from '~/data-provider';
1313
import { useEditorContext } from '~/Providers';
1414

1515
const createDebouncedMutation = (
@@ -124,6 +124,17 @@ export const ArtifactCodeEditor = memo(function ({
124124
sharedProps: Partial<SandpackProviderProps>;
125125
editorRef: React.MutableRefObject<CodeEditorRef>;
126126
}) {
127+
const { data: config } = useGetStartupConfig();
128+
const options: typeof sharedOptions = useMemo(() => {
129+
if (!config) {
130+
return sharedOptions;
131+
}
132+
return {
133+
...sharedOptions,
134+
bundlerURL: config.bundlerURL,
135+
};
136+
}, [config]);
137+
127138
if (Object.keys(files).length === 0) {
128139
return null;
129140
}
@@ -135,7 +146,7 @@ export const ArtifactCodeEditor = memo(function ({
135146
...files,
136147
...sharedFiles,
137148
}}
138-
options={{ ...sharedOptions }}
149+
options={options}
139150
{...sharedProps}
140151
template={template}
141152
>

client/src/components/Artifacts/ArtifactPreview.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import type { SandpackPreviewRef } from '@codesandbox/sandpack-react/unstyled';
88
import type { ArtifactFiles } from '~/common';
99
import { sharedFiles, sharedOptions } from '~/utils/artifacts';
10+
import { useGetStartupConfig } from '~/data-provider';
1011
import { useEditorContext } from '~/Providers';
1112

1213
export const ArtifactPreview = memo(function ({
@@ -23,6 +24,8 @@ export const ArtifactPreview = memo(function ({
2324
previewRef: React.MutableRefObject<SandpackPreviewRef>;
2425
}) {
2526
const { currentCode } = useEditorContext();
27+
const { data: config } = useGetStartupConfig();
28+
2629
const artifactFiles = useMemo(() => {
2730
if (Object.keys(files).length === 0) {
2831
return files;
@@ -38,6 +41,17 @@ export const ArtifactPreview = memo(function ({
3841
},
3942
};
4043
}, [currentCode, files, fileKey]);
44+
45+
const options: typeof sharedOptions = useMemo(() => {
46+
if (!config) {
47+
return sharedOptions;
48+
}
49+
return {
50+
...sharedOptions,
51+
bundlerURL: config.bundlerURL,
52+
};
53+
}, [config]);
54+
4155
if (Object.keys(artifactFiles).length === 0) {
4256
return null;
4357
}
@@ -48,7 +62,7 @@ export const ArtifactPreview = memo(function ({
4862
...artifactFiles,
4963
...sharedFiles,
5064
}}
51-
options={{ ...sharedOptions }}
65+
options={options}
5266
{...sharedProps}
5367
template={template}
5468
>

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/data-provider/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "librechat-data-provider",
3-
"version": "0.7.6997",
3+
"version": "0.7.6998",
44
"description": "data services for librechat apps",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",

packages/data-provider/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ export type TStartupConfig = {
531531
publicSharedLinksEnabled: boolean;
532532
analyticsGtmId?: string;
533533
instanceProjectId: string;
534+
bundlerURL?: string;
534535
};
535536

536537
export const configSchema = z.object({

0 commit comments

Comments
 (0)