ui: Constants refactor (#26908)
* refactor: Constants * refactor: Constants/Enums cleanup * refactor: Constant objects instead of multiple single value constants * refactor: Cleanup constants
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { LEGACY_AGENTIC_REGEX } from '$lib/constants/agentic';
|
||||
import { LEGACY_AGENTIC_REGEX } from '$lib/constants';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { CONFIG_LOCALSTORAGE_KEY } from '$lib/constants';
|
||||
import { SETTINGS_KEYS } from '$lib/constants/settings-keys';
|
||||
import { CONFIG_LOCALSTORAGE_KEY, SETTINGS_KEYS } from '$lib/constants';
|
||||
import type { DatabaseConversation } from '$lib/types/database';
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SETTINGS_KEYS } from '$lib/constants/settings-keys';
|
||||
import { SETTINGS_KEYS } from '$lib/constants';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
/**
|
||||
@@ -12,7 +12,7 @@ import { describe, expect, it } from 'vitest';
|
||||
*/
|
||||
describe('MCP_SERVERS default value', () => {
|
||||
it('does not preload any servers in the MCP_SERVERS setting default', async () => {
|
||||
const { SETTING_CONFIG_DEFAULT } = await import('$lib/constants/settings-registry');
|
||||
const { SETTING_CONFIG_DEFAULT } = await import('$lib/constants');
|
||||
|
||||
expect(SETTING_CONFIG_DEFAULT[SETTINGS_KEYS.MCP_SERVERS]).toBe('[]');
|
||||
}, 15000);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Client } from '@modelcontextprotocol/sdk/client';
|
||||
import { CORS_PROXY_HEADER_PREFIX } from '$lib/constants';
|
||||
import { CORS_PROXY } from '$lib/constants';
|
||||
import { MCPConnectionPhase, MCPTransportType } from '$lib/enums';
|
||||
import { MCPService } from '$lib/services/mcp.service';
|
||||
import type { MCPConnectionLog, MCPServerConfig } from '$lib/types';
|
||||
@@ -96,9 +96,9 @@ describe('MCPService', () => {
|
||||
|
||||
it('wraps dynamic request headers when using the CORS proxy', async () => {
|
||||
const logs: MCPConnectionLog[] = [];
|
||||
const proxiedAuthToken = `${CORS_PROXY_HEADER_PREFIX}x-auth-token`;
|
||||
const proxiedContentType = `${CORS_PROXY_HEADER_PREFIX}content-type`;
|
||||
const proxiedSessionId = `${CORS_PROXY_HEADER_PREFIX}mcp-session-id`;
|
||||
const proxiedAuthToken = `${CORS_PROXY.HEADER_PREFIX}x-auth-token`;
|
||||
const proxiedContentType = `${CORS_PROXY.HEADER_PREFIX}content-type`;
|
||||
const proxiedSessionId = `${CORS_PROXY.HEADER_PREFIX}mcp-session-id`;
|
||||
const response = new Response('{}', {
|
||||
headers: { 'content-type': 'application/json' },
|
||||
status: 200
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MCP_SERVER_ID_PREFIX } from '$lib/constants/mcp';
|
||||
import { MCP_SERVER_ID_PREFIX } from '$lib/constants';
|
||||
import { parseMcpServerSettings } from '$lib/utils/mcp';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CORS_PROXY_HEADER_PREFIX } from '$lib/constants';
|
||||
import { CORS_PROXY } from '$lib/constants';
|
||||
import { sanitizeHeaders } from '$lib/utils/api-headers';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
@@ -61,9 +61,9 @@ describe('sanitizeHeaders', () => {
|
||||
});
|
||||
|
||||
it('redacts proxied sensitive and custom target headers', () => {
|
||||
const proxiedAuthorization = `${CORS_PROXY_HEADER_PREFIX}authorization`;
|
||||
const proxiedSessionId = `${CORS_PROXY_HEADER_PREFIX}mcp-session-id`;
|
||||
const proxiedVendorKey = `${CORS_PROXY_HEADER_PREFIX}x-vendor-key`;
|
||||
const proxiedAuthorization = `${CORS_PROXY.HEADER_PREFIX}authorization`;
|
||||
const proxiedSessionId = `${CORS_PROXY.HEADER_PREFIX}mcp-session-id`;
|
||||
const proxiedVendorKey = `${CORS_PROXY.HEADER_PREFIX}x-vendor-key`;
|
||||
const headers = new Headers({
|
||||
[proxiedAuthorization]: 'Bearer secret',
|
||||
[proxiedSessionId]: 'session-12345',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { URI_TEMPLATE_OPERATORS } from '../../src/lib/constants/uri-template';
|
||||
import { URI_TEMPLATE_SYMBOLS } from '../../src/lib/constants/uri-template.constants';
|
||||
import {
|
||||
expandTemplate,
|
||||
extractTemplateVariables,
|
||||
@@ -26,7 +26,7 @@ describe('extractTemplateVariables', () => {
|
||||
it('extracts variables with operators', () => {
|
||||
const vars = extractTemplateVariables('http://example.com{+path}');
|
||||
|
||||
expect(vars).toEqual([{ name: 'path', operator: URI_TEMPLATE_OPERATORS.RESERVED }]);
|
||||
expect(vars).toEqual([{ name: 'path', operator: URI_TEMPLATE_SYMBOLS.RESERVED }]);
|
||||
});
|
||||
|
||||
it('extracts comma-separated variable lists', () => {
|
||||
@@ -48,13 +48,13 @@ describe('extractTemplateVariables', () => {
|
||||
it('handles fragment expansion', () => {
|
||||
const vars = extractTemplateVariables('http://example.com/page{#section}');
|
||||
|
||||
expect(vars).toEqual([{ name: 'section', operator: URI_TEMPLATE_OPERATORS.FRAGMENT }]);
|
||||
expect(vars).toEqual([{ name: 'section', operator: URI_TEMPLATE_SYMBOLS.FRAGMENT }]);
|
||||
});
|
||||
|
||||
it('handles path segment expansion', () => {
|
||||
const vars = extractTemplateVariables('http://example.com{/path}');
|
||||
|
||||
expect(vars).toEqual([{ name: 'path', operator: URI_TEMPLATE_OPERATORS.PATH_SEGMENT }]);
|
||||
expect(vars).toEqual([{ name: 'path', operator: URI_TEMPLATE_SYMBOLS.PATH_SEGMENT }]);
|
||||
});
|
||||
|
||||
it('returns empty array for template without variables', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GLOB_WILDCARD, PATH_NAV_MAX_DEPTH } from '$lib/constants';
|
||||
import { GLOB, SEARCH } from '$lib/constants';
|
||||
import {
|
||||
buildCaseInsensitiveGlob,
|
||||
buildGlobSearchArgs,
|
||||
@@ -148,7 +148,7 @@ describe('buildGlobSearchArgs', () => {
|
||||
|
||||
expect(args.path).toBe('~');
|
||||
expect(args.include).toBe(buildCaseInsensitiveGlob('proj'));
|
||||
expect(args.maxDepth).toBe(PATH_NAV_MAX_DEPTH);
|
||||
expect(args.maxDepth).toBe(SEARCH.PATH_NAV_MAX_DEPTH);
|
||||
expect(args.rankQuery).toBe('proj');
|
||||
expect(args.last).toBe('proj');
|
||||
});
|
||||
@@ -157,8 +157,8 @@ describe('buildGlobSearchArgs', () => {
|
||||
const args = buildGlobSearchArgs('~/', '/home', DEPTH);
|
||||
|
||||
expect(args.path).toBe('~');
|
||||
expect(args.include).toBe(GLOB_WILDCARD);
|
||||
expect(args.maxDepth).toBe(PATH_NAV_MAX_DEPTH);
|
||||
expect(args.include).toBe(GLOB.WILDCARD);
|
||||
expect(args.maxDepth).toBe(SEARCH.PATH_NAV_MAX_DEPTH);
|
||||
});
|
||||
|
||||
it('navigates an absolute path under its root', () => {
|
||||
@@ -166,7 +166,7 @@ describe('buildGlobSearchArgs', () => {
|
||||
|
||||
expect(args.path).toBe('/usr/local');
|
||||
expect(args.include).toBe(buildCaseInsensitiveGlob('bin'));
|
||||
expect(args.maxDepth).toBe(PATH_NAV_MAX_DEPTH);
|
||||
expect(args.maxDepth).toBe(SEARCH.PATH_NAV_MAX_DEPTH);
|
||||
expect(args.rankQuery).toBe('bin');
|
||||
expect(args.last).toBe('bin');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user