refactor: Cleanup
This commit is contained in:
parent
8bf2d38da1
commit
3d7426cdd4
|
|
@ -366,13 +366,20 @@
|
|||
'agenticMaxToolPreviewLines'
|
||||
];
|
||||
|
||||
const positiveIntegerFields = ['agenticMaxTurns', 'agenticMaxToolPreviewLines'];
|
||||
|
||||
for (const field of numericFields) {
|
||||
if (processedConfig[field] !== undefined && processedConfig[field] !== '') {
|
||||
const numValue = Number(processedConfig[field]);
|
||||
if (!isNaN(numValue)) {
|
||||
processedConfig[field] = numValue;
|
||||
if (positiveIntegerFields.includes(field)) {
|
||||
processedConfig[field] = Math.max(1, Math.round(numValue));
|
||||
} else {
|
||||
processedConfig[field] = numValue;
|
||||
}
|
||||
} else {
|
||||
alert(`Invalid numeric value for ${field}. Please enter a valid number.`);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import type { AgenticMessage, AgenticConfig } from '$lib/types/agentic';
|
|||
import type { SettingsConfigType } from '$lib/types/settings';
|
||||
import type { McpServerOverride } from '$lib/types/database';
|
||||
import { DEFAULT_AGENTIC_CONFIG } from '$lib/constants/agentic';
|
||||
import { normalizePositiveNumber } from '$lib/utils/number';
|
||||
import { mcpStore } from '$lib/stores/mcp.svelte';
|
||||
import { MessageRole } from '$lib/enums';
|
||||
|
||||
|
|
@ -17,14 +16,9 @@ export function getAgenticConfig(
|
|||
settings: SettingsConfigType,
|
||||
perChatOverrides?: McpServerOverride[]
|
||||
): AgenticConfig {
|
||||
const maxTurns = normalizePositiveNumber(
|
||||
settings.agenticMaxTurns,
|
||||
DEFAULT_AGENTIC_CONFIG.maxTurns
|
||||
);
|
||||
const maxToolPreviewLines = normalizePositiveNumber(
|
||||
settings.agenticMaxToolPreviewLines,
|
||||
DEFAULT_AGENTIC_CONFIG.maxToolPreviewLines
|
||||
);
|
||||
const maxTurns = Number(settings.agenticMaxTurns) || DEFAULT_AGENTIC_CONFIG.maxTurns;
|
||||
const maxToolPreviewLines =
|
||||
Number(settings.agenticMaxToolPreviewLines) || DEFAULT_AGENTIC_CONFIG.maxToolPreviewLines;
|
||||
|
||||
return {
|
||||
enabled: mcpStore.hasEnabledServers(perChatOverrides) && DEFAULT_AGENTIC_CONFIG.enabled,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import type { SettingsConfigType } from '$lib/types/settings';
|
|||
import type { McpServerOverride } from '$lib/types/database';
|
||||
import { MCPTransportType, MCPLogLevel, HealthCheckStatus } from '$lib/enums';
|
||||
import { DEFAULT_MCP_CONFIG } from '$lib/constants/mcp';
|
||||
import { normalizePositiveNumber } from '$lib/utils/number';
|
||||
import { Info, AlertTriangle, XCircle } from '@lucide/svelte';
|
||||
import type { Component } from 'svelte';
|
||||
|
||||
|
|
@ -110,14 +109,11 @@ export function serializeHeaders(pairs: { key: string; value: string }[]): strin
|
|||
|
||||
/**
|
||||
* Parses MCP server settings from a JSON string or array.
|
||||
* requestTimeoutSeconds is not user-configurable in the UI, so we always use the default value.
|
||||
* @param rawServers - The raw servers to parse
|
||||
* @param fallbackRequestTimeoutSeconds - The fallback request timeout seconds
|
||||
* @returns An empty array if the input is invalid.
|
||||
*/
|
||||
export function parseMcpServerSettings(
|
||||
rawServers: unknown,
|
||||
fallbackRequestTimeoutSeconds = DEFAULT_MCP_CONFIG.requestTimeoutSeconds
|
||||
): MCPServerSettingsEntry[] {
|
||||
export function parseMcpServerSettings(rawServers: unknown): MCPServerSettingsEntry[] {
|
||||
if (!rawServers) return [];
|
||||
|
||||
let parsed: unknown;
|
||||
|
|
@ -138,11 +134,6 @@ export function parseMcpServerSettings(
|
|||
if (!Array.isArray(parsed)) return [];
|
||||
|
||||
return parsed.map((entry, index) => {
|
||||
const requestTimeoutSeconds = normalizePositiveNumber(
|
||||
(entry as { requestTimeoutSeconds?: unknown })?.requestTimeoutSeconds,
|
||||
fallbackRequestTimeoutSeconds
|
||||
);
|
||||
|
||||
const url = typeof entry?.url === 'string' ? entry.url.trim() : '';
|
||||
const headers = typeof entry?.headers === 'string' ? entry.headers.trim() : undefined;
|
||||
|
||||
|
|
@ -150,7 +141,7 @@ export function parseMcpServerSettings(
|
|||
id: generateMcpServerId((entry as { id?: unknown })?.id, index),
|
||||
enabled: Boolean((entry as { enabled?: unknown })?.enabled),
|
||||
url,
|
||||
requestTimeoutSeconds,
|
||||
requestTimeoutSeconds: DEFAULT_MCP_CONFIG.requestTimeoutSeconds,
|
||||
headers: headers || undefined
|
||||
} satisfies MCPServerSettingsEntry;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
/**
|
||||
* Normalizes a value to a positive number, returning the fallback if invalid.
|
||||
* Handles both string and number inputs.
|
||||
*/
|
||||
export function normalizePositiveNumber(value: unknown, fallback: number): number {
|
||||
const parsed = typeof value === 'string' ? Number.parseFloat(value) : Number(value);
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
return fallback;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
Loading…
Reference in New Issue