refactor: Types
This commit is contained in:
parent
dfd3031b17
commit
6f7750489e
|
|
@ -21,6 +21,7 @@
|
|||
import githubLightCss from 'highlight.js/styles/github.css?inline';
|
||||
import { mode } from 'mode-watcher';
|
||||
import CodePreviewDialog from './CodePreviewDialog.svelte';
|
||||
import { getImageErrorFallbackHtml } from '$lib/utils/image-error-fallback';
|
||||
|
||||
interface Props {
|
||||
content: string;
|
||||
|
|
@ -345,24 +346,7 @@
|
|||
// Create fallback element
|
||||
const fallback = document.createElement('div');
|
||||
fallback.className = 'image-load-error';
|
||||
fallback.innerHTML = `
|
||||
<div class="image-error-content">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect width="18" height="18" x="3" y="3" rx="2" ry="2"/>
|
||||
<circle cx="9" cy="9" r="2"/>
|
||||
<path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/>
|
||||
</svg>
|
||||
<span class="image-error-text">External image cannot be displayed</span>
|
||||
<a href="${src}" target="_blank" rel="noopener noreferrer" class="image-error-link">
|
||||
<span>Open in new tab</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
|
||||
<polyline points="15 3 21 3 21 9"/>
|
||||
<line x1="10" x2="21" y1="14" y2="3"/>
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
fallback.innerHTML = getImageErrorFallbackHtml(src);
|
||||
|
||||
// Replace image with fallback
|
||||
img.parentNode?.replaceChild(fallback, img);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
import type { MCPClientConfig, MCPServerConfig, MCPServerSettingsEntry } from '$lib/types/mcp';
|
||||
import type {
|
||||
MCPClientConfig,
|
||||
MCPServerConfig,
|
||||
MCPServerSettingsEntry,
|
||||
McpServerUsageStats
|
||||
} from '$lib/types/mcp';
|
||||
import type { SettingsConfigType } from '$lib/types/settings';
|
||||
import type { McpServerOverride } from '$lib/types/database';
|
||||
import { DEFAULT_MCP_CONFIG } from '$lib/constants/mcp';
|
||||
|
|
@ -144,8 +149,6 @@ export function hasEnabledMcpServers(
|
|||
// MCP Server Usage Stats
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
export type McpServerUsageStats = Record<string, number>;
|
||||
|
||||
/**
|
||||
* Parse MCP server usage stats from settings.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -21,41 +21,17 @@
|
|||
* - Automatic tool-to-server routing
|
||||
*/
|
||||
|
||||
import { MCPServerConnection, type ToolExecutionResult } from './server-connection';
|
||||
import { MCPServerConnection } from './server-connection';
|
||||
import type { ToolExecutionResult } from '$lib/types/mcp';
|
||||
import type {
|
||||
MCPClientConfig,
|
||||
MCPToolCall,
|
||||
ClientCapabilities,
|
||||
Implementation
|
||||
MCPHostManagerConfig,
|
||||
OpenAIToolDefinition,
|
||||
ServerStatus
|
||||
} from '$lib/types/mcp';
|
||||
import { MCPError } from '$lib/errors';
|
||||
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
||||
|
||||
export interface MCPHostManagerConfig {
|
||||
/** Server configurations keyed by server name */
|
||||
servers: MCPClientConfig['servers'];
|
||||
/** Client info to advertise to all servers */
|
||||
clientInfo?: Implementation;
|
||||
/** Default capabilities to advertise */
|
||||
capabilities?: ClientCapabilities;
|
||||
}
|
||||
|
||||
export interface OpenAIToolDefinition {
|
||||
type: 'function';
|
||||
function: {
|
||||
name: string;
|
||||
description?: string;
|
||||
parameters: Record<string, unknown>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ServerStatus {
|
||||
name: string;
|
||||
isConnected: boolean;
|
||||
toolCount: number;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages multiple MCP server connections and provides unified tool access.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,20 +1,6 @@
|
|||
// New architecture exports
|
||||
export { MCPHostManager } from './host-manager';
|
||||
export type { MCPHostManagerConfig, OpenAIToolDefinition, ServerStatus } from './host-manager';
|
||||
export { MCPServerConnection } from './server-connection';
|
||||
export type {
|
||||
MCPServerConnectionConfig,
|
||||
ToolCallParams,
|
||||
ToolExecutionResult
|
||||
} from './server-connection';
|
||||
|
||||
// Errors
|
||||
export { MCPError } from '$lib/errors';
|
||||
|
||||
// Types
|
||||
export type {
|
||||
MCPClientConfig,
|
||||
MCPServerConfig,
|
||||
MCPToolCall,
|
||||
MCPServerSettingsEntry
|
||||
} from '$lib/types/mcp';
|
||||
|
|
|
|||
|
|
@ -22,7 +22,11 @@ import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|||
import { WebSocketClientTransport } from '@modelcontextprotocol/sdk/client/websocket.js';
|
||||
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
||||
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
||||
import type { MCPServerConfig, ClientCapabilities, Implementation } from '$lib/types/mcp';
|
||||
import type {
|
||||
MCPServerConnectionConfig,
|
||||
ToolCallParams,
|
||||
ToolExecutionResult
|
||||
} from '$lib/types/mcp';
|
||||
import { MCPError } from '$lib/errors';
|
||||
import { DEFAULT_MCP_CONFIG } from '$lib/constants/mcp';
|
||||
|
||||
|
|
@ -42,27 +46,6 @@ interface ToolCallResult {
|
|||
_meta?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface MCPServerConnectionConfig {
|
||||
/** Unique server name/identifier */
|
||||
name: string;
|
||||
/** Server configuration */
|
||||
server: MCPServerConfig;
|
||||
/** Client info to advertise */
|
||||
clientInfo?: Implementation;
|
||||
/** Capabilities to advertise */
|
||||
capabilities?: ClientCapabilities;
|
||||
}
|
||||
|
||||
export interface ToolCallParams {
|
||||
name: string;
|
||||
arguments: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ToolExecutionResult {
|
||||
content: string;
|
||||
isError: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the MCP SDK Client and provides a clean interface for tool operations.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
import { browser } from '$app/environment';
|
||||
import {
|
||||
MCPHostManager,
|
||||
type OpenAIToolDefinition,
|
||||
type ServerStatus
|
||||
} from '$lib/mcp/host-manager';
|
||||
import { MCPHostManager } from '$lib/mcp/host-manager';
|
||||
import { MCPServerConnection } from '$lib/mcp/server-connection';
|
||||
import type { ToolExecutionResult } from '$lib/mcp/server-connection';
|
||||
import type { OpenAIToolDefinition, ServerStatus, ToolExecutionResult } from '$lib/types/mcp';
|
||||
import { buildMcpClientConfig, incrementMcpServerUsage } from '$lib/config/mcp';
|
||||
import { config, settingsStore } from '$lib/stores/settings.svelte';
|
||||
import type { MCPToolCall } from '$lib/types/mcp';
|
||||
|
|
|
|||
|
|
@ -70,3 +70,63 @@ export type MCPServerSettingsEntry = {
|
|||
/** Server icon URL from metadata (fetched during health check). */
|
||||
iconUrl?: string;
|
||||
};
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Host Manager Types
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface MCPHostManagerConfig {
|
||||
/** Server configurations keyed by server name */
|
||||
servers: MCPClientConfig['servers'];
|
||||
/** Client info to advertise to all servers */
|
||||
clientInfo?: Implementation;
|
||||
/** Default capabilities to advertise */
|
||||
capabilities?: ClientCapabilities;
|
||||
}
|
||||
|
||||
export interface OpenAIToolDefinition {
|
||||
type: 'function';
|
||||
function: {
|
||||
name: string;
|
||||
description?: string;
|
||||
parameters: Record<string, unknown>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ServerStatus {
|
||||
name: string;
|
||||
isConnected: boolean;
|
||||
toolCount: number;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Usage Stats
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
export type McpServerUsageStats = Record<string, number>;
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Server Connection Types
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface MCPServerConnectionConfig {
|
||||
/** Unique server name/identifier */
|
||||
name: string;
|
||||
/** Server configuration */
|
||||
server: MCPServerConfig;
|
||||
/** Client info to advertise */
|
||||
clientInfo?: Implementation;
|
||||
/** Capabilities to advertise */
|
||||
capabilities?: ClientCapabilities;
|
||||
}
|
||||
|
||||
export interface ToolCallParams {
|
||||
name: string;
|
||||
arguments: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ToolExecutionResult {
|
||||
content: string;
|
||||
isError: boolean;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Simplified HTML fallback for external images that fail to load.
|
||||
* Displays a centered message with a link to open the image in a new tab.
|
||||
*/
|
||||
export function getImageErrorFallbackHtml(src: string): string {
|
||||
return `<div class="image-error-content">
|
||||
<span>Image cannot be displayed</span>
|
||||
<a href="${src}" target="_blank" rel="noopener noreferrer">(open link)</a>
|
||||
</div>`;
|
||||
}
|
||||
Loading…
Reference in New Issue