🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(model-runtime): declare OpenRouter app categories for rankings (#21641)
LiJian3b42bb88b15a
diff --git a/packages/model-runtime/src/providers/openrouter/index.attribution.test.ts b/packages/model-runtime/src/providers/openrouter/index.attribution.test.tsnew file mode 100644index 00000000000..20b68dd3335--- /dev/null+++ b/packages/model-runtime/src/providers/openrouter/index.attribution.test.ts@@ -0,0 +1,36 @@+// @vitest-environment node+import { describe, expect, it, vi } from 'vitest';++import { LobeOpenRouterAI, params } from './index';++vi.mock('@lobechat/business-model-bank/model-config', () => ({+ loadModels: vi.fn().mockResolvedValue([]),+}));++const ATTRIBUTION_HEADERS = {+ 'HTTP-Referer': 'https://lobehub.com',+ 'X-OpenRouter-Categories': 'personal-agent,general-chat',+ 'X-OpenRouter-Title': 'LobeHub',+};++describe('LobeOpenRouterAI app attribution', () => {+ it('declares the attribution headers', () => {+ expect(params.constructorOptions.defaultHeaders).toEqual(ATTRIBUTION_HEADERS);+ });++ it('sends the attribution headers on requests', async () => {+ const fetchMock = vi.fn().mockResolvedValue(+ new Response(JSON.stringify({ data: [], object: 'list' }), {+ headers: { 'content-type': 'application/json' },+ }),+ );+ const instance = new LobeOpenRouterAI({ apiKey: 'test', fetch: fetchMock });++ await instance['client'].models.list();++ const headers = new Headers(fetchMock.mock.calls[0][1].headers);+ for (const [name, value] of Object.entries(ATTRIBUTION_HEADERS)) {+ expect(headers.get(name)).toBe(value);+ }+ });+});diff --git a/packages/model-runtime/src/providers/openrouter/index.test.ts b/packages/model-runtime/src/providers/openrouter/index.test.tsindex 886b2591581..5e111cce762 100644--- a/packages/model-runtime/src/providers/openrouter/index.test.ts+++ b/packages/model-runtime/src/providers/openrouter/index.test.ts@@ -30,15 +30,6 @@ afterEach(() => {});describe('LobeOpenRouterAI - custom features', () => {- describe('Params Export', () => {- it('should have constructorOptions with headers', () => {- expect(params.constructorOptions).toBeDefined();- expect(params.constructorOptions.defaultHeaders).toBeDefined();- expect(params.constructorOptions.defaultHeaders['HTTP-Referer']).toBe('https://lobehub.com');- expect(params.constructorOptions.defaultHeaders['X-Title']).toBe('LobeHub');- });- });-describe('Debug Configuration', () => {it('should disable debug by default', () => {delete process.env.DEBUG_OPENROUTER_CHAT_COMPLETION;@@ -55,13 +46,6 @@ describe('LobeOpenRouterAI - custom features', () => {});describe('Constructor Options', () => {- it('should set default headers', () => {- const instance = new LobeOpenRouterAI({ apiKey: 'test' });- expect(instance).toBeDefined();- // Headers are set in constructorOptions but not directly accessible- // We can verify by checking that the instance was created successfully- });-it('should use custom base URL when provided', () => {const customBaseURL = 'https://custom.openrouter.ai/api/v1';const instance = new LobeOpenRouterAI({ apiKey: 'test', baseURL: customBaseURL });diff --git a/packages/model-runtime/src/providers/openrouter/index.ts b/packages/model-runtime/src/providers/openrouter/index.tsindex 91b76b72488..3d971885e4a 100644--- a/packages/model-runtime/src/providers/openrouter/index.ts+++ b/packages/model-runtime/src/providers/openrouter/index.ts@@ -97,9 +97,12 @@ export const params = {},},constructorOptions: {+ // App attribution for OpenRouter rankings: https://openrouter.ai/docs/app-attribution+ // Categories accept at most 2 recognized values per request and cannot be removed once merged.defaultHeaders: {'HTTP-Referer': 'https://lobehub.com',- 'X-Title': 'LobeHub',+ 'X-OpenRouter-Categories': 'personal-agent,general-chat',+ 'X-OpenRouter-Title': 'LobeHub',},},debug: {