docs: add descriptive comments to hardcoded magic numbers
- userApi.ts: Extract DEFAULT_API_TOKEN_TTL_SECONDS constant (157680000 = 5 years) - agentControlApi.ts: Extract DEFAULT_LOGS_LIMIT (500) and DEFAULT_AGGREGATED_LOGS_LIMIT (100) constants - useAgentStatus.ts: Add comment explaining RECONNECT_DELAY_MS purpose Closes #8
This commit is contained in:
@@ -2,6 +2,9 @@ import { useState, useRef, useCallback, useEffect } from 'react'
|
||||
import type { AgentStatus } from '@/types/agentControl'
|
||||
|
||||
const HIVE_URL = import.meta.env.VITE_API_URL || 'http://localhost:4000'
|
||||
// Delay before attempting to reconnect after SSE stream disconnection or error
|
||||
// 5 seconds provides a reasonable balance between responsiveness and avoiding
|
||||
// rapid retry loops.
|
||||
const RECONNECT_DELAY_MS = 5000
|
||||
|
||||
interface UseAgentStatusOptions {
|
||||
|
||||
@@ -66,6 +66,14 @@ export function getAnalyticsNarrow(): Promise<RawJsonData> {
|
||||
// Logs Endpoints
|
||||
// =============================================================================
|
||||
|
||||
// Default pagination limits for log queries.
|
||||
|
||||
// Higher limit for raw logs - balances data completeness with response size.
|
||||
const DEFAULT_LOGS_LIMIT = 500
|
||||
|
||||
// Lower limit for grouped results - typically fewer unique groups needed.
|
||||
const DEFAULT_AGGREGATED_LOGS_LIMIT = 100
|
||||
|
||||
/**
|
||||
* Get raw logs for a time range
|
||||
* @param start - ISO date string
|
||||
@@ -77,7 +85,7 @@ export function getAnalyticsNarrow(): Promise<RawJsonData> {
|
||||
export function getLogs(
|
||||
start: string,
|
||||
end: string,
|
||||
limit = 500,
|
||||
limit = DEFAULT_LOGS_LIMIT,
|
||||
offset = 0,
|
||||
filters?: { type?: string; success?: string }
|
||||
): Promise<RawJsonData> {
|
||||
@@ -103,7 +111,7 @@ export function getLogsAggregated(
|
||||
start: string,
|
||||
end: string,
|
||||
groupBy: string,
|
||||
limit = 100
|
||||
limit = DEFAULT_AGGREGATED_LOGS_LIMIT
|
||||
): Promise<RawJsonData> {
|
||||
return hiveClient.get(
|
||||
`/tsdb/logs?start=${encodeURIComponent(start)}&end=${encodeURIComponent(end)}&group_by=${groupBy}&limit=${limit}`
|
||||
|
||||
@@ -9,6 +9,9 @@ import type {
|
||||
TeamRoleResponse,
|
||||
} from '@/types/user'
|
||||
|
||||
// 5 years in seconds (5 * 365 * 24 * 60 * 60) - default TTL for API tokens.
|
||||
const DEFAULT_API_TOKEN_TTL_SECONDS = 157680000
|
||||
|
||||
// Profile Management
|
||||
export const getUserProfile = () =>
|
||||
serverClient.get<UserProfileResponse>('/user/profile')
|
||||
@@ -23,10 +26,10 @@ export const updateUserAvatar = (data: UpdateAvatarPayload) =>
|
||||
export const getAPITokens = () =>
|
||||
serverClient.get<APITokensResponse>('/user/get-dev-tokens')
|
||||
|
||||
export const createAPIToken = (label: string, ttl: number = 157680000) =>
|
||||
export const createAPIToken = (label: string, ttl: number = DEFAULT_API_TOKEN_TTL_SECONDS) =>
|
||||
serverClient.post<APITokenResponse>('/user/generate-dev-token', {
|
||||
label,
|
||||
ttl, // Default: ~5 years
|
||||
ttl,
|
||||
} as CreateAPITokenPayload)
|
||||
|
||||
// Team/Role (needed for org initialization)
|
||||
|
||||
Reference in New Issue
Block a user