Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor: remove edge runtime (#9085)

Arvin Xud3544f90d30b
diff --git a/src/app/(backend)/webapi/chat/[provider]/route.ts b/src/app/(backend)/webapi/chat/[provider]/route.ts
index de47609a8b5..3a5fefd4931 100644
--- a/src/app/(backend)/webapi/chat/[provider]/route.ts
+++ b/src/app/(backend)/webapi/chat/[provider]/route.ts
@@ -11,7 +11,7 @@ import { ChatStreamPayload } from '@/types/openai/chat';
import { createErrorResponse } from '@/utils/errorResponse';
import { getTracePayload } from '@/utils/trace';
-export const runtime = 'edge';
+export const maxDuration = 300;
export const POST = checkAuth(async (req: Request, { params, jwtPayload, createRuntime }) => {
const { provider } = await params;
diff --git a/src/app/(backend)/webapi/chat/anthropic/route.test.ts b/src/app/(backend)/webapi/chat/anthropic/route.test.ts
deleted file mode 100644
index 581daedb3b2..00000000000
--- a/src/app/(backend)/webapi/chat/anthropic/route.test.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-// @vitest-environment edge-runtime
-import { describe, expect, it, vi } from 'vitest';
-
-import { POST as UniverseRoute } from '../[provider]/route';
-import { POST, preferredRegion, runtime } from './route';
-
-// 模拟 '../[provider]/route'
-vi.mock('../[provider]/route', () => ({
- POST: vi.fn().mockResolvedValue('mocked response'),
-}));
-
-describe('Configuration tests', () => {
- it('should have runtime set to "edge"', () => {
- expect(runtime).toBe('edge');
- });
-
- it('should contain specific regions in preferredRegion', () => {
- expect(preferredRegion).not.contain(['hk1']);
- });
-});
-
-describe('Anthropic POST function tests', () => {
- it('should call UniverseRoute with correct parameters', async () => {
- const mockRequest = new Request('https://example.com', { method: 'POST' });
- await POST(mockRequest);
- expect(UniverseRoute).toHaveBeenCalledWith(mockRequest, {
- params: Promise.resolve({ provider: 'anthropic' }),
- });
- });
-});
diff --git a/src/app/(backend)/webapi/chat/anthropic/route.ts b/src/app/(backend)/webapi/chat/anthropic/route.ts
deleted file mode 100644
index 31ca09ff44f..00000000000
--- a/src/app/(backend)/webapi/chat/anthropic/route.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { POST as UniverseRoute } from '../[provider]/route';
-
-export const runtime = 'edge';
-
-export const preferredRegion = [
- 'bom1',
- 'cle1',
- 'cpt1',
- 'gru1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1',
-];
-
-export const POST = async (req: Request) =>
- UniverseRoute(req, { params: Promise.resolve({ provider: 'anthropic' }) });
diff --git a/src/app/(backend)/webapi/chat/google/route.test.ts b/src/app/(backend)/webapi/chat/google/route.test.ts
deleted file mode 100644
index c5aab99f404..00000000000
--- a/src/app/(backend)/webapi/chat/google/route.test.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-// @vitest-environment edge-runtime
-import { describe, expect, it, vi } from 'vitest';
-
-import { POST as UniverseRoute } from '../[provider]/route';
-import { POST, preferredRegion, runtime } from './route';
-
-// 模拟 '../[provider]/route'
-vi.mock('../[provider]/route', () => ({
- POST: vi.fn().mockResolvedValue('mocked response'),
-}));
-
-describe('Configuration tests', () => {
- it('should have runtime set to "edge"', () => {
- expect(runtime).toBe('edge');
- });
-
- it('should contain specific regions in preferredRegion', () => {
- expect(preferredRegion).not.contain(['hkg1']);
- expect(preferredRegion).not.contain(['dub1']);
- expect(preferredRegion).not.contain(['cdg1']);
- expect(preferredRegion).not.contain(['fra1']);
- expect(preferredRegion).not.contain(['lhr1']);
- expect(preferredRegion).not.contain(['arn1']);
- });
-});
-
-describe('Google POST function tests', () => {
- it('should call UniverseRoute with correct parameters', async () => {
- const mockRequest = new Request('https://example.com', { method: 'POST' });
- await POST(mockRequest);
- expect(UniverseRoute).toHaveBeenCalledWith(mockRequest, {
- params: Promise.resolve({ provider: 'google' }),
- });
- });
-});
diff --git a/src/app/(backend)/webapi/chat/google/route.ts b/src/app/(backend)/webapi/chat/google/route.ts
deleted file mode 100644
index 075b23900a0..00000000000
--- a/src/app/(backend)/webapi/chat/google/route.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { POST as UniverseRoute } from '../[provider]/route';
-
-export const runtime = 'edge';
-
-// due to Gemini-1.5-pro is not available in Hong Kong, we need to set the preferred region to exclude "Hong Kong (hkg1)".
-// the paid service of the Gemini API is required in the following regions until 8 July 2024. The free service is not available. Therefore, the regions is temporarily disabled.
-// regions include Dublin (dub1, Ireland), Paris (cdg1, France), Frankfurt (fra1, Germany), London (lhr1, UK), and Stockholm (arn1, Sweden).
-// refs: https://ai.google.dev/gemini-api/docs/available-regions
-export const preferredRegion = [
- 'icn1',
- 'sin1',
- 'hnd1',
- 'kix1',
- 'bom1',
- 'cpt1',
- 'pdx1',
- 'cle1',
- 'syd1',
- 'iad1',
- 'sfo1',
- 'gru1',
-];
-
-export const POST = async (req: Request) =>
- UniverseRoute(req, { params: Promise.resolve({ provider: 'google' }) });
diff --git a/src/app/(backend)/webapi/chat/groq/route.test.ts b/src/app/(backend)/webapi/chat/groq/route.test.ts
deleted file mode 100644
index 943203cd3a3..00000000000
--- a/src/app/(backend)/webapi/chat/groq/route.test.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-// @vitest-environment edge-runtime
-import { describe, expect, it, vi } from 'vitest';
-
-import { POST as UniverseRoute } from '../[provider]/route';
-import { POST, preferredRegion, runtime } from './route';
-
-vi.mock('../[provider]/route', () => ({
- POST: vi.fn().mockResolvedValue('mocked response'),
-}));
-
-describe('Configuration tests', () => {
- it('should have runtime set to "edge"', () => {
- expect(runtime).toBe('edge');
- });
-
- it('should contain specific regions in preferredRegion', () => {
- expect(preferredRegion).not.contain(['hk1']);
- });
-});
-
-describe('Groq POST function tests', () => {
- it('should call UniverseRoute with correct parameters', async () => {
- const mockRequest = new Request('https://example.com', { method: 'POST' });
- await POST(mockRequest);
- expect(UniverseRoute).toHaveBeenCalledWith(mockRequest, {
- params: Promise.resolve({ provider: 'groq' }),
- });
- });
-});
diff --git a/src/app/(backend)/webapi/chat/groq/route.ts b/src/app/(backend)/webapi/chat/groq/route.ts
deleted file mode 100644
index 4c334721a2d..00000000000
--- a/src/app/(backend)/webapi/chat/groq/route.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { POST as UniverseRoute } from '../[provider]/route';
-
-export const runtime = 'edge';
-
-export const preferredRegion = [
- 'bom1',
- 'cle1',
- 'cpt1',
- 'gru1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1',
-];
-
-export const POST = async (req: Request) =>
- UniverseRoute(req, { params: Promise.resolve({ provider: 'groq' }) });
diff --git a/src/app/(backend)/webapi/chat/openai/route.test.ts b/src/app/(backend)/webapi/chat/openai/route.test.ts
deleted file mode 100644
index 7b403592b96..00000000000
--- a/src/app/(backend)/webapi/chat/openai/route.test.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-// @vitest-environment edge-runtime
-import { describe, expect, it, vi } from 'vitest';
-
-import { POST as UniverseRoute } from '../[provider]/route';
-import { POST, preferredRegion, runtime } from './route';
-
-// 模拟 '../[provider]/route'
-vi.mock('../[provider]/route', () => ({
- POST: vi.fn().mockResolvedValue('mocked response'),
-}));
-
-describe('Configuration tests', () => {
- it('should have runtime set to "edge"', () => {
- expect(runtime).toBe('edge');
- });
-
- it('should contain specific regions in preferredRegion', () => {
- expect(preferredRegion).not.contain(['hkg1']);
- });
-});
-
-describe('OpenAI POST function tests', () => {
- it('should call UniverseRoute with correct parameters', async () => {
- const mockRequest = new Request('https://example.com', { method: 'POST' });
- await POST(mockRequest);
- expect(UniverseRoute).toHaveBeenCalledWith(mockRequest, {
- params: Promise.resolve({ provider: 'openai' }),
- });
- });
-});
diff --git a/src/app/(backend)/webapi/chat/openai/route.ts b/src/app/(backend)/webapi/chat/openai/route.ts
deleted file mode 100644
index bff4739e81d..00000000000
--- a/src/app/(backend)/webapi/chat/openai/route.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { POST as UniverseRoute } from '../[provider]/route';
-
-export const runtime = 'edge';
-
-export const preferredRegion = [
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1',
-];
-
-export const POST = async (req: Request) =>
- UniverseRoute(req, { params: Promise.resolve({ provider: 'openai' }) });
diff --git a/src/app/(backend)/webapi/chat/vertexai/route.ts b/src/app/(backend)/webapi/chat/vertexai/route.ts
index e1a7f7a4f13..e03efcde640 100644
--- a/src/app/(backend)/webapi/chat/vertexai/route.ts
+++ b/src/app/(backend)/webapi/chat/vertexai/route.ts
@@ -6,6 +6,7 @@ import { safeParseJSON } from '@/utils/safeParseJSON';
import { POST as UniverseRoute } from '../[provider]/route';
+export const maxDuration = 300;
// due to the Chinese region does not support accessing Google
// we need to use proxy to access it
// refs: https://github.com/google/generative-ai-js/issues/29#issuecomment-1866246513