@lobehub/chat 1.21.4 → 1.21.6

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 (74) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/package.json +1 -1
  3. package/src/app/{api → (backend)/api}/chat/[provider]/route.test.ts +1 -1
  4. package/src/app/{api → (backend)/api}/chat/[provider]/route.ts +1 -1
  5. package/src/app/{api → (backend)/api}/chat/models/[provider]/route.ts +1 -1
  6. package/src/app/{api → (backend)/api}/middleware/auth/index.test.ts +2 -2
  7. package/src/app/{api → (backend)/api}/middleware/auth/index.ts +1 -1
  8. package/src/app/{webapi → (backend)/webapi}/plugin/gateway/route.ts +2 -2
  9. package/src/app/{webapi → (backend)/webapi}/stt/openai/route.ts +1 -1
  10. package/src/app/{webapi → (backend)/webapi}/text-to-image/[provider]/route.ts +3 -3
  11. package/src/app/{webapi → (backend)/webapi}/tts/openai/route.ts +1 -1
  12. package/src/app/(main)/chat/(workspace)/@portal/Artifacts/Body/Renderer/React/index.tsx +51 -0
  13. package/src/app/(main)/chat/(workspace)/@portal/Artifacts/Body/Renderer/React/template.ts +32 -0
  14. package/src/libs/agent-runtime/AgentRuntime.test.ts +1 -1
  15. package/src/libs/trpc/middleware/jwtPayload.test.ts +1 -1
  16. package/src/libs/trpc/middleware/jwtPayload.ts +1 -1
  17. package/src/libs/trpc/middleware/keyVaults.ts +1 -1
  18. package/src/server/routers/async/file.ts +1 -1
  19. package/src/server/routers/async/ragEval.ts +1 -1
  20. package/src/server/routers/lambda/chunk.ts +1 -1
  21. package/src/services/_url.ts +1 -1
  22. package/src/services/chat.ts +1 -1
  23. package/src/services/ollama.ts +1 -1
  24. package/src/app/(main)/chat/(workspace)/@portal/Artifacts/Body/Renderer/React.tsx +0 -31
  25. /package/src/app/{api → (backend)/api}/auth/[...nextauth]/route.ts +0 -0
  26. /package/src/app/{api → (backend)/api}/auth/error/AuthErrorPage.tsx +0 -0
  27. /package/src/app/{api → (backend)/api}/auth/error/page.tsx +0 -0
  28. /package/src/app/{api → (backend)/api}/chat/agentRuntime.test.ts +0 -0
  29. /package/src/app/{api → (backend)/api}/chat/agentRuntime.ts +0 -0
  30. /package/src/app/{api → (backend)/api}/chat/anthropic/route.test.ts +0 -0
  31. /package/src/app/{api → (backend)/api}/chat/anthropic/route.ts +0 -0
  32. /package/src/app/{api → (backend)/api}/chat/apiKeyManager.test.ts +0 -0
  33. /package/src/app/{api → (backend)/api}/chat/apiKeyManager.ts +0 -0
  34. /package/src/app/{api → (backend)/api}/chat/google/route.test.ts +0 -0
  35. /package/src/app/{api → (backend)/api}/chat/google/route.ts +0 -0
  36. /package/src/app/{api → (backend)/api}/chat/minimax/route.test.ts +0 -0
  37. /package/src/app/{api → (backend)/api}/chat/minimax/route.ts +0 -0
  38. /package/src/app/{api → (backend)/api}/chat/openai/route.test.ts +0 -0
  39. /package/src/app/{api → (backend)/api}/chat/openai/route.ts +0 -0
  40. /package/src/app/{api → (backend)/api}/chat/wenxin/route.test.ts +0 -0
  41. /package/src/app/{api → (backend)/api}/chat/wenxin/route.ts +0 -0
  42. /package/src/app/{api → (backend)/api}/errorResponse.test.ts +0 -0
  43. /package/src/app/{api → (backend)/api}/errorResponse.ts +0 -0
  44. /package/src/app/{api → (backend)/api}/middleware/auth/utils.test.ts +0 -0
  45. /package/src/app/{api → (backend)/api}/middleware/auth/utils.ts +0 -0
  46. /package/src/app/{api → (backend)/api}/openai/createBizOpenAI/auth.test.ts +0 -0
  47. /package/src/app/{api → (backend)/api}/openai/createBizOpenAI/auth.ts +0 -0
  48. /package/src/app/{api → (backend)/api}/openai/createBizOpenAI/createAzureOpenai.ts +0 -0
  49. /package/src/app/{api → (backend)/api}/openai/createBizOpenAI/createOpenai.ts +0 -0
  50. /package/src/app/{api → (backend)/api}/openai/createBizOpenAI/index.ts +0 -0
  51. /package/src/app/{api → (backend)/api}/webhooks/casdoor/__tests__/route.test.ts +0 -0
  52. /package/src/app/{api → (backend)/api}/webhooks/casdoor/route.ts +0 -0
  53. /package/src/app/{api → (backend)/api}/webhooks/casdoor/validateRequest.ts +0 -0
  54. /package/src/app/{api → (backend)/api}/webhooks/clerk/__tests__/fixtures/createUser.json +0 -0
  55. /package/src/app/{api → (backend)/api}/webhooks/clerk/route.ts +0 -0
  56. /package/src/app/{api → (backend)/api}/webhooks/clerk/validateRequest.ts +0 -0
  57. /package/src/app/{api → (backend)/api}/webhooks/logto/__tests__/route.test.ts +0 -0
  58. /package/src/app/{api → (backend)/api}/webhooks/logto/route.ts +0 -0
  59. /package/src/app/{api → (backend)/api}/webhooks/logto/validateRequest.ts +0 -0
  60. /package/src/app/{trpc → (backend)/trpc}/async/[trpc]/route.ts +0 -0
  61. /package/src/app/{trpc → (backend)/trpc}/edge/[trpc]/route.ts +0 -0
  62. /package/src/app/{trpc → (backend)/trpc}/lambda/[trpc]/route.ts +0 -0
  63. /package/src/app/{trpc → (backend)/trpc}/tools/[trpc]/route.ts +0 -0
  64. /package/src/app/{webapi → (backend)/webapi}/assistant/[id]/route.ts +0 -0
  65. /package/src/app/{webapi → (backend)/webapi}/assistant/store/route.ts +0 -0
  66. /package/src/app/{webapi → (backend)/webapi}/plugin/gateway/settings.test.ts +0 -0
  67. /package/src/app/{webapi → (backend)/webapi}/plugin/gateway/settings.ts +0 -0
  68. /package/src/app/{webapi → (backend)/webapi}/plugin/store/route.ts +0 -0
  69. /package/src/app/{webapi → (backend)/webapi}/proxy/route.ts +0 -0
  70. /package/src/app/{webapi → (backend)/webapi}/tokenizer/index.test.ts +0 -0
  71. /package/src/app/{webapi → (backend)/webapi}/tokenizer/route.ts +0 -0
  72. /package/src/app/{webapi → (backend)/webapi}/trace/route.ts +0 -0
  73. /package/src/app/{webapi → (backend)/webapi}/tts/edge/route.ts +0 -0
  74. /package/src/app/{webapi → (backend)/webapi}/tts/microsoft/route.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,64 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.21.6](https://github.com/lobehub/lobe-chat/compare/v1.21.5...v1.21.6)
6
+
7
+ <sup>Released on **2024-10-05**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Move backend api to (backend) folder group.
12
+
13
+ #### 🐛 Bug Fixes
14
+
15
+ - **misc**: Fix txt-to-image api.
16
+
17
+ <br/>
18
+
19
+ <details>
20
+ <summary><kbd>Improvements and Fixes</kbd></summary>
21
+
22
+ #### Code refactoring
23
+
24
+ - **misc**: Move backend api to (backend) folder group, closes [#4262](https://github.com/lobehub/lobe-chat/issues/4262) ([d8afb46](https://github.com/lobehub/lobe-chat/commit/d8afb46))
25
+
26
+ #### What's fixed
27
+
28
+ - **misc**: Fix txt-to-image api, closes [#4264](https://github.com/lobehub/lobe-chat/issues/4264) ([d1ff4ba](https://github.com/lobehub/lobe-chat/commit/d1ff4ba))
29
+
30
+ </details>
31
+
32
+ <div align="right">
33
+
34
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
35
+
36
+ </div>
37
+
38
+ ### [Version 1.21.5](https://github.com/lobehub/lobe-chat/compare/v1.21.4...v1.21.5)
39
+
40
+ <sup>Released on **2024-10-05**</sup>
41
+
42
+ #### 💄 Styles
43
+
44
+ - **misc**: Support shadcn in Artifacts.
45
+
46
+ <br/>
47
+
48
+ <details>
49
+ <summary><kbd>Improvements and Fixes</kbd></summary>
50
+
51
+ #### Styles
52
+
53
+ - **misc**: Support shadcn in Artifacts, closes [#4256](https://github.com/lobehub/lobe-chat/issues/4256) ([863bae5](https://github.com/lobehub/lobe-chat/commit/863bae5))
54
+
55
+ </details>
56
+
57
+ <div align="right">
58
+
59
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
60
+
61
+ </div>
62
+
5
63
  ### [Version 1.21.4](https://github.com/lobehub/lobe-chat/compare/v1.21.3...v1.21.4)
6
64
 
7
65
  <sup>Released on **2024-10-02**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.21.4",
3
+ "version": "1.21.6",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -2,7 +2,7 @@
2
2
  import { getAuth } from '@clerk/nextjs/server';
3
3
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
4
 
5
- import { checkAuthMethod, getJWTPayload } from '@/app/api/middleware/auth/utils';
5
+ import { checkAuthMethod, getJWTPayload } from '@/app/(backend)/api/middleware/auth/utils';
6
6
  import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED } from '@/const/auth';
7
7
  import { AgentRuntime, LobeRuntimeAI } from '@/libs/agent-runtime';
8
8
  import { ChatErrorType } from '@/types/fetch';
@@ -1,4 +1,4 @@
1
- import { createErrorResponse } from '@/app/api/errorResponse';
1
+ import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
2
2
  import { AgentRuntime, ChatCompletionErrorPayload } from '@/libs/agent-runtime';
3
3
  import { ChatErrorType } from '@/types/fetch';
4
4
  import { ChatStreamPayload } from '@/types/openai/chat';
@@ -1,6 +1,6 @@
1
1
  import { NextResponse } from 'next/server';
2
2
 
3
- import { createErrorResponse } from '@/app/api/errorResponse';
3
+ import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
4
4
  import { ChatCompletionErrorPayload, ModelProvider } from '@/libs/agent-runtime';
5
5
  import { ChatErrorType } from '@/types/fetch';
6
6
 
@@ -1,7 +1,7 @@
1
1
  import { getAuth } from '@clerk/nextjs/server';
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
3
 
4
- import { createErrorResponse } from '@/app/api/errorResponse';
4
+ import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
5
5
  import { AgentRuntimeError } from '@/libs/agent-runtime';
6
6
  import { ChatErrorType } from '@/types/fetch';
7
7
 
@@ -12,7 +12,7 @@ vi.mock('@clerk/nextjs/server', () => ({
12
12
  getAuth: vi.fn(),
13
13
  }));
14
14
 
15
- vi.mock('@/app/api/errorResponse', () => ({
15
+ vi.mock('@/app/(backend)/api/errorResponse', () => ({
16
16
  createErrorResponse: vi.fn(),
17
17
  }));
18
18
 
@@ -2,7 +2,7 @@ import { AuthObject } from '@clerk/backend';
2
2
  import { getAuth } from '@clerk/nextjs/server';
3
3
  import { NextRequest } from 'next/server';
4
4
 
5
- import { createErrorResponse } from '@/app/api/errorResponse';
5
+ import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
6
6
  import { JWTPayload, LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED, enableClerk } from '@/const/auth';
7
7
  import { AgentRuntime, AgentRuntimeError, ChatCompletionErrorPayload } from '@/libs/agent-runtime';
8
8
  import { ChatErrorType } from '@/types/fetch';
@@ -1,8 +1,8 @@
1
1
  import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk';
2
2
  import { createGatewayOnEdgeRuntime } from '@lobehub/chat-plugins-gateway';
3
3
 
4
- import { createErrorResponse } from '@/app/api/errorResponse';
5
- import { getJWTPayload } from '@/app/api/middleware/auth/utils';
4
+ import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
5
+ import { getJWTPayload } from '@/app/(backend)/api/middleware/auth/utils';
6
6
  import { getAppConfig } from '@/config/app';
7
7
  import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED, enableNextAuth } from '@/const/auth';
8
8
  import { LOBE_CHAT_TRACE_ID, TraceNameMap } from '@/const/trace';
@@ -1,7 +1,7 @@
1
1
  import { OpenAISTTPayload } from '@lobehub/tts';
2
2
  import { createOpenaiAudioTranscriptions } from '@lobehub/tts/server';
3
3
 
4
- import { createBizOpenAI } from '@/app/api/openai/createBizOpenAI';
4
+ import { createBizOpenAI } from '@/app/(backend)/api/openai/createBizOpenAI';
5
5
 
6
6
  export const runtime = 'edge';
7
7
 
@@ -1,8 +1,8 @@
1
1
  import { NextResponse } from 'next/server';
2
2
 
3
- import { initAgentRuntimeWithUserPayload } from '@/app/api/chat/agentRuntime';
4
- import { createErrorResponse } from '@/app/api/errorResponse';
5
- import { checkAuth } from '@/app/api/middleware/auth';
3
+ import { initAgentRuntimeWithUserPayload } from '@/app/(backend)/api/chat/agentRuntime';
4
+ import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
5
+ import { checkAuth } from '@/app/(backend)/api/middleware/auth';
6
6
  import { ChatCompletionErrorPayload } from '@/libs/agent-runtime';
7
7
  import { TextToImagePayload } from '@/libs/agent-runtime/types';
8
8
  import { ChatErrorType } from '@/types/fetch';
@@ -1,7 +1,7 @@
1
1
  import { OpenAITTSPayload } from '@lobehub/tts';
2
2
  import { createOpenaiAudioSpeech } from '@lobehub/tts/server';
3
3
 
4
- import { createBizOpenAI } from '@/app/api/openai/createBizOpenAI';
4
+ import { createBizOpenAI } from '@/app/(backend)/api/openai/createBizOpenAI';
5
5
 
6
6
  export const runtime = 'edge';
7
7
 
@@ -0,0 +1,51 @@
1
+ import { SandpackLayout, SandpackPreview, SandpackProvider } from '@codesandbox/sandpack-react';
2
+ import { memo } from 'react';
3
+
4
+ import { useChatStore } from '@/store/chat';
5
+ import { chatPortalSelectors } from '@/store/chat/selectors';
6
+
7
+ import { createTemplateFiles } from './template';
8
+
9
+ interface ReactRendererProps {
10
+ code: string;
11
+ }
12
+
13
+ const ReactRenderer = memo<ReactRendererProps>(({ code }) => {
14
+ const title = useChatStore(chatPortalSelectors.artifactTitle);
15
+
16
+ return (
17
+ <SandpackProvider
18
+ customSetup={{
19
+ dependencies: {
20
+ '@lshay/ui': 'latest',
21
+ '@radix-ui/react-alert-dialog': 'latest',
22
+ '@radix-ui/react-dialog': 'latest',
23
+ '@radix-ui/react-icons': 'latest',
24
+ 'antd': 'latest',
25
+ 'class-variance-authority': 'latest',
26
+ 'clsx': 'latest',
27
+ 'lucide-react': 'latest',
28
+ 'recharts': 'latest',
29
+ 'tailwind-merge': 'latest',
30
+ },
31
+ }}
32
+ files={{
33
+ 'App.tsx': code,
34
+ ...createTemplateFiles({ title }),
35
+ }}
36
+ options={{
37
+ externalResources: ['https://cdn.tailwindcss.com'],
38
+ visibleFiles: ['App.tsx'],
39
+ }}
40
+ style={{ height: '100%' }}
41
+ template="vite-react-ts"
42
+ theme="auto"
43
+ >
44
+ <SandpackLayout style={{ height: '100%' }}>
45
+ <SandpackPreview style={{ height: '100%' }} />
46
+ </SandpackLayout>
47
+ </SandpackProvider>
48
+ );
49
+ });
50
+
51
+ export default ReactRenderer;
@@ -0,0 +1,32 @@
1
+ interface TemplateFilesParams {
2
+ title?: string;
3
+ }
4
+ export const createTemplateFiles = ({ title }: TemplateFilesParams = {}) => ({
5
+ 'index.html': `<!DOCTYPE html>
6
+ <html lang="en">
7
+ <head>
8
+ <meta charset="UTF-8" />
9
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
+ <title>${title || 'Artifacts App'}</title>
11
+ <script src="https://cdn.tailwindcss.com"></script>
12
+ </head>
13
+ <body>
14
+ <div id="root"></div>
15
+ <script type="module" src="/index.tsx"></script>
16
+ </body>
17
+ </html>
18
+ `,
19
+ 'vite.config.ts': {
20
+ code: `import { defineConfig } from 'vite';
21
+ import react from '@vitejs/plugin-react';
22
+
23
+ export default defineConfig({
24
+ plugins: [react()],
25
+ resolve: {
26
+ alias: {
27
+ '@/components/ui': '@lshay/ui/components/default',
28
+ },
29
+ },
30
+ });`,
31
+ },
32
+ });
@@ -4,7 +4,7 @@ import { LangfuseGenerationClient, LangfuseTraceClient } from 'langfuse-core';
4
4
  import { ClientOptions } from 'openai';
5
5
  import { beforeEach, describe, expect, it, vi } from 'vitest';
6
6
 
7
- import { createTraceOptions } from '@/app/api/chat/agentRuntime';
7
+ import { createTraceOptions } from '@/app/(backend)/api/chat/agentRuntime';
8
8
  import * as langfuseCfg from '@/config/langfuse';
9
9
  import { JWTPayload } from '@/const/auth';
10
10
  import { TraceNameMap } from '@/const/trace';
@@ -2,7 +2,7 @@
2
2
  import { TRPCError } from '@trpc/server';
3
3
  import { beforeEach, describe, expect, it, vi } from 'vitest';
4
4
 
5
- import * as utils from '@/app/api/middleware/auth/utils';
5
+ import * as utils from '@/app/(backend)/api/middleware/auth/utils';
6
6
  import { createCallerFactory } from '@/libs/trpc';
7
7
  import { trpc } from '@/libs/trpc/init';
8
8
  import { AuthContext, createContextInner } from '@/server/context';
@@ -1,6 +1,6 @@
1
1
  import { TRPCError } from '@trpc/server';
2
2
 
3
- import { getJWTPayload } from '@/app/api/middleware/auth/utils';
3
+ import { getJWTPayload } from '@/app/(backend)/api/middleware/auth/utils';
4
4
  import { trpc } from '@/libs/trpc/init';
5
5
 
6
6
  export const jwtPayloadChecker = trpc.middleware(async (opts) => {
@@ -1,6 +1,6 @@
1
1
  import { TRPCError } from '@trpc/server';
2
2
 
3
- import { getJWTPayload } from '@/app/api/middleware/auth/utils';
3
+ import { getJWTPayload } from '@/app/(backend)/api/middleware/auth/utils';
4
4
  import { trpc } from '@/libs/trpc/init';
5
5
 
6
6
  export const keyVaults = trpc.middleware(async (opts) => {
@@ -3,7 +3,7 @@ import { chunk } from 'lodash-es';
3
3
  import pMap from 'p-map';
4
4
  import { z } from 'zod';
5
5
 
6
- import { initAgentRuntimeWithUserPayload } from '@/app/api/chat/agentRuntime';
6
+ import { initAgentRuntimeWithUserPayload } from '@/app/(backend)/api/chat/agentRuntime';
7
7
  import { fileEnv } from '@/config/file';
8
8
  import { DEFAULT_EMBEDDING_MODEL } from '@/const/settings';
9
9
  import { ASYNC_TASK_TIMEOUT, AsyncTaskModel } from '@/database/server/models/asyncTask';
@@ -2,7 +2,7 @@ import { TRPCError } from '@trpc/server';
2
2
  import OpenAI from 'openai';
3
3
  import { z } from 'zod';
4
4
 
5
- import { initAgentRuntimeWithUserPayload } from '@/app/api/chat/agentRuntime';
5
+ import { initAgentRuntimeWithUserPayload } from '@/app/(backend)/api/chat/agentRuntime';
6
6
  import { chainAnswerWithContext } from '@/chains/answerWithContext';
7
7
  import { DEFAULT_EMBEDDING_MODEL, DEFAULT_MODEL } from '@/const/settings';
8
8
  import { ChunkModel } from '@/database/server/models/chunk';
@@ -1,7 +1,7 @@
1
1
  import { inArray } from 'drizzle-orm';
2
2
  import { z } from 'zod';
3
3
 
4
- import { initAgentRuntimeWithUserPayload } from '@/app/api/chat/agentRuntime';
4
+ import { initAgentRuntimeWithUserPayload } from '@/app/(backend)/api/chat/agentRuntime';
5
5
  import { DEFAULT_EMBEDDING_MODEL } from '@/const/settings';
6
6
  import { serverDB } from '@/database/server';
7
7
  import { AsyncTaskModel } from '@/database/server/models/asyncTask';
@@ -36,7 +36,7 @@ export const API_ENDPOINTS = mapWithBasePath({
36
36
  trace: '/webapi/trace',
37
37
 
38
38
  // image
39
- images: '/webapi/api/text-to-image/openai',
39
+ images: '/webapi/text-to-image/openai',
40
40
 
41
41
  // STT
42
42
  stt: '/webapi/stt/openai',
@@ -2,7 +2,7 @@ import { PluginRequestPayload, createHeadersWithPluginSettings } from '@lobehub/
2
2
  import { produce } from 'immer';
3
3
  import { merge } from 'lodash-es';
4
4
 
5
- import { createErrorResponse } from '@/app/api/errorResponse';
5
+ import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
6
6
  import { DEFAULT_MODEL_PROVIDER_LIST } from '@/config/modelProviders';
7
7
  import { INBOX_GUIDE_SYSTEMROLE } from '@/const/guide';
8
8
  import { INBOX_SESSION_ID } from '@/const/session';
@@ -1,6 +1,6 @@
1
1
  import { ListResponse, Ollama as OllamaBrowser, ProgressResponse } from 'ollama/browser';
2
2
 
3
- import { createErrorResponse } from '@/app/api/errorResponse';
3
+ import { createErrorResponse } from '@/app/(backend)/api/errorResponse';
4
4
  import { ModelProvider } from '@/libs/agent-runtime';
5
5
  import { useUserStore } from '@/store/user';
6
6
  import { keyVaultsConfigSelectors } from '@/store/user/selectors';
@@ -1,31 +0,0 @@
1
- import { SandpackLayout, SandpackPreview, SandpackProvider } from '@codesandbox/sandpack-react';
2
- import { memo } from 'react';
3
-
4
- interface ReactRendererProps {
5
- code: string;
6
- }
7
- const ReactRenderer = memo<ReactRendererProps>(({ code }) => {
8
- return (
9
- <SandpackProvider
10
- customSetup={{
11
- dependencies: {
12
- antd: 'latest',
13
- recharts: 'latest',
14
- },
15
- }}
16
- files={{
17
- 'App.js': code,
18
- }}
19
- options={{ externalResources: ['https://cdn.tailwindcss.com'] }}
20
- style={{ height: '100%' }}
21
- template="react"
22
- theme="auto"
23
- >
24
- <SandpackLayout style={{ height: '100%' }}>
25
- <SandpackPreview style={{ height: '100%' }} />
26
- </SandpackLayout>
27
- </SandpackProvider>
28
- );
29
- });
30
-
31
- export default ReactRenderer;
File without changes