mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🪄 feat: Customize Sandpack bundlerURL for Artifacts (#6191)
This commit is contained in:
parent
00b2d026c1
commit
c8f7588164
6 changed files with 36 additions and 9 deletions
|
|
@ -80,6 +80,7 @@ router.get('/', async function (req, res) {
|
||||||
publicSharedLinksEnabled,
|
publicSharedLinksEnabled,
|
||||||
analyticsGtmId: process.env.ANALYTICS_GTM_ID,
|
analyticsGtmId: process.env.ANALYTICS_GTM_ID,
|
||||||
instanceProjectId: instanceProject._id.toString(),
|
instanceProjectId: instanceProject._id.toString(),
|
||||||
|
bundlerURL: process.env.SANDPACK_BUNDLER_URL,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (ldap) {
|
if (ldap) {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import {
|
||||||
import { SandpackProviderProps } from '@codesandbox/sandpack-react/unstyled';
|
import { SandpackProviderProps } from '@codesandbox/sandpack-react/unstyled';
|
||||||
import type { CodeEditorRef } from '@codesandbox/sandpack-react';
|
import type { CodeEditorRef } from '@codesandbox/sandpack-react';
|
||||||
import type { ArtifactFiles, Artifact } from '~/common';
|
import type { ArtifactFiles, Artifact } from '~/common';
|
||||||
|
import { useEditArtifact, useGetStartupConfig } from '~/data-provider';
|
||||||
import { sharedFiles, sharedOptions } from '~/utils/artifacts';
|
import { sharedFiles, sharedOptions } from '~/utils/artifacts';
|
||||||
import { useEditArtifact } from '~/data-provider';
|
|
||||||
import { useEditorContext } from '~/Providers';
|
import { useEditorContext } from '~/Providers';
|
||||||
|
|
||||||
const createDebouncedMutation = (
|
const createDebouncedMutation = (
|
||||||
|
|
@ -124,6 +124,17 @@ export const ArtifactCodeEditor = memo(function ({
|
||||||
sharedProps: Partial<SandpackProviderProps>;
|
sharedProps: Partial<SandpackProviderProps>;
|
||||||
editorRef: React.MutableRefObject<CodeEditorRef>;
|
editorRef: React.MutableRefObject<CodeEditorRef>;
|
||||||
}) {
|
}) {
|
||||||
|
const { data: config } = useGetStartupConfig();
|
||||||
|
const options: typeof sharedOptions = useMemo(() => {
|
||||||
|
if (!config) {
|
||||||
|
return sharedOptions;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...sharedOptions,
|
||||||
|
bundlerURL: config.bundlerURL,
|
||||||
|
};
|
||||||
|
}, [config]);
|
||||||
|
|
||||||
if (Object.keys(files).length === 0) {
|
if (Object.keys(files).length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -135,7 +146,7 @@ export const ArtifactCodeEditor = memo(function ({
|
||||||
...files,
|
...files,
|
||||||
...sharedFiles,
|
...sharedFiles,
|
||||||
}}
|
}}
|
||||||
options={{ ...sharedOptions }}
|
options={options}
|
||||||
{...sharedProps}
|
{...sharedProps}
|
||||||
template={template}
|
template={template}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import type { SandpackPreviewRef } from '@codesandbox/sandpack-react/unstyled';
|
import type { SandpackPreviewRef } from '@codesandbox/sandpack-react/unstyled';
|
||||||
import type { ArtifactFiles } from '~/common';
|
import type { ArtifactFiles } from '~/common';
|
||||||
import { sharedFiles, sharedOptions } from '~/utils/artifacts';
|
import { sharedFiles, sharedOptions } from '~/utils/artifacts';
|
||||||
|
import { useGetStartupConfig } from '~/data-provider';
|
||||||
import { useEditorContext } from '~/Providers';
|
import { useEditorContext } from '~/Providers';
|
||||||
|
|
||||||
export const ArtifactPreview = memo(function ({
|
export const ArtifactPreview = memo(function ({
|
||||||
|
|
@ -23,6 +24,8 @@ export const ArtifactPreview = memo(function ({
|
||||||
previewRef: React.MutableRefObject<SandpackPreviewRef>;
|
previewRef: React.MutableRefObject<SandpackPreviewRef>;
|
||||||
}) {
|
}) {
|
||||||
const { currentCode } = useEditorContext();
|
const { currentCode } = useEditorContext();
|
||||||
|
const { data: config } = useGetStartupConfig();
|
||||||
|
|
||||||
const artifactFiles = useMemo(() => {
|
const artifactFiles = useMemo(() => {
|
||||||
if (Object.keys(files).length === 0) {
|
if (Object.keys(files).length === 0) {
|
||||||
return files;
|
return files;
|
||||||
|
|
@ -38,6 +41,17 @@ export const ArtifactPreview = memo(function ({
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}, [currentCode, files, fileKey]);
|
}, [currentCode, files, fileKey]);
|
||||||
|
|
||||||
|
const options: typeof sharedOptions = useMemo(() => {
|
||||||
|
if (!config) {
|
||||||
|
return sharedOptions;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...sharedOptions,
|
||||||
|
bundlerURL: config.bundlerURL,
|
||||||
|
};
|
||||||
|
}, [config]);
|
||||||
|
|
||||||
if (Object.keys(artifactFiles).length === 0) {
|
if (Object.keys(artifactFiles).length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +62,7 @@ export const ArtifactPreview = memo(function ({
|
||||||
...artifactFiles,
|
...artifactFiles,
|
||||||
...sharedFiles,
|
...sharedFiles,
|
||||||
}}
|
}}
|
||||||
options={{ ...sharedOptions }}
|
options={options}
|
||||||
{...sharedProps}
|
{...sharedProps}
|
||||||
template={template}
|
template={template}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -43146,7 +43146,7 @@
|
||||||
},
|
},
|
||||||
"packages/data-provider": {
|
"packages/data-provider": {
|
||||||
"name": "librechat-data-provider",
|
"name": "librechat-data-provider",
|
||||||
"version": "0.7.6997",
|
"version": "0.7.6998",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "librechat-data-provider",
|
"name": "librechat-data-provider",
|
||||||
"version": "0.7.6997",
|
"version": "0.7.6998",
|
||||||
"description": "data services for librechat apps",
|
"description": "data services for librechat apps",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/index.es.js",
|
"module": "dist/index.es.js",
|
||||||
|
|
|
||||||
|
|
@ -531,6 +531,7 @@ export type TStartupConfig = {
|
||||||
publicSharedLinksEnabled: boolean;
|
publicSharedLinksEnabled: boolean;
|
||||||
analyticsGtmId?: string;
|
analyticsGtmId?: string;
|
||||||
instanceProjectId: string;
|
instanceProjectId: string;
|
||||||
|
bundlerURL?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const configSchema = z.object({
|
export const configSchema = z.object({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue