Skip to content

Commit

Permalink
⚡️ perf: update agent index url (lobehub#4861)
Browse files Browse the repository at this point in the history
* update agent index

* fix test

* improve url

* fix test
  • Loading branch information
arvinxx authored Dec 2, 2024
1 parent 7b11deb commit 9731b0d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/config/__tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('getServerConfig', () => {
describe('index url', () => {
it('should return default URLs when no environment variables are set', () => {
const config = getAppConfig();
expect(config.AGENTS_INDEX_URL).toBe('https://chat-agents.lobehub.com');
expect(config.AGENTS_INDEX_URL).toBe('https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public');
expect(config.PLUGINS_INDEX_URL).toBe('https://chat-plugins.lobehub.com');
});

Expand All @@ -41,7 +41,7 @@ describe('getServerConfig', () => {
process.env.PLUGINS_INDEX_URL = '';

const config = getAppConfig();
expect(config.AGENTS_INDEX_URL).toBe('https://chat-agents.lobehub.com');
expect(config.AGENTS_INDEX_URL).toBe('https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public');
expect(config.PLUGINS_INDEX_URL).toBe('https://chat-plugins.lobehub.com');
});
});
Expand Down
9 changes: 7 additions & 2 deletions src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ if (typeof window === 'undefined' && isServerMode && !APP_URL) {
throw new Error('`APP_URL` is required in server mode');
}

const ASSISTANT_INDEX_URL =
'https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public';

const PLUGINS_INDEX_URL = 'https://chat-plugins.lobehub.com';

export const getAppConfig = () => {
const ACCESS_CODES = process.env.ACCESS_CODE?.split(',').filter(Boolean) || [];

Expand Down Expand Up @@ -60,14 +65,14 @@ export const getAppConfig = () => {

AGENTS_INDEX_URL: !!process.env.AGENTS_INDEX_URL
? process.env.AGENTS_INDEX_URL
: 'https://chat-agents.lobehub.com',
: ASSISTANT_INDEX_URL,

DEFAULT_AGENT_CONFIG: process.env.DEFAULT_AGENT_CONFIG || '',
SYSTEM_AGENT: process.env.SYSTEM_AGENT,

PLUGINS_INDEX_URL: !!process.env.PLUGINS_INDEX_URL
? process.env.PLUGINS_INDEX_URL
: 'https://chat-plugins.lobehub.com',
: PLUGINS_INDEX_URL,

PLUGIN_SETTINGS: process.env.PLUGIN_SETTINGS,

Expand Down
8 changes: 4 additions & 4 deletions src/server/modules/AssistantStore/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest';

import { AssistantStore } from './index';

const baseURL = 'https://chat-agents.lobehub.com';
const baseURL = 'https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public';
describe('AssistantStore', () => {
it('should return the default index URL when no language is provided', () => {
const agentMarket = new AssistantStore();
Expand All @@ -14,19 +14,19 @@ describe('AssistantStore', () => {
it('should return the index URL for a not supported language', () => {
const agentMarket = new AssistantStore();
const url = agentMarket.getAgentIndexUrl('xxx' as any);
expect(url).toBe('https://chat-agents.lobehub.com');
expect(url).toBe('https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public');
});

it('should return the zh-CN URL for zh locale', () => {
const agentMarket = new AssistantStore();
const url = agentMarket.getAgentIndexUrl('zh' as any);
expect(url).toBe('https://chat-agents.lobehub.com/index.zh-CN.json');
expect(url).toBe('https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public/index.zh-CN.json');
});

it('should return the default URL for en locale', () => {
const agentMarket = new AssistantStore();
const url = agentMarket.getAgentIndexUrl('en' as any);
expect(url).toBe('https://chat-agents.lobehub.com');
expect(url).toBe('https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public');
});

it('should return the base URL if the provided language is not supported', () => {
Expand Down

0 comments on commit 9731b0d

Please sign in to comment.