Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions archon-ui-main/src/config/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@

// Get the API URL from environment or construct it
export function getApiUrl(): string {
// Check if VITE_API_URL is provided (set by docker-compose)
// 1. Priority: VITE_API_URL from environment (e.g., Docker)
if (import.meta.env.VITE_API_URL) {
return import.meta.env.VITE_API_URL;
return import.meta.env.VITE_API_URL
}

// In both development (via Vite proxy) and production, we use a relative path.
// This ensures that requests are proxied correctly by the dev server or
// sent to the same origin in production.
return '';
// 2. Production mode: Use relative path
if (import.meta.env.PROD) {
return ''
}

// 3. Development mode: Construct URL from port
const port = import.meta.env.ARCHON_SERVER_PORT
if (!port) {
throw new Error(
'ARCHON_SERVER_PORT environment variable is required. ' +
'Please set it in your .env file. ' +
'Default value: 8181',
)
}

const protocol = window.location.protocol
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Prefira a desestruturação de objetos ao acessar e usar propriedades. (use-object-destructuring)

Suggested change
const protocol = window.location.protocol
const {protocol} = window.location


ExplicaçãoA desestruturação de objetos pode frequentemente remover uma referência temporária desnecessária, além de tornar seu código mais sucinto.

Do Guia de Estilo JavaScript do Airbnb

Original comment in English

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
const protocol = window.location.protocol
const {protocol} = window.location


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

const hostname = window.location.hostname
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Prefira a desestruturação de objetos ao acessar e usar propriedades. (use-object-destructuring)

Suggested change
const hostname = window.location.hostname
const {hostname} = window.location


ExplicaçãoA desestruturação de objetos pode frequentemente remover uma referência temporária desnecessária, além de tornar seu código mais sucinto.

Do Guia de Estilo JavaScript do Airbnb

Original comment in English

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
const hostname = window.location.hostname
const {hostname} = window.location


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

return `${protocol}//${hostname}:${port}`
}

// Get the base path for API endpoints
Expand Down
4 changes: 1 addition & 3 deletions archon-ui-main/src/services/mcpClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@ const MCPToolSchema = z.object({
export type MCPTool = z.infer<typeof MCPToolSchema>;
export type MCPParameter = z.infer<typeof MCPParameterSchema>;

import { getApiUrl } from '../config/api';

/**
* MCP Client Service - Universal MCP client that connects to any MCP servers
* This service communicates with the standalone Python MCP client service
*/
class MCPClientService {
export class MCPClientService {
private baseUrl = getApiUrl();

// ========================================
Expand Down
9 changes: 5 additions & 4 deletions archon-ui-main/test/config/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ describe('API Configuration', () => {
delete (import.meta.env as any).VITE_API_URL;
delete (import.meta.env as any).ARCHON_SERVER_PORT;

const { getApiUrl } = await import('../../src/config/api');

expect(() => getApiUrl()).toThrow('ARCHON_SERVER_PORT environment variable is required');
expect(() => getApiUrl()).toThrow('Default value: 8181');
// The import() promise should reject because a top-level statement calls getApiUrl()
// which will throw an error when ARCHON_SERVER_PORT is not set.
await expect(import('../../src/config/api')).rejects.toThrow(
/ARCHON_SERVER_PORT environment variable is required.*Default value: 8181/
);
});

it('should use ARCHON_SERVER_PORT when set in development', async () => {
Expand Down
9 changes: 1 addition & 8 deletions archon-ui-main/test/errors.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe('Error Handling Tests', () => {
})

test('timeout error simulation', async () => {
vi.useFakeTimers()
const MockTimeoutComponent = () => {
const [status, setStatus] = React.useState('idle')

Expand All @@ -62,14 +61,8 @@ describe('Error Handling Tests', () => {
fireEvent.click(screen.getByText('Start Request'))
expect(screen.getByText('Loading...')).toBeInTheDocument()

// Fast-forward time
await act(async () => {
await vi.advanceTimersByTimeAsync(150)
})

const alert = await screen.findByRole('alert')
const alert = await screen.findByRole('alert', {}, { timeout: 500 })
expect(alert).toHaveTextContent('Request timed out')
vi.useRealTimers()
})

test('form validation errors', () => {
Expand Down