${this.#renderVersionBanner()}
${welcomeMessage ? this.#renderMessage(welcomeMessage, 0) : Lit.nothing}
+ ${suggestions}
+
${this.#showOAuthLogin ? html`
+ Try one of these
+
+ ${examples.map(ex => html`
+
+ `)}
+
+
+ `;
+ }
+
+ // On suggestion click, fill input field and focus it
+ #handleExampleClick(text: string, agentType?: string): void {
+ const bar = this.#shadow.querySelector('ai-input-bar') as (HTMLElement & { setInputValue?: (t: string) => void }) | null;
+ if (bar && typeof (bar as any).setInputValue === 'function') {
+ (bar as any).setInputValue(text);
+ } else {
+ // Fallback: try to set directly on ai-chat-input if present
+ const input = bar?.querySelector('ai-chat-input') as (HTMLElement & { value?: string, focusInput?: () => void }) | null;
+ if (input) {
+ (input as any).value = text;
+ if (typeof (input as any).focusInput === 'function') {
+ (input as any).focusInput();
+ }
+ // Bubble change up so parent state updates
+ bar?.dispatchEvent(new CustomEvent('inputchange', { bubbles: true, detail: { value: text }}));
+ }
+ }
+
+ // Auto-select agent type if provided
+ if (agentType) {
+ this.#autoSelectAgent(agentType);
+ }
+ }
+
+ // Programmatically select an agent type in the UI and notify parent
+ #autoSelectAgent(agentType: string | null): void {
+ this.#selectedPromptType = agentType;
+ if (this.#onPromptSelected) {
+ this.#onPromptSelected(agentType);
+ }
+ // Re-render to update agent button selection immediately
+ void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#boundRender);
+ }
+
+ // Get current inspected page URL (if available)
+ #getCurrentPageURL(): string | null {
+ try {
+ const target = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
+ if (!target) {
+ return null;
+ }
+ const resourceTree = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
+ const url = resourceTree?.mainFrame?.url;
+ return url || null;
+ } catch {
+ return null;
+ }
+ }
+
+ // Build example suggestions (generic + page-specific if URL is present)
+ #getExampleSuggestions(): Array<{ text: string; agentType?: string }> {
+ const generic: Array<{ text: string; agentType?: string }> = [
+ { text: 'Summarize this page' },
+ { text: 'Extract all links and titles from this page' },
+ ];
+
+ const url = this.#getCurrentPageURL();
+ if (!url) {
+ // Show a smaller set to avoid overcrowding
+ return generic.slice(0, 4);
+ }
+
+ let hostname = '';
+ try { hostname = new URL(url).hostname; } catch {}
+
+ // Detect all Chrome internal pages
+ const isChromeInternalPage = url.startsWith('chrome://');
+
+ if (isChromeInternalPage) {
+ // Provide mixed examples for all Chrome internal pages
+ const researchAgent = BaseOrchestratorAgent.BaseOrchestratorAgentType.DEEP_RESEARCH;
+ const searchAgent = BaseOrchestratorAgent.BaseOrchestratorAgentType.SEARCH;
+ const searchExamples: Array<{ text: string; agentType?: string }> = [
+ { text: 'Deep research latest breakthroughs in AI agents', agentType: researchAgent },
+ { text: 'Find content writers in Seattle, WA', agentType: searchAgent },
+ { text: 'Provide me analysis of Apple stocks?', agentType: researchAgent },
+ { text: 'Summarize today\'s news', agentType: researchAgent },
+ ];
+ return searchExamples;
+ }
+
+ // Detect common search engines
+ const isSearchSite = /(^|\.)((google|bing|duckduckgo|yahoo|yandex|baidu)\.(com|co\.[a-z]+|[a-z]+))$/i.test(hostname);
+
+ if (isSearchSite) {
+ // Provide deep-research oriented examples and pre-select the deep research agent on click
+ const researchAgent = BaseOrchestratorAgent.BaseOrchestratorAgentType.DEEP_RESEARCH;
+ const searchExamples: Array<{ text: string; agentType?: string }> = [
+ { text: 'Deep research latest breakthroughs in AI agents', agentType: researchAgent },
+ { text: 'What are the reviews of iPhone 17?', agentType: researchAgent },
+ { text: 'Provide me analysis of Apple stocks?', agentType: researchAgent },
+ { text: 'Summarize today\'s news', agentType: researchAgent },
+ ];
+ return searchExamples;
+ }
+
+ const specific: Array<{ text: string; agentType?: string }> = [
+ { text: `What do you think about ${hostname ? hostname + ' ' : ''}page?` },
+ ];
+
+ // Merge, de-duplicate by text, cap to concise set
+ const map = new Map
();
+ [...specific, ...generic].forEach(item => { if (!map.has(item.text)) map.set(item.text, item); });
+ return Array.from(map.values()).slice(0, 6);
+ }
+
// Helper method to format JSON with syntax highlighting
#formatJsonWithSyntaxHighlighting(jsonString: string): Lit.TemplateResult {
try {
@@ -782,7 +985,7 @@ export class ChatView extends HTMLElement {
ModelOption[],
removeCustomModelOption: (modelName: string) => ModelOption[],
): Promise {
- logger.debug('SettingsDialog.show - Initial parameters:');
- logger.debug('selectedModel:', selectedModel);
- logger.debug('miniModel:', miniModel);
- logger.debug('nanoModel:', nanoModel);
- logger.debug('Current provider:', localStorage.getItem(PROVIDER_SELECTION_KEY) || 'openai');
// Get all model options using the provided getModelOptions function
const modelOptions = getModelOptions();
- logger.debug('Model options from getModelOptions:', modelOptions);
// Count models by provider
const openaiModels = modelOptions.filter(m => m.type === 'openai');
const litellmModels = modelOptions.filter(m => m.type === 'litellm');
- logger.debug(`Model counts - OpenAI: ${openaiModels.length}, LiteLLM: ${litellmModels.length}`);
// Reset selector references
SettingsDialog.#openaiMiniModelSelect = null;
@@ -596,7 +638,6 @@ export class SettingsDialog {
groqContent.style.display = selectedProvider === 'groq' ? 'block' : 'none';
openrouterContent.style.display = selectedProvider === 'openrouter' ? 'block' : 'none';
- logger.debug(`Provider changed to: ${selectedProvider}`);
// If switching to LiteLLM, fetch the latest models if endpoint is configured
if (selectedProvider === 'litellm') {
@@ -658,8 +699,6 @@ export class SettingsDialog {
// Get model options filtered by the selected provider
const availableModels = getModelOptions(selectedProvider as 'openai' | 'litellm' | 'groq' | 'openrouter');
- logger.debug(`Available models for ${selectedProvider}:`, availableModels);
- logger.debug(`Current miniModel: ${miniModel}, nanoModel: ${nanoModel}`);
// Refresh model selectors based on new provider
@@ -708,11 +747,9 @@ export class SettingsDialog {
// Function to update OpenAI model selectors
function updateOpenAIModelSelectors() {
- logger.debug('Updating OpenAI model selectors');
// Get the latest model options filtered for OpenAI provider
const openaiModels = getModelOptions('openai');
- logger.debug('OpenAI models from getModelOptions:', openaiModels);
// Get valid models using generic helper
const validMiniModel = getValidModelForProvider(miniModel, openaiModels, 'openai', 'mini');
@@ -732,7 +769,6 @@ export class SettingsDialog {
openaiModelSectionTitle.textContent = 'Model Size Selection';
openaiModelSection.appendChild(openaiModelSectionTitle);
- logger.debug(`Current miniModel: ${miniModel}, nanoModel: ${nanoModel}`);
// No focus handler needed for OpenAI selectors as we don't need to fetch models on focus
@@ -748,7 +784,6 @@ export class SettingsDialog {
undefined // No focus handler for OpenAI
);
- logger.debug('Created OpenAI Mini Model Select:', SettingsDialog.#openaiMiniModelSelect);
// Create OpenAI Nano Model selection and store reference
SettingsDialog.#openaiNanoModelSelect = createModelSelector(
@@ -762,7 +797,6 @@ export class SettingsDialog {
undefined // No focus handler for OpenAI
);
- logger.debug('Created OpenAI Nano Model Select:', SettingsDialog.#openaiNanoModelSelect);
}
// Initialize OpenAI model selectors
@@ -980,7 +1014,6 @@ export class SettingsDialog {
litellmModelSectionTitle.textContent = 'Model Size Selection';
litellmModelSection.appendChild(litellmModelSectionTitle);
- logger.debug(`Current miniModel: ${miniModel}, nanoModel: ${nanoModel}`);
// Create a focus handler for LiteLLM selectors
const onLiteLLMSelectorFocus = async () => {
@@ -1272,1682 +1305,1777 @@ export class SettingsDialog {
addModelButton.disabled = false;
});
-
- // Add Advanced Settings Toggle
- const ADVANCED_SETTINGS_ENABLED_KEY = 'ai_chat_advanced_settings_enabled';
-
- const advancedToggleSection = document.createElement('div');
- advancedToggleSection.className = 'advanced-settings-toggle-section';
- contentDiv.appendChild(advancedToggleSection);
-
- const advancedToggleContainer = document.createElement('div');
- advancedToggleContainer.className = 'advanced-settings-toggle-container';
- advancedToggleSection.appendChild(advancedToggleContainer);
-
- const advancedToggleCheckbox = document.createElement('input');
- advancedToggleCheckbox.type = 'checkbox';
- advancedToggleCheckbox.id = 'advanced-settings-toggle';
- advancedToggleCheckbox.className = 'advanced-settings-checkbox';
- advancedToggleCheckbox.checked = localStorage.getItem(ADVANCED_SETTINGS_ENABLED_KEY) === 'true';
- advancedToggleContainer.appendChild(advancedToggleCheckbox);
-
- const advancedToggleLabel = document.createElement('label');
- advancedToggleLabel.htmlFor = 'advanced-settings-toggle';
- advancedToggleLabel.className = 'advanced-settings-label';
- advancedToggleLabel.textContent = '⚙️ Advanced Settings';
- advancedToggleContainer.appendChild(advancedToggleLabel);
-
- const advancedToggleHint = document.createElement('div');
- advancedToggleHint.className = 'settings-hint';
- advancedToggleHint.textContent = 'Show advanced configuration options (Browsing History, Vector DB, Tracing, Evaluation)';
- advancedToggleSection.appendChild(advancedToggleHint);
-
- // Add browsing history section
- const historySection = document.createElement('div');
- historySection.className = 'settings-section history-section';
- contentDiv.appendChild(historySection);
-
- const historyTitle = document.createElement('h3');
- historyTitle.className = 'settings-subtitle';
- historyTitle.textContent = i18nString(UIStrings.browsingHistoryTitle);
- historySection.appendChild(historyTitle);
-
- const historyDescription = document.createElement('p');
- historyDescription.className = 'settings-description';
- historyDescription.textContent = i18nString(UIStrings.browsingHistoryDescription);
- historySection.appendChild(historyDescription);
-
- // Status message element (initially hidden)
- const statusMessage = document.createElement('div');
- statusMessage.className = 'settings-status history-status';
- statusMessage.style.display = 'none';
- statusMessage.textContent = i18nString(UIStrings.historyCleared);
- historySection.appendChild(statusMessage);
-
- // Clear history button
- const clearHistoryButton = document.createElement('button');
- clearHistoryButton.textContent = i18nString(UIStrings.clearHistoryButton);
- clearHistoryButton.className = 'settings-button clear-button';
- clearHistoryButton.setAttribute('type', 'button');
- historySection.appendChild(clearHistoryButton);
-
- clearHistoryButton.addEventListener('click', async () => {
- try {
- // Import the VisitHistoryManager from its dedicated file
- const { VisitHistoryManager } = await import('../tools/VisitHistoryManager.js');
- await VisitHistoryManager.getInstance().clearHistory();
-
- // Show success message
- statusMessage.style.display = 'block';
-
- // Hide message after 3 seconds
- setTimeout(() => {
- statusMessage.style.display = 'none';
- }, 3000);
- } catch (error) {
- logger.error('Error clearing browsing history:', error);
- }
- });
-
- // Initialize LiteLLM model selectors
- updateLiteLLMModelSelectors();
-
- // Setup Groq content
- const groqSettingsSection = document.createElement('div');
- groqSettingsSection.className = 'settings-section';
- groqContent.appendChild(groqSettingsSection);
-
- // Groq API Key
- const groqApiKeyLabel = document.createElement('div');
- groqApiKeyLabel.className = 'settings-label';
- groqApiKeyLabel.textContent = i18nString(UIStrings.groqApiKeyLabel);
- groqSettingsSection.appendChild(groqApiKeyLabel);
-
- const groqApiKeyHint = document.createElement('div');
- groqApiKeyHint.className = 'settings-hint';
- groqApiKeyHint.textContent = i18nString(UIStrings.groqApiKeyHint);
- groqSettingsSection.appendChild(groqApiKeyHint);
-
- const settingsSavedGroqApiKey = localStorage.getItem(GROQ_API_KEY_STORAGE_KEY) || '';
- const groqApiKeyInput = document.createElement('input');
- groqApiKeyInput.className = 'settings-input groq-api-key-input';
- groqApiKeyInput.type = 'password';
- groqApiKeyInput.placeholder = 'Enter your Groq API key';
- groqApiKeyInput.value = settingsSavedGroqApiKey;
- groqSettingsSection.appendChild(groqApiKeyInput);
-
- // Fetch Groq models button
- const groqFetchButtonContainer = document.createElement('div');
- groqFetchButtonContainer.className = 'fetch-button-container';
- groqSettingsSection.appendChild(groqFetchButtonContainer);
-
- const fetchGroqModelsButton = document.createElement('button');
- fetchGroqModelsButton.className = 'settings-button';
- fetchGroqModelsButton.setAttribute('type', 'button');
- fetchGroqModelsButton.textContent = i18nString(UIStrings.fetchGroqModelsButton);
- fetchGroqModelsButton.disabled = !groqApiKeyInput.value.trim();
- groqFetchButtonContainer.appendChild(fetchGroqModelsButton);
-
- const fetchGroqModelsStatus = document.createElement('div');
- fetchGroqModelsStatus.className = 'settings-status';
- fetchGroqModelsStatus.style.display = 'none';
- groqFetchButtonContainer.appendChild(fetchGroqModelsStatus);
-
- // Update button state when API key changes
- groqApiKeyInput.addEventListener('input', () => {
- fetchGroqModelsButton.disabled = !groqApiKeyInput.value.trim();
- });
-
- // Generic helper function to get valid model for provider
- function getValidModelForProvider(
- currentModel: string,
- providerModels: ModelOption[],
- provider: 'openai' | 'litellm' | 'groq' | 'openrouter',
- modelType: 'mini' | 'nano'
- ): string {
- // Check if current model is valid for this provider
- if (providerModels.some(model => model.value === currentModel)) {
- return currentModel;
- }
-
- // Get defaults from AIChatPanel's DEFAULT_PROVIDER_MODELS
- const defaults = DEFAULT_PROVIDER_MODELS[provider] || DEFAULT_PROVIDER_MODELS.openai;
- const defaultModel = modelType === 'mini' ? defaults.mini : defaults.nano;
-
- // Return default if it exists in provider models
- if (defaultModel && providerModels.some(model => model.value === defaultModel)) {
- return defaultModel;
- }
- // If no valid model found, return empty string to indicate no selection
- // The UI should handle this by showing a placeholder or the first available option
- return '';
- }
-
- // Function to update Groq model selectors
- function updateGroqModelSelectors() {
- logger.debug('Updating Groq model selectors');
-
- // Get the latest model options filtered for Groq provider
- const groqModels = getModelOptions('groq');
- logger.debug('Groq models from getModelOptions:', groqModels);
+ // ---- MCP Integration Section ----
+ const mcpSection = document.createElement('div');
+ mcpSection.className = 'settings-section mcp-section';
+ // Make MCP UI visible so users can configure OAuth/bearer and connect
+ mcpSection.style.display = 'block';
+ contentDiv.appendChild(mcpSection);
- // Get valid models using generic helper
- const validMiniModel = getValidModelForProvider(miniModel, groqModels, 'groq', 'mini');
- const validNanoModel = getValidModelForProvider(nanoModel, groqModels, 'groq', 'nano');
-
- logger.debug('Groq model selection:', { originalMini: miniModel, validMini: validMiniModel, originalNano: nanoModel, validNano: validNanoModel });
+ const mcpSectionTitle = document.createElement('h3');
+ mcpSectionTitle.className = 'settings-subtitle';
+ mcpSectionTitle.textContent = i18nString(UIStrings.mcpSection);
+ mcpSection.appendChild(mcpSectionTitle);
- // Clear any existing model selectors
- const existingSelectors = groqContent.querySelectorAll('.model-selection-section');
- existingSelectors.forEach(selector => selector.remove());
-
- // Create a new model selection section
- const groqModelSection = document.createElement('div');
- groqModelSection.className = 'settings-section model-selection-section';
- groqContent.appendChild(groqModelSection);
-
- const groqModelSectionTitle = document.createElement('h3');
- groqModelSectionTitle.className = 'settings-subtitle';
- groqModelSectionTitle.textContent = 'Model Size Selection';
- groqModelSection.appendChild(groqModelSectionTitle);
-
- logger.debug(`Current miniModel: ${miniModel}, nanoModel: ${nanoModel}`);
-
- // Create Groq Mini Model selection and store reference
- SettingsDialog.#groqMiniModelSelect = createModelSelector(
- groqModelSection,
- i18nString(UIStrings.miniModelLabel),
- i18nString(UIStrings.miniModelDescription),
- 'groq-mini-model-select',
- groqModels,
- validMiniModel,
- i18nString(UIStrings.defaultMiniOption),
- undefined // No focus handler needed for Groq
- );
-
- logger.debug('Created Groq Mini Model Select:', SettingsDialog.#groqMiniModelSelect);
-
- // Create Groq Nano Model selection and store reference
- SettingsDialog.#groqNanoModelSelect = createModelSelector(
- groqModelSection,
- i18nString(UIStrings.nanoModelLabel),
- i18nString(UIStrings.nanoModelDescription),
- 'groq-nano-model-select',
- groqModels,
- validNanoModel,
- i18nString(UIStrings.defaultNanoOption),
- undefined // No focus handler needed for Groq
- );
-
- logger.debug('Created Groq Nano Model Select:', SettingsDialog.#groqNanoModelSelect);
- }
-
- // Add click handler for fetch Groq models button
- fetchGroqModelsButton.addEventListener('click', async () => {
- fetchGroqModelsButton.disabled = true;
- fetchGroqModelsStatus.textContent = i18nString(UIStrings.fetchingModels);
- fetchGroqModelsStatus.style.display = 'block';
- fetchGroqModelsStatus.style.backgroundColor = 'var(--color-accent-blue-background)';
- fetchGroqModelsStatus.style.color = 'var(--color-accent-blue)';
+ // Current MCP config
+ const currentMCPConfig = getMCPConfig();
- try {
- const groqApiKey = groqApiKeyInput.value.trim();
-
- // Fetch Groq models using LLMClient static method
- const groqModels = await LLMClient.fetchGroqModels(groqApiKey);
-
- // Convert Groq models to ModelOption format
- const modelOptions: ModelOption[] = groqModels.map(model => ({
- value: model.id,
- label: model.id,
- type: 'groq' as const
- }));
-
- // Update model options with fetched Groq models
- updateModelOptions(modelOptions, false);
-
- // Get all Groq models including any custom ones
- const allGroqModels = getModelOptions('groq');
- const actualModelCount = groqModels.length;
-
- // Refresh existing model selectors with new options if they exist
- if (SettingsDialog.#groqMiniModelSelect) {
- refreshModelSelectOptions(SettingsDialog.#groqMiniModelSelect, allGroqModels, miniModel, i18nString(UIStrings.defaultMiniOption));
- }
- if (SettingsDialog.#groqNanoModelSelect) {
- refreshModelSelectOptions(SettingsDialog.#groqNanoModelSelect, allGroqModels, nanoModel, i18nString(UIStrings.defaultNanoOption));
- }
+ // Status indicator
+ const mcpStatusContainer = document.createElement('div');
+ mcpStatusContainer.className = 'connection-status-container';
+ mcpStatusContainer.style.display = 'flex';
+ mcpStatusContainer.style.alignItems = 'center';
+ mcpStatusContainer.style.gap = '8px';
+ mcpStatusContainer.style.marginTop = '8px';
+ mcpStatusContainer.style.fontSize = '13px';
+ mcpSection.appendChild(mcpStatusContainer);
- fetchGroqModelsStatus.textContent = i18nString(UIStrings.fetchedModels, {PH1: actualModelCount});
- fetchGroqModelsStatus.style.backgroundColor = 'var(--color-accent-green-background)';
- fetchGroqModelsStatus.style.color = 'var(--color-accent-green)';
-
- // Update Groq model selections
- updateGroqModelSelectors();
-
- } catch (error) {
- logger.error('Failed to fetch Groq models:', error);
- fetchGroqModelsStatus.textContent = `Error: ${error instanceof Error ? error.message : 'Unknown error'}`;
- fetchGroqModelsStatus.style.backgroundColor = 'var(--color-accent-red-background)';
- fetchGroqModelsStatus.style.color = 'var(--color-accent-red)';
- } finally {
- fetchGroqModelsButton.disabled = !groqApiKeyInput.value.trim();
- setTimeout(() => {
- fetchGroqModelsStatus.style.display = 'none';
- }, 3000);
- }
- });
-
- // Initialize Groq model selectors
- updateGroqModelSelectors();
-
- // Setup OpenRouter content
- const openrouterSettingsSection = document.createElement('div');
- openrouterSettingsSection.className = 'settings-section';
- openrouterContent.appendChild(openrouterSettingsSection);
-
- // OpenRouter API Key
- const openrouterApiKeyLabel = document.createElement('div');
- openrouterApiKeyLabel.className = 'settings-label';
- openrouterApiKeyLabel.textContent = i18nString(UIStrings.openrouterApiKeyLabel);
- openrouterSettingsSection.appendChild(openrouterApiKeyLabel);
-
- const openrouterApiKeyHint = document.createElement('div');
- openrouterApiKeyHint.className = 'settings-hint';
- openrouterApiKeyHint.textContent = i18nString(UIStrings.openrouterApiKeyHint);
- openrouterSettingsSection.appendChild(openrouterApiKeyHint);
-
- const settingsSavedOpenRouterApiKey = localStorage.getItem(OPENROUTER_API_KEY_STORAGE_KEY) || '';
- const openrouterApiKeyInput = document.createElement('input');
- openrouterApiKeyInput.className = 'settings-input openrouter-api-key-input';
- openrouterApiKeyInput.type = 'password';
- openrouterApiKeyInput.placeholder = 'Enter your OpenRouter API key';
- openrouterApiKeyInput.value = settingsSavedOpenRouterApiKey;
- openrouterSettingsSection.appendChild(openrouterApiKeyInput);
-
- // OAuth section - alternative to API key
- const oauthDivider = document.createElement('div');
- oauthDivider.className = 'settings-divider';
- oauthDivider.textContent = 'OR';
- openrouterSettingsSection.appendChild(oauthDivider);
-
- const oauthButtonContainer = document.createElement('div');
- oauthButtonContainer.className = 'oauth-button-container';
- openrouterSettingsSection.appendChild(oauthButtonContainer);
-
- const oauthButton = document.createElement('button');
- oauthButton.className = 'settings-button oauth-button';
- oauthButton.setAttribute('type', 'button');
- oauthButton.textContent = 'Connect with OpenRouter';
- oauthButtonContainer.appendChild(oauthButton);
-
- const oauthStatus = document.createElement('div');
- oauthStatus.className = 'oauth-status';
- oauthStatus.style.display = 'none';
- oauthButtonContainer.appendChild(oauthStatus);
-
- // Add OAuth-specific styles
- const oauthStyles = document.createElement('style');
- oauthStyles.textContent = `
- .settings-divider {
- text-align: center;
- margin: 15px 0;
- color: var(--color-text-secondary);
- font-size: 12px;
- font-weight: bold;
- }
- .oauth-button-container {
- margin-bottom: 10px;
- }
- .oauth-button {
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: white;
- border: none;
- padding: 10px 20px;
- border-radius: 6px;
- cursor: pointer;
- font-weight: 500;
- transition: all 0.3s ease;
- width: 100%;
- margin-bottom: 8px;
- }
- .oauth-button:hover {
- transform: translateY(-1px);
- box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
- }
- .oauth-button:disabled {
- opacity: 0.6;
- cursor: not-allowed;
- transform: none;
- box-shadow: none;
- }
- .oauth-button.disconnect {
- background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
- }
- .oauth-status {
- font-size: 12px;
- margin-top: 5px;
- padding: 5px 8px;
- border-radius: 4px;
- background: var(--color-background-highlight);
- }
- `;
- document.head.appendChild(oauthStyles);
-
- // Import OAuth service dynamically when needed
- let OpenRouterOAuth: any = null;
- const getOpenRouterOAuth = async () => {
- if (!OpenRouterOAuth) {
- const module = await import('../auth/OpenRouterOAuth.js');
- OpenRouterOAuth = module.OpenRouterOAuth;
- }
- return OpenRouterOAuth;
+ const mcpStatusDot = document.createElement('div');
+ mcpStatusDot.className = 'connection-status-dot';
+ mcpStatusDot.style.width = '8px';
+ mcpStatusDot.style.height = '8px';
+ mcpStatusDot.style.borderRadius = '50%';
+ mcpStatusDot.style.flexShrink = '0';
+ mcpStatusContainer.appendChild(mcpStatusDot);
+
+ const mcpStatusText = document.createElement('span');
+ mcpStatusText.className = 'connection-status-text';
+ mcpStatusContainer.appendChild(mcpStatusText);
+
+ const mcpStatusDetails = document.createElement('div');
+ mcpStatusDetails.className = 'settings-hint';
+ mcpStatusDetails.style.marginTop = '12px';
+ mcpStatusDetails.style.display = 'flex';
+ mcpStatusDetails.style.flexDirection = 'column';
+ mcpStatusDetails.style.gap = '8px';
+ mcpSection.appendChild(mcpStatusDetails);
+
+ const formatTimestamp = (date: Date | undefined): string => {
+ if (!date) return '';
+ return date.toLocaleString();
};
-
- // Update OAuth button state
- const updateOAuthButton = async () => {
- const OAuth = await getOpenRouterOAuth();
- if (await OAuth.isOAuthAuthenticated()) {
- oauthButton.textContent = 'Disconnect OpenRouter';
- oauthButton.classList.add('disconnect');
- oauthStatus.textContent = '✓ Connected via OpenRouter account';
- oauthStatus.style.color = 'var(--color-accent-green)';
- oauthStatus.style.display = 'block';
- } else {
- oauthButton.textContent = 'Connect with OpenRouter';
- oauthButton.classList.remove('disconnect');
- oauthStatus.style.display = 'none';
+
+ const formatMCPError = (error: string, errorType?: string): {message: string, hint?: string} => {
+ if (!errorType) return {message: error};
+ switch (errorType) {
+ case 'connection':
+ return {message: `Connection failed: ${error}`, hint: 'Check if the MCP server is running and the endpoint URL is correct.'};
+ case 'authentication':
+ return {message: `Authentication failed: ${error}`, hint: 'Verify your auth token is correct and has not expired.'};
+ case 'configuration':
+ return {message: `Configuration error: ${error}`, hint: 'Check your endpoint URL format (should be ws:// or wss://).'};
+ case 'network':
+ return {message: `Network error: ${error}`, hint: 'Check your internet connection and firewall settings.'};
+ case 'server_error':
+ return {message: `Server error: ${error}`, hint: 'The MCP server encountered an internal error. Contact the server administrator.'};
+ default:
+ return {message: error};
}
};
-
- oauthButtonContainer.appendChild(oauthButton);
- updateOAuthButton();
-
- // OAuth button click handler
- oauthButton.addEventListener('click', async () => {
- const OAuth = await getOpenRouterOAuth();
- oauthButton.disabled = true;
-
- try {
- if (await OAuth.isOAuthAuthenticated()) {
- // Disconnect
- if (confirm('Are you sure you want to disconnect your OpenRouter account?')) {
- await OAuth.revokeToken();
- updateOAuthButton();
+
+ const updateMCPStatus = () => {
+ const status = MCPRegistry.getStatus();
+
+
+ const appendServerRow = (server: typeof status.servers[number], isConnected: boolean) => {
+ // Get auth errors once for this server
+ const authErrors = getStoredAuthErrors();
+ const serverAuthError = authErrors.find(error => error.serverId === server.id);
+
+ const row = document.createElement('div');
+ row.style.display = 'flex';
+ row.style.alignItems = 'flex-start';
+ row.style.gap = '8px';
+ row.style.marginBottom = '6px';
+ row.style.padding = '8px';
+ row.style.borderRadius = '6px';
+ row.style.backgroundColor = 'var(--color-background-elevation-1)';
+ row.style.border = '1px solid var(--color-details-hairline)';
+
+ // Status indicator dot (smaller)
+ const statusDot = document.createElement('span');
+ statusDot.style.width = '6px';
+ statusDot.style.height = '6px';
+ statusDot.style.borderRadius = '50%';
+ statusDot.style.marginTop = '8px';
+ statusDot.style.flexShrink = '0';
+
+ // Server info container
+ const serverInfo = document.createElement('div');
+ serverInfo.style.flex = '1';
+ serverInfo.style.minWidth = '0';
+
+ // Server name line
+ const serverNameLine = document.createElement('div');
+ serverNameLine.style.display = 'flex';
+ serverNameLine.style.alignItems = 'center';
+ serverNameLine.style.gap = '8px';
+ serverNameLine.style.marginBottom = '4px';
+ serverNameLine.style.flexWrap = 'wrap';
+
+ const serverName = document.createElement('span');
+ serverName.style.fontWeight = '600';
+ serverName.style.color = 'var(--color-text-primary)';
+ serverName.style.fontSize = '13px';
+ serverName.textContent = server.name || server.id;
+
+ const statusBadge = document.createElement('span');
+ statusBadge.style.fontSize = '10px';
+ statusBadge.style.padding = '2px 6px';
+ statusBadge.style.borderRadius = '12px';
+ statusBadge.style.fontWeight = '500';
+ statusBadge.style.textTransform = 'uppercase';
+ statusBadge.style.letterSpacing = '0.5px';
+
+ // Determine status and styling with modern badge design
+ if (isConnected) {
+ if (server.toolCount === 0) {
+ // Connected but discovering tools
+ statusDot.style.backgroundColor = '#f59e0b';
+ statusBadge.style.backgroundColor = '#fef3c7';
+ statusBadge.style.color = '#92400e';
+ statusBadge.textContent = 'Discovering';
+ } else {
+ // Connected with tools
+ statusDot.style.backgroundColor = '#10b981';
+ statusBadge.style.backgroundColor = '#d1fae5';
+ statusBadge.style.color = '#065f46';
+ statusBadge.textContent = 'Connected';
}
} else {
- // Connect - provide clear feedback for tab-based flow
- oauthButton.textContent = 'Redirecting to OpenRouter...';
- oauthStatus.textContent = 'You will be redirected to OpenRouter to authorize access. The page will return here automatically after authorization.';
- oauthStatus.style.color = 'var(--color-text-secondary)';
- oauthStatus.style.display = 'block';
-
- await OAuth.startAuthFlow();
- updateOAuthButton();
+ if (serverAuthError) {
+ statusDot.style.backgroundColor = '#ef4444';
+ statusBadge.style.backgroundColor = '#fee2e2';
+ statusBadge.style.color = '#991b1b';
+ statusBadge.textContent = 'Auth Required';
+ } else {
+ statusDot.style.backgroundColor = '#9ca3af';
+ statusBadge.style.backgroundColor = '#f3f4f6';
+ statusBadge.style.color = '#6b7280';
+ statusBadge.textContent = 'Disconnected';
+ }
}
- } catch (error) {
- console.error('OAuth flow error:', error);
- oauthStatus.textContent = `Error: ${error instanceof Error ? error.message : 'Unknown error'}`;
- oauthStatus.style.color = 'var(--color-accent-red)';
- oauthStatus.style.display = 'block';
- } finally {
- oauthButton.disabled = false;
- if (!await OAuth.isOAuthAuthenticated()) {
- oauthButton.textContent = 'Connect with OpenRouter';
- oauthStatus.style.display = 'none';
+
+ serverNameLine.appendChild(serverName);
+ serverNameLine.appendChild(statusBadge);
+
+ // Details line
+ const detailsLine = document.createElement('div');
+ detailsLine.style.fontSize = '11px';
+ detailsLine.style.color = 'var(--color-text-secondary)';
+
+ const toolCountText = server.toolCount === 0 && isConnected ?
+ 'Tools loading...' :
+ `${server.toolCount} tools`;
+
+ detailsLine.textContent = `${toolCountText} • ${server.authType === 'oauth' ? 'OAuth' : 'Bearer'}`;
+
+ serverInfo.appendChild(serverNameLine);
+ serverInfo.appendChild(detailsLine);
+
+ row.appendChild(statusDot);
+ row.appendChild(serverInfo);
+
+ const needsReconnect = server.authType === 'oauth' && !isConnected;
+ if (needsReconnect) {
+ const reconnectButton = document.createElement('button');
+ reconnectButton.className = 'settings-button';
+ reconnectButton.style.padding = '2px 8px';
+ reconnectButton.style.fontSize = '12px';
+ reconnectButton.textContent = i18nString(UIStrings.mcpReconnectButton);
+ reconnectButton.addEventListener('click', async () => {
+ reconnectButton.disabled = true;
+ reconnectButton.textContent = i18nString(UIStrings.mcpReconnectInProgress);
+ try {
+ await MCPRegistry.reconnect(server.id);
+ // Clear stored authentication error on successful reconnection
+ clearStoredAuthError(server.id);
+ } catch (err) {
+ logger.error('Failed to reconnect MCP server', { serverId: server.id, error: err });
+ reconnectButton.disabled = false;
+ reconnectButton.textContent = i18nString(UIStrings.mcpReconnectRetry);
+ return;
+ } finally {
+ updateMCPStatus();
+ updateActionButtons();
+ }
+ });
+ row.appendChild(reconnectButton);
}
+
+ mcpStatusDetails.appendChild(row);
+
+ // Add authentication error details if present
+ if (serverAuthError) {
+ const errorDetails = document.createElement('div');
+ errorDetails.className = 'settings-hint';
+ errorDetails.style.color = 'var(--color-error)';
+ errorDetails.style.fontSize = '12px';
+ errorDetails.style.marginTop = '2px';
+ errorDetails.style.marginLeft = '16px';
+ errorDetails.style.marginBottom = '4px';
+
+ const timestamp = new Date(serverAuthError.timestamp).toLocaleString();
+ errorDetails.textContent = `Last error (${timestamp}): ${serverAuthError.message}`;
+
+ mcpStatusDetails.appendChild(errorDetails);
+ }
+ };
+
+ if (!status.enabled) {
+ mcpStatusDot.style.backgroundColor = 'var(--color-text-disabled)';
+ mcpStatusText.innerHTML = `⚫ Disabled`;
+ mcpStatusDetails.textContent = '';
+ return;
}
- });
-
- // Handle OAuth events
- const handleOAuthSuccess = () => {
- updateOAuthButton();
- oauthStatus.textContent = '✓ Successfully connected to OpenRouter';
- oauthStatus.style.color = 'var(--color-accent-green)';
- oauthStatus.style.display = 'block';
-
- // Trigger chat panel refresh to recognize new credentials
- const chatPanel = document.querySelector('ai-chat-panel') as any;
- if (chatPanel && typeof chatPanel.refreshCredentials === 'function') {
- chatPanel.refreshCredentials();
- }
-
- // Auto-save settings and close dialog after successful OAuth
- onSettingsSaved(); // Notify parent that settings changed
- setTimeout(() => {
- dialog.hide(); // Close dialog after showing success message
- }, 2000); // 2 seconds to show success message
- };
-
- const handleOAuthError = (event: Event) => {
- const customEvent = event as CustomEvent;
- oauthStatus.textContent = `Error: ${customEvent.detail.error}`;
- oauthStatus.style.color = 'var(--color-accent-red)';
- oauthStatus.style.display = 'block';
- };
-
- const handleOAuthLogout = () => {
- // Clear the API key input field
- openrouterApiKeyInput.value = '';
-
- // Update OAuth button state
- updateOAuthButton();
-
- // Show logout confirmation
- oauthStatus.textContent = '✓ Disconnected from OpenRouter';
- oauthStatus.style.color = 'var(--color-text-secondary)';
- oauthStatus.style.display = 'block';
-
- // Refresh chat panel to recognize credential removal
- const chatPanel = document.querySelector('ai-chat-panel') as any;
- if (chatPanel && typeof chatPanel.refreshCredentials === 'function') {
- chatPanel.refreshCredentials();
+ const anyConnected = status.servers.some(s => s.connected);
+ const toolCount = status.registeredToolNames.length;
+ const authErrors = getStoredAuthErrors();
+ const hasAuthErrors = authErrors.length > 0;
+
+ if (anyConnected) {
+ if (hasAuthErrors) {
+ mcpStatusDot.style.backgroundColor = 'var(--color-warning)';
+ mcpStatusText.innerHTML = `🟡 Connected with issues (${toolCount} tools)`;
+ } else {
+ mcpStatusDot.style.backgroundColor = 'var(--color-accent-green)';
+ mcpStatusText.innerHTML = `🟢 Connected (${toolCount} tools)`;
+ }
+
+ // Safely build details content without using innerHTML
+ mcpStatusDetails.textContent = '';
+ if (status.servers.length > 0) {
+ status.servers.forEach(server => appendServerRow(server, server.connected));
+ }
+ if (status.lastConnected) {
+ const line = document.createElement('div');
+ line.style.fontSize = '11px';
+ line.style.color = 'var(--color-text-secondary)';
+ line.style.marginTop = '8px';
+ line.textContent = `Last connected: ${formatTimestamp(status.lastConnected)}`;
+ mcpStatusDetails.appendChild(line);
+ }
+ if (status.lastError) {
+ const {message, hint} = formatMCPError(status.lastError, status.lastErrorType);
+ const errLine = document.createElement('div');
+ const errSpan = document.createElement('span');
+ errSpan.style.color = 'var(--color-error-text)';
+ errSpan.textContent = message;
+ errLine.appendChild(errSpan);
+ mcpStatusDetails.appendChild(errLine);
+ if (hint) {
+ const hintLine = document.createElement('div');
+ hintLine.style.color = 'var(--color-text-secondary)';
+ hintLine.style.fontSize = '12px';
+ hintLine.textContent = hint;
+ mcpStatusDetails.appendChild(hintLine);
+ }
+ }
+ } else {
+ if (hasAuthErrors) {
+ mcpStatusDot.style.backgroundColor = 'var(--color-error)';
+ mcpStatusText.innerHTML = `🔴 Authentication required`;
+ } else {
+ mcpStatusDot.style.backgroundColor = 'var(--color-text-disabled)';
+ mcpStatusText.innerHTML = `⚪ Not connected`;
+ }
+
+ // Safely build details content without using innerHTML
+ mcpStatusDetails.textContent = '';
+ if (status.servers.length > 0) {
+ status.servers.forEach(server => appendServerRow(server, false));
+ }
+ if (status.lastDisconnected) {
+ const line = document.createElement('div');
+ line.style.fontSize = '11px';
+ line.style.color = 'var(--color-text-secondary)';
+ line.style.marginTop = '8px';
+ line.textContent = `Last disconnected: ${formatTimestamp(status.lastDisconnected)}`;
+ mcpStatusDetails.appendChild(line);
+ }
+ if (status.lastError) {
+ const {message, hint} = formatMCPError(status.lastError, status.lastErrorType);
+ const errLine = document.createElement('div');
+ const errSpan = document.createElement('span');
+ errSpan.style.color = 'var(--color-error-text)';
+ errSpan.textContent = message;
+ errLine.appendChild(errSpan);
+ mcpStatusDetails.appendChild(errLine);
+ if (hint) {
+ const hintLine = document.createElement('div');
+ hintLine.style.color = 'var(--color-text-secondary)';
+ hintLine.style.fontSize = '12px';
+ hintLine.textContent = hint;
+ mcpStatusDetails.appendChild(hintLine);
+ }
+ }
}
-
- // Auto-close dialog after showing disconnect message
- setTimeout(() => {
- dialog.hide();
- }, 2000); // 2 seconds to show disconnect message
};
-
- window.addEventListener('openrouter-oauth-success', handleOAuthSuccess);
- window.addEventListener('openrouter-oauth-error', handleOAuthError);
- window.addEventListener('openrouter-oauth-logout', handleOAuthLogout);
-
- // Update API key input behavior for OAuth compatibility
- openrouterApiKeyInput.addEventListener('input', async () => {
- if (openrouterApiKeyInput.value.trim()) {
- // Switch to manual API key method
- localStorage.setItem('openrouter_auth_method', 'api_key');
- const OAuth = await getOpenRouterOAuth();
- if (await OAuth.isOAuthAuthenticated()) {
- OAuth.switchToManualApiKey();
- }
+ updateMCPStatus();
+
+ // Set up periodic MCP status updates every 10 seconds
+ const mcpStatusUpdateInterval = setInterval(updateMCPStatus, 10000);
+
+ // Action buttons row (shown when connected)
+ const mcpActionsContainer = document.createElement('div');
+ mcpActionsContainer.style.marginTop = '12px';
+ mcpActionsContainer.style.marginBottom = '8px';
+ mcpActionsContainer.style.display = 'flex';
+ mcpActionsContainer.style.gap = '8px';
+ mcpActionsContainer.style.flexWrap = 'wrap';
+ mcpSection.appendChild(mcpActionsContainer);
+
+ // Disconnect button
+ const mcpDisconnectButton = document.createElement('button');
+ mcpDisconnectButton.textContent = 'Disconnect';
+ mcpDisconnectButton.className = 'settings-button';
+ mcpDisconnectButton.style.backgroundColor = '#fee2e2';
+ mcpDisconnectButton.style.border = '1px solid #fecaca';
+ mcpDisconnectButton.style.color = '#dc2626';
+ mcpDisconnectButton.style.padding = '6px 12px';
+ mcpDisconnectButton.style.borderRadius = '6px';
+ mcpDisconnectButton.style.cursor = 'pointer';
+ mcpDisconnectButton.style.fontSize = '12px';
+ mcpDisconnectButton.style.fontWeight = '500';
+ mcpDisconnectButton.addEventListener('click', async () => {
+ try {
+ MCPRegistry.dispose();
+ updateMCPStatus();
+ updateActionButtons();
+ } catch (err) {
+ console.error('Failed to disconnect MCP:', err);
}
});
-
- // Fetch OpenRouter models button
- const openrouterFetchButtonContainer = document.createElement('div');
- openrouterFetchButtonContainer.className = 'fetch-button-container';
- openrouterSettingsSection.appendChild(openrouterFetchButtonContainer);
-
- const fetchOpenRouterModelsButton = document.createElement('button');
- fetchOpenRouterModelsButton.className = 'settings-button';
- fetchOpenRouterModelsButton.setAttribute('type', 'button');
- fetchOpenRouterModelsButton.textContent = i18nString(UIStrings.fetchOpenRouterModelsButton);
- fetchOpenRouterModelsButton.disabled = !openrouterApiKeyInput.value.trim();
- openrouterFetchButtonContainer.appendChild(fetchOpenRouterModelsButton);
-
- const fetchOpenRouterModelsStatus = document.createElement('div');
- fetchOpenRouterModelsStatus.className = 'settings-status';
- fetchOpenRouterModelsStatus.style.display = 'none';
- openrouterFetchButtonContainer.appendChild(fetchOpenRouterModelsStatus);
-
- // Update button state when API key changes
- openrouterApiKeyInput.addEventListener('input', () => {
- fetchOpenRouterModelsButton.disabled = !openrouterApiKeyInput.value.trim();
+ mcpActionsContainer.appendChild(mcpDisconnectButton);
+
+ // Manage connections button
+ const mcpManageButton = document.createElement('button');
+ mcpManageButton.textContent = 'Manage connections';
+ mcpManageButton.className = 'settings-button';
+ mcpManageButton.style.backgroundColor = 'var(--color-background-elevation-1)';
+ mcpManageButton.style.border = '1px solid var(--color-details-hairline)';
+ mcpManageButton.style.color = 'var(--color-text-primary)';
+ mcpManageButton.style.padding = '6px 12px';
+ mcpManageButton.style.borderRadius = '6px';
+ mcpManageButton.style.cursor = 'pointer';
+ mcpManageButton.style.fontSize = '12px';
+ mcpManageButton.style.fontWeight = '500';
+ mcpManageButton.addEventListener('click', () => {
+ dialog.hide();
+ MCPConnectionsDialog.show();
});
-
- // Function to check cache age and auto-refresh OpenRouter models if stale
- async function checkAndRefreshOpenRouterCache(): Promise {
+ mcpActionsContainer.appendChild(mcpManageButton);
+
+ // Reconnect all button
+ const mcpReconnectAllButton = document.createElement('button');
+ mcpReconnectAllButton.textContent = 'Reconnect all';
+ mcpReconnectAllButton.className = 'settings-button';
+ mcpReconnectAllButton.style.backgroundColor = '#dbeafe';
+ mcpReconnectAllButton.style.border = '1px solid #bfdbfe';
+ mcpReconnectAllButton.style.color = '#1d4ed8';
+ mcpReconnectAllButton.style.padding = '6px 12px';
+ mcpReconnectAllButton.style.borderRadius = '6px';
+ mcpReconnectAllButton.style.cursor = 'pointer';
+ mcpReconnectAllButton.style.fontSize = '12px';
+ mcpReconnectAllButton.style.fontWeight = '500';
+ mcpReconnectAllButton.addEventListener('click', async () => {
+ mcpReconnectAllButton.disabled = true;
+ mcpReconnectAllButton.textContent = 'Reconnecting...';
try {
- const cacheTimestamp = localStorage.getItem('openrouter_models_cache_timestamp');
- const now = Date.now();
-
- // If no timestamp, cache is considered stale
- if (!cacheTimestamp) {
- logger.debug('OpenRouter models cache has no timestamp, considering stale');
- await autoRefreshOpenRouterModels();
- return;
- }
-
- const cacheAge = now - parseInt(cacheTimestamp, 10);
- const isStale = cacheAge > OPENROUTER_MODELS_CACHE_DURATION_MS;
-
- if (isStale) {
- const ageMinutes = Math.round(cacheAge / (1000 * 60));
- logger.debug(`OpenRouter models cache is stale (${ageMinutes} minutes old), auto-refreshing...`);
- await autoRefreshOpenRouterModels();
- } else {
- const remainingMinutes = Math.round((OPENROUTER_MODELS_CACHE_DURATION_MS - cacheAge) / (1000 * 60));
- logger.debug(`OpenRouter models cache is fresh (expires in ${remainingMinutes} minutes)`);
- }
- } catch (error) {
- logger.warn('Failed to check OpenRouter models cache age:', error);
+ await MCPRegistry.init(true);
+ updateMCPStatus();
+ updateActionButtons();
+ } catch (err) {
+ console.error('Failed to reconnect all MCP servers:', err);
+ } finally {
+ mcpReconnectAllButton.disabled = false;
+ mcpReconnectAllButton.textContent = 'Reconnect all';
}
- }
+ });
+ mcpActionsContainer.appendChild(mcpReconnectAllButton);
- // Function to auto-refresh OpenRouter models silently
- async function autoRefreshOpenRouterModels(): Promise {
+ const updateActionButtons = () => {
+ const status = MCPRegistry.getStatus();
+ const anyConnected = status.enabled && status.servers.some(s => s.connected);
+ mcpActionsContainer.style.display = anyConnected ? 'flex' : 'none';
+ };
+ updateActionButtons();
+
+ // Connections management
+ const mcpConnectionsLabel = document.createElement('div');
+ mcpConnectionsLabel.className = 'settings-label';
+ mcpConnectionsLabel.textContent = i18nString(UIStrings.mcpConnectionsHeader);
+ mcpSection.appendChild(mcpConnectionsLabel);
+
+ const mcpConnectionsHint = document.createElement('div');
+ mcpConnectionsHint.className = 'settings-hint';
+ mcpConnectionsHint.textContent = i18nString(UIStrings.mcpConnectionsHint);
+ mcpSection.appendChild(mcpConnectionsHint);
+
+ const mcpConnectionsActions = document.createElement('div');
+ mcpConnectionsActions.className = 'mcp-connections-actions';
+ mcpConnectionsActions.style.display = 'flex';
+ mcpConnectionsActions.style.gap = '8px';
+ mcpConnectionsActions.style.marginBottom = '12px';
+ mcpSection.appendChild(mcpConnectionsActions);
+
+ const manageConnectionsButton = document.createElement('button');
+ manageConnectionsButton.className = 'settings-button';
+ manageConnectionsButton.textContent = i18nString(UIStrings.mcpManageConnections);
+ manageConnectionsButton.addEventListener('click', () => {
+ MCPConnectionsDialog.show({
+ onSave: async () => {
+ try {
+ await MCPRegistry.init(true);
+ await MCPRegistry.refresh();
+ } catch (err) {
+ logger.error('Failed to refresh MCP connections after save', err);
+ } finally {
+ updateMCPStatus();
+ updateActionButtons();
+ onSettingsSaved();
+ }
+ },
+ });
+ });
+ mcpConnectionsActions.appendChild(manageConnectionsButton);
+
+ const refreshConnectionsButton = document.createElement('button');
+ refreshConnectionsButton.className = 'settings-button';
+ refreshConnectionsButton.textContent = i18nString(UIStrings.mcpRefreshConnections);
+ refreshConnectionsButton.addEventListener('click', async () => {
try {
- const openrouterApiKey = openrouterApiKeyInput.value.trim();
-
- if (!openrouterApiKey) {
- logger.debug('No OpenRouter API key available for auto-refresh');
- return;
- }
-
- logger.debug('Auto-refreshing OpenRouter models...');
- const openrouterModels = await LLMClient.fetchOpenRouterModels(openrouterApiKey);
-
- // Convert OpenRouter models to ModelOption format
- const modelOptions: ModelOption[] = openrouterModels.map(model => ({
- value: model.id,
- label: model.name || model.id,
- type: 'openrouter' as const
- }));
-
- // Store in localStorage with timestamp
- localStorage.setItem('openrouter_models_cache', JSON.stringify(modelOptions));
- localStorage.setItem('openrouter_models_cache_timestamp', Date.now().toString());
-
- // Also update global model options so UI immediately sees models
- updateModelOptions(modelOptions, false);
-
- logger.debug(`Auto-refreshed ${modelOptions.length} OpenRouter models`);
- } catch (error) {
- logger.warn('Failed to auto-refresh OpenRouter models:', error);
+ await MCPRegistry.init(true);
+ await MCPRegistry.refresh();
+ } catch (err) {
+ logger.error('Failed to refresh MCP connections', err);
+ } finally {
+ updateMCPStatus();
+ updateActionButtons();
}
- }
+ });
+ mcpConnectionsActions.appendChild(refreshConnectionsButton);
- // Function to update OpenRouter model selectors
- async function updateOpenRouterModelSelectors() {
- logger.debug('Updating OpenRouter model selectors');
-
- // Check if OpenRouter models cache is stale and auto-refresh if needed
- await checkAndRefreshOpenRouterCache();
-
- // Get the latest model options filtered for OpenRouter provider
- const openrouterModels = getModelOptions('openrouter');
- logger.debug('OpenRouter models from getModelOptions:', openrouterModels);
+ // MCP config inputs (always visible since MCP is always enabled)
+ const mcpConfigContainer = document.createElement('div');
+ mcpConfigContainer.className = 'mcp-config-container';
+ mcpConfigContainer.style.display = 'block';
+ mcpSection.appendChild(mcpConfigContainer);
- // Get valid models using generic helper
- const validMiniModel = getValidModelForProvider(miniModel, openrouterModels, 'openrouter', 'mini');
- const validNanoModel = getValidModelForProvider(nanoModel, openrouterModels, 'openrouter', 'nano');
-
- logger.debug('OpenRouter model selection:', { originalMini: miniModel, validMini: validMiniModel, originalNano: nanoModel, validNano: validNanoModel });
+ // Tool mode selection
+ const mcpToolModeLabel = document.createElement('div');
+ mcpToolModeLabel.className = 'settings-label';
+ mcpToolModeLabel.textContent = i18nString(UIStrings.mcpToolMode);
+ mcpConfigContainer.appendChild(mcpToolModeLabel);
- // Clear any existing model selectors
- const existingSelectors = openrouterContent.querySelectorAll('.model-selection-section');
- existingSelectors.forEach(selector => selector.remove());
-
- // Create a new model selection section
- const openrouterModelSection = document.createElement('div');
- openrouterModelSection.className = 'model-selection-section';
- openrouterContent.appendChild(openrouterModelSection);
-
- // Create Mini Model selection for OpenRouter and store reference
- SettingsDialog.#openrouterMiniModelSelect = createModelSelector(
- openrouterModelSection,
- i18nString(UIStrings.miniModelLabel),
- i18nString(UIStrings.miniModelDescription),
- 'openrouter-mini-model-select',
- openrouterModels,
- validMiniModel,
- i18nString(UIStrings.defaultMiniOption),
- undefined // No focus handler needed for OpenRouter
- );
-
- // Create Nano Model selection for OpenRouter and store reference
- SettingsDialog.#openrouterNanoModelSelect = createModelSelector(
- openrouterModelSection,
- i18nString(UIStrings.nanoModelLabel),
- i18nString(UIStrings.nanoModelDescription),
- 'openrouter-nano-model-select',
- openrouterModels,
- validNanoModel,
- i18nString(UIStrings.defaultNanoOption),
- undefined // No focus handler needed for OpenRouter
- );
- }
-
- // Add click handler for fetch OpenRouter models button
- fetchOpenRouterModelsButton.addEventListener('click', async () => {
- fetchOpenRouterModelsButton.disabled = true;
- fetchOpenRouterModelsStatus.textContent = i18nString(UIStrings.fetchingModels);
- fetchOpenRouterModelsStatus.style.display = 'block';
- fetchOpenRouterModelsStatus.style.backgroundColor = 'var(--color-accent-blue-background)';
- fetchOpenRouterModelsStatus.style.color = 'var(--color-accent-blue)';
+ const mcpToolModeHint = document.createElement('div');
+ mcpToolModeHint.className = 'settings-hint';
+ mcpToolModeHint.textContent = i18nString(UIStrings.mcpToolModeHint);
+ mcpConfigContainer.appendChild(mcpToolModeHint);
- try {
- const openrouterApiKey = openrouterApiKeyInput.value.trim();
-
- // Fetch OpenRouter models using LLMClient static method
- const openrouterModels = await LLMClient.fetchOpenRouterModels(openrouterApiKey);
-
- // Convert OpenRouter models to ModelOption format
- const modelOptions: ModelOption[] = openrouterModels.map(model => ({
- value: model.id,
- label: model.name || model.id,
- type: 'openrouter' as const
- }));
-
- // Update model options with fetched OpenRouter models
- updateModelOptions(modelOptions, false);
-
- // Update timestamp for cache management
- localStorage.setItem('openrouter_models_cache_timestamp', Date.now().toString());
-
- const actualModelCount = openrouterModels.length;
-
- // Update the model selectors with the new models
- await updateOpenRouterModelSelectors();
-
- // Update status to show success
- fetchOpenRouterModelsStatus.textContent = i18nString(UIStrings.fetchedModels, {PH1: actualModelCount});
- fetchOpenRouterModelsStatus.style.backgroundColor = 'var(--color-accent-green-background)';
- fetchOpenRouterModelsStatus.style.color = 'var(--color-accent-green)';
-
- logger.debug(`Successfully fetched ${actualModelCount} OpenRouter models`);
- } catch (error) {
- logger.error('Error fetching OpenRouter models:', error);
- fetchOpenRouterModelsStatus.textContent = `Error: ${error instanceof Error ? error.message : 'Unknown error'}`;
- fetchOpenRouterModelsStatus.style.backgroundColor = 'var(--color-accent-red-background)';
- fetchOpenRouterModelsStatus.style.color = 'var(--color-accent-red)';
- } finally {
- fetchOpenRouterModelsButton.disabled = false;
-
- // Hide status message after 3 seconds
- setTimeout(() => {
- fetchOpenRouterModelsStatus.style.display = 'none';
- }, 3000);
+ const mcpToolModeSelect = document.createElement('select');
+ mcpToolModeSelect.className = 'settings-select';
+ mcpConfigContainer.appendChild(mcpToolModeSelect);
+
+ // Tool mode options
+ const toolModeOptions = [
+ { value: 'all', text: i18nString(UIStrings.mcpToolModeAll) },
+ { value: 'router', text: i18nString(UIStrings.mcpToolModeRouter) },
+ { value: 'meta', text: i18nString(UIStrings.mcpToolModeMeta) },
+ ];
+
+ toolModeOptions.forEach(option => {
+ const optionElement = document.createElement('option');
+ optionElement.value = option.value;
+ optionElement.textContent = option.text;
+ if ((currentMCPConfig.toolMode || 'router') === option.value) {
+ optionElement.selected = true;
}
+ mcpToolModeSelect.appendChild(optionElement);
});
-
- // Initialize OpenRouter model selectors
- await updateOpenRouterModelSelectors();
-
- // Add Vector DB configuration section
- const vectorDBSection = document.createElement('div');
- vectorDBSection.className = 'settings-section vector-db-section';
- contentDiv.appendChild(vectorDBSection);
-
- const vectorDBTitle = document.createElement('h3');
- vectorDBTitle.textContent = i18nString(UIStrings.vectorDBLabel);
- vectorDBTitle.classList.add('settings-subtitle');
- vectorDBSection.appendChild(vectorDBTitle);
-
- // Vector DB enabled checkbox
- const vectorDBEnabledContainer = document.createElement('div');
- vectorDBEnabledContainer.className = 'tracing-enabled-container';
- vectorDBSection.appendChild(vectorDBEnabledContainer);
- const vectorDBEnabledCheckbox = document.createElement('input');
- vectorDBEnabledCheckbox.type = 'checkbox';
- vectorDBEnabledCheckbox.id = 'vector-db-enabled';
- vectorDBEnabledCheckbox.className = 'tracing-checkbox';
- vectorDBEnabledCheckbox.checked = localStorage.getItem(VECTOR_DB_ENABLED_KEY) === 'true';
- vectorDBEnabledContainer.appendChild(vectorDBEnabledCheckbox);
+ // Ensure the select reflects the currently stored mode even if options were appended later
+ mcpToolModeSelect.value = (currentMCPConfig.toolMode || 'router');
- const vectorDBEnabledLabel = document.createElement('label');
- vectorDBEnabledLabel.htmlFor = 'vector-db-enabled';
- vectorDBEnabledLabel.className = 'tracing-label';
- vectorDBEnabledLabel.textContent = i18nString(UIStrings.vectorDBEnabled);
- vectorDBEnabledContainer.appendChild(vectorDBEnabledLabel);
+ // Handle tool mode changes
+ mcpToolModeSelect.addEventListener('change', () => {
+ setMCPConfig({ toolMode: mcpToolModeSelect.value as 'all' | 'router' | 'meta' });
+ onSettingsSaved();
+ });
- const vectorDBEnabledHint = document.createElement('div');
- vectorDBEnabledHint.className = 'settings-hint';
- vectorDBEnabledHint.textContent = i18nString(UIStrings.vectorDBEnabledHint);
- vectorDBSection.appendChild(vectorDBEnabledHint);
+ // Advanced budget controls
+ const mcpMaxToolsLabel = document.createElement('div');
+ mcpMaxToolsLabel.className = 'settings-label';
+ mcpMaxToolsLabel.textContent = i18nString(UIStrings.mcpMaxToolsPerTurn);
+ mcpConfigContainer.appendChild(mcpMaxToolsLabel);
- // Vector DB configuration container (shown when enabled)
- const vectorDBConfigContainer = document.createElement('div');
- vectorDBConfigContainer.className = 'tracing-config-container';
- vectorDBConfigContainer.style.display = vectorDBEnabledCheckbox.checked ? 'block' : 'none';
- vectorDBSection.appendChild(vectorDBConfigContainer);
+ const mcpMaxToolsHint = document.createElement('div');
+ mcpMaxToolsHint.className = 'settings-hint';
+ mcpMaxToolsHint.textContent = i18nString(UIStrings.mcpMaxToolsPerTurnHint);
+ mcpConfigContainer.appendChild(mcpMaxToolsHint);
+
+ const mcpMaxToolsInput = document.createElement('input');
+ mcpMaxToolsInput.type = 'number';
+ mcpMaxToolsInput.className = 'settings-input';
+ mcpMaxToolsInput.min = '1';
+ mcpMaxToolsInput.max = '100';
+ mcpMaxToolsInput.value = String(currentMCPConfig.maxToolsPerTurn || 20);
+ mcpConfigContainer.appendChild(mcpMaxToolsInput);
+
+ const mcpMaxMcpLabel = document.createElement('div');
+ mcpMaxMcpLabel.className = 'settings-label';
+ mcpMaxMcpLabel.textContent = i18nString(UIStrings.mcpMaxMcpPerTurn);
+ mcpConfigContainer.appendChild(mcpMaxMcpLabel);
+
+ const mcpMaxMcpHint = document.createElement('div');
+ mcpMaxMcpHint.className = 'settings-hint';
+ mcpMaxMcpHint.textContent = i18nString(UIStrings.mcpMaxMcpPerTurnHint);
+ mcpConfigContainer.appendChild(mcpMaxMcpHint);
+
+ const mcpMaxMcpInput = document.createElement('input');
+ mcpMaxMcpInput.type = 'number';
+ mcpMaxMcpInput.className = 'settings-input';
+ mcpMaxMcpInput.min = '1';
+ mcpMaxMcpInput.max = '50';
+ mcpMaxMcpInput.value = String(currentMCPConfig.maxMcpPerTurn || 8);
+ mcpConfigContainer.appendChild(mcpMaxMcpInput);
+
+ // Handle budget control changes
+ const updateBudgetControls = () => {
+ const maxTools = Math.max(1, Math.min(100, parseInt(mcpMaxToolsInput.value, 10) || 20));
+ const maxMcp = Math.max(1, Math.min(50, parseInt(mcpMaxMcpInput.value, 10) || 8));
+ setMCPConfig({
+ maxToolsPerTurn: maxTools,
+ maxMcpPerTurn: maxMcp,
+ });
+ onSettingsSaved();
+ };
+
+ mcpMaxToolsInput.addEventListener('change', updateBudgetControls);
+ mcpMaxMcpInput.addEventListener('change', updateBudgetControls);
+
+
+ // Add Advanced Settings Toggle
+ const ADVANCED_SETTINGS_ENABLED_KEY = 'ai_chat_advanced_settings_enabled';
- // Vector DB Endpoint
- const vectorDBEndpointDiv = document.createElement('div');
- vectorDBEndpointDiv.classList.add('settings-field');
- vectorDBConfigContainer.appendChild(vectorDBEndpointDiv);
+ const advancedToggleSection = document.createElement('div');
+ advancedToggleSection.className = 'advanced-settings-toggle-section';
+ contentDiv.appendChild(advancedToggleSection);
- const vectorDBEndpointLabel = document.createElement('label');
- vectorDBEndpointLabel.textContent = i18nString(UIStrings.vectorDBEndpoint);
- vectorDBEndpointLabel.classList.add('settings-label');
- vectorDBEndpointDiv.appendChild(vectorDBEndpointLabel);
+ const advancedToggleContainer = document.createElement('div');
+ advancedToggleContainer.className = 'advanced-settings-toggle-container';
+ advancedToggleSection.appendChild(advancedToggleContainer);
- const vectorDBEndpointHint = document.createElement('div');
- vectorDBEndpointHint.textContent = i18nString(UIStrings.vectorDBEndpointHint);
- vectorDBEndpointHint.classList.add('settings-hint');
- vectorDBEndpointDiv.appendChild(vectorDBEndpointHint);
+ const advancedToggleCheckbox = document.createElement('input');
+ advancedToggleCheckbox.type = 'checkbox';
+ advancedToggleCheckbox.id = 'advanced-settings-toggle';
+ advancedToggleCheckbox.className = 'advanced-settings-checkbox';
+ advancedToggleCheckbox.checked = localStorage.getItem(ADVANCED_SETTINGS_ENABLED_KEY) === 'true';
+ advancedToggleContainer.appendChild(advancedToggleCheckbox);
- const vectorDBEndpointInput = document.createElement('input');
- vectorDBEndpointInput.classList.add('settings-input');
- vectorDBEndpointInput.type = 'text';
- vectorDBEndpointInput.placeholder = 'http://localhost:19530';
- vectorDBEndpointInput.value = localStorage.getItem(MILVUS_ENDPOINT_KEY) || '';
- vectorDBEndpointDiv.appendChild(vectorDBEndpointInput);
+ const advancedToggleLabel = document.createElement('label');
+ advancedToggleLabel.htmlFor = 'advanced-settings-toggle';
+ advancedToggleLabel.className = 'advanced-settings-label';
+ advancedToggleLabel.textContent = '⚙️ Advanced Settings';
+ advancedToggleContainer.appendChild(advancedToggleLabel);
- // Vector DB API Key
- const vectorDBApiKeyDiv = document.createElement('div');
- vectorDBApiKeyDiv.classList.add('settings-field');
- vectorDBConfigContainer.appendChild(vectorDBApiKeyDiv);
+ const advancedToggleHint = document.createElement('div');
+ advancedToggleHint.className = 'settings-hint';
+ advancedToggleHint.textContent = 'Show advanced configuration options (Browsing History, Vector DB, Tracing, Evaluation)';
+ advancedToggleSection.appendChild(advancedToggleHint);
- const vectorDBApiKeyLabel = document.createElement('label');
- vectorDBApiKeyLabel.textContent = i18nString(UIStrings.vectorDBApiKey);
- vectorDBApiKeyLabel.classList.add('settings-label');
- vectorDBApiKeyDiv.appendChild(vectorDBApiKeyLabel);
-
- const vectorDBApiKeyHint = document.createElement('div');
- vectorDBApiKeyHint.textContent = i18nString(UIStrings.vectorDBApiKeyHint);
- vectorDBApiKeyHint.classList.add('settings-hint');
- vectorDBApiKeyDiv.appendChild(vectorDBApiKeyHint);
-
- const vectorDBApiKeyInput = document.createElement('input');
- vectorDBApiKeyInput.classList.add('settings-input');
- vectorDBApiKeyInput.type = 'text';
- vectorDBApiKeyInput.placeholder = 'root';
- vectorDBApiKeyInput.value = localStorage.getItem(MILVUS_USERNAME_KEY) || 'root';
- vectorDBApiKeyDiv.appendChild(vectorDBApiKeyInput);
-
- // Milvus Password
- const milvusPasswordDiv = document.createElement('div');
- milvusPasswordDiv.classList.add('settings-field');
- vectorDBConfigContainer.appendChild(milvusPasswordDiv);
-
- const milvusPasswordLabel = document.createElement('label');
- milvusPasswordLabel.textContent = i18nString(UIStrings.milvusPassword);
- milvusPasswordLabel.classList.add('settings-label');
- milvusPasswordDiv.appendChild(milvusPasswordLabel);
+ // Add browsing history section
+ const historySection = document.createElement('div');
+ historySection.className = 'settings-section history-section';
+ contentDiv.appendChild(historySection);
- const milvusPasswordHint = document.createElement('div');
- milvusPasswordHint.textContent = i18nString(UIStrings.milvusPasswordHint);
- milvusPasswordHint.classList.add('settings-hint');
- milvusPasswordDiv.appendChild(milvusPasswordHint);
+ const historyTitle = document.createElement('h3');
+ historyTitle.className = 'settings-subtitle';
+ historyTitle.textContent = i18nString(UIStrings.browsingHistoryTitle);
+ historySection.appendChild(historyTitle);
- const milvusPasswordInput = document.createElement('input');
- milvusPasswordInput.classList.add('settings-input');
- milvusPasswordInput.type = 'password';
- milvusPasswordInput.placeholder = 'Milvus (self-hosted) or API token (cloud)';
- milvusPasswordInput.value = localStorage.getItem(MILVUS_PASSWORD_KEY) || 'Milvus';
- milvusPasswordDiv.appendChild(milvusPasswordInput);
+ const historyDescription = document.createElement('p');
+ historyDescription.className = 'settings-description';
+ historyDescription.textContent = i18nString(UIStrings.browsingHistoryDescription);
+ historySection.appendChild(historyDescription);
- // OpenAI API Key for embeddings
- const milvusOpenAIDiv = document.createElement('div');
- milvusOpenAIDiv.classList.add('settings-field');
- vectorDBConfigContainer.appendChild(milvusOpenAIDiv);
+ // Status message element (initially hidden)
+ const statusMessage = document.createElement('div');
+ statusMessage.className = 'settings-status history-status';
+ statusMessage.style.display = 'none';
+ statusMessage.textContent = i18nString(UIStrings.historyCleared);
+ historySection.appendChild(statusMessage);
- const milvusOpenAILabel = document.createElement('label');
- milvusOpenAILabel.textContent = i18nString(UIStrings.milvusOpenAIKey);
- milvusOpenAILabel.classList.add('settings-label');
- milvusOpenAIDiv.appendChild(milvusOpenAILabel);
+ // Clear history button
+ const clearHistoryButton = document.createElement('button');
+ clearHistoryButton.textContent = i18nString(UIStrings.clearHistoryButton);
+ clearHistoryButton.className = 'settings-button clear-button';
+ clearHistoryButton.setAttribute('type', 'button');
+ historySection.appendChild(clearHistoryButton);
- const milvusOpenAIHint = document.createElement('div');
- milvusOpenAIHint.textContent = i18nString(UIStrings.milvusOpenAIKeyHint);
- milvusOpenAIHint.classList.add('settings-hint');
- milvusOpenAIDiv.appendChild(milvusOpenAIHint);
+ clearHistoryButton.addEventListener('click', async () => {
+ try {
+ // Import the VisitHistoryManager from its dedicated file
+ const { VisitHistoryManager } = await import('../tools/VisitHistoryManager.js');
+ await VisitHistoryManager.getInstance().clearHistory();
+
+ // Show success message
+ statusMessage.style.display = 'block';
+
+ // Hide message after 3 seconds
+ setTimeout(() => {
+ statusMessage.style.display = 'none';
+ }, 3000);
+ } catch (error) {
+ logger.error('Error clearing browsing history:', error);
+ }
+ });
- const milvusOpenAIInput = document.createElement('input');
- milvusOpenAIInput.classList.add('settings-input');
- milvusOpenAIInput.type = 'password';
- milvusOpenAIInput.placeholder = 'sk-...';
- milvusOpenAIInput.value = localStorage.getItem(MILVUS_OPENAI_KEY) || '';
- milvusOpenAIDiv.appendChild(milvusOpenAIInput);
+ // Initialize LiteLLM model selectors
+ updateLiteLLMModelSelectors();
- // Vector DB Collection Name
- const vectorDBCollectionDiv = document.createElement('div');
- vectorDBCollectionDiv.classList.add('settings-field');
- vectorDBConfigContainer.appendChild(vectorDBCollectionDiv);
+ // Setup Groq content
+ const groqSettingsSection = document.createElement('div');
+ groqSettingsSection.className = 'settings-section';
+ groqContent.appendChild(groqSettingsSection);
- const vectorDBCollectionLabel = document.createElement('label');
- vectorDBCollectionLabel.textContent = i18nString(UIStrings.vectorDBCollection);
- vectorDBCollectionLabel.classList.add('settings-label');
- vectorDBCollectionDiv.appendChild(vectorDBCollectionLabel);
+ // Groq API Key
+ const groqApiKeyLabel = document.createElement('div');
+ groqApiKeyLabel.className = 'settings-label';
+ groqApiKeyLabel.textContent = i18nString(UIStrings.groqApiKeyLabel);
+ groqSettingsSection.appendChild(groqApiKeyLabel);
- const vectorDBCollectionHint = document.createElement('div');
- vectorDBCollectionHint.textContent = i18nString(UIStrings.vectorDBCollectionHint);
- vectorDBCollectionHint.classList.add('settings-hint');
- vectorDBCollectionDiv.appendChild(vectorDBCollectionHint);
+ const groqApiKeyHint = document.createElement('div');
+ groqApiKeyHint.className = 'settings-hint';
+ groqApiKeyHint.textContent = i18nString(UIStrings.groqApiKeyHint);
+ groqSettingsSection.appendChild(groqApiKeyHint);
- const vectorDBCollectionInput = document.createElement('input');
- vectorDBCollectionInput.classList.add('settings-input');
- vectorDBCollectionInput.type = 'text';
- vectorDBCollectionInput.placeholder = 'bookmarks';
- vectorDBCollectionInput.value = localStorage.getItem(MILVUS_COLLECTION_KEY) || 'bookmarks';
- vectorDBCollectionDiv.appendChild(vectorDBCollectionInput);
+ const settingsSavedGroqApiKey = localStorage.getItem(GROQ_API_KEY_STORAGE_KEY) || '';
+ const groqApiKeyInput = document.createElement('input');
+ groqApiKeyInput.className = 'settings-input groq-api-key-input';
+ groqApiKeyInput.type = 'password';
+ groqApiKeyInput.placeholder = 'Enter your Groq API key';
+ groqApiKeyInput.value = settingsSavedGroqApiKey;
+ groqSettingsSection.appendChild(groqApiKeyInput);
- // Test Vector DB Connection Button
- const vectorDBTestDiv = document.createElement('div');
- vectorDBTestDiv.classList.add('settings-field', 'test-connection-field');
- vectorDBConfigContainer.appendChild(vectorDBTestDiv);
+ // Fetch Groq models button
+ const groqFetchButtonContainer = document.createElement('div');
+ groqFetchButtonContainer.className = 'fetch-button-container';
+ groqSettingsSection.appendChild(groqFetchButtonContainer);
- const vectorDBTestButton = document.createElement('button');
- vectorDBTestButton.classList.add('settings-button', 'test-button');
- vectorDBTestButton.setAttribute('type', 'button');
- vectorDBTestButton.textContent = i18nString(UIStrings.testVectorDBConnection);
- vectorDBTestDiv.appendChild(vectorDBTestButton);
+ const fetchGroqModelsButton = document.createElement('button');
+ fetchGroqModelsButton.className = 'settings-button';
+ fetchGroqModelsButton.setAttribute('type', 'button');
+ fetchGroqModelsButton.textContent = i18nString(UIStrings.fetchGroqModelsButton);
+ fetchGroqModelsButton.disabled = !groqApiKeyInput.value.trim();
+ groqFetchButtonContainer.appendChild(fetchGroqModelsButton);
- const vectorDBTestStatus = document.createElement('div');
- vectorDBTestStatus.classList.add('settings-status');
- vectorDBTestStatus.style.display = 'none';
- vectorDBTestDiv.appendChild(vectorDBTestStatus);
+ const fetchGroqModelsStatus = document.createElement('div');
+ fetchGroqModelsStatus.className = 'settings-status';
+ fetchGroqModelsStatus.style.display = 'none';
+ groqFetchButtonContainer.appendChild(fetchGroqModelsStatus);
- // Toggle vector DB config visibility
- vectorDBEnabledCheckbox.addEventListener('change', () => {
- vectorDBConfigContainer.style.display = vectorDBEnabledCheckbox.checked ? 'block' : 'none';
- localStorage.setItem(VECTOR_DB_ENABLED_KEY, vectorDBEnabledCheckbox.checked.toString());
+ // Update button state when API key changes
+ groqApiKeyInput.addEventListener('input', () => {
+ fetchGroqModelsButton.disabled = !groqApiKeyInput.value.trim();
});
- // Save Vector DB settings on input change
- const saveVectorDBSettings = () => {
- localStorage.setItem(VECTOR_DB_ENABLED_KEY, vectorDBEnabledCheckbox.checked.toString());
- localStorage.setItem(MILVUS_ENDPOINT_KEY, vectorDBEndpointInput.value);
- localStorage.setItem(MILVUS_USERNAME_KEY, vectorDBApiKeyInput.value);
- localStorage.setItem(MILVUS_PASSWORD_KEY, milvusPasswordInput.value);
- localStorage.setItem(MILVUS_COLLECTION_KEY, vectorDBCollectionInput.value);
- localStorage.setItem(MILVUS_OPENAI_KEY, milvusOpenAIInput.value);
- };
-
- vectorDBEndpointInput.addEventListener('input', saveVectorDBSettings);
- vectorDBApiKeyInput.addEventListener('input', saveVectorDBSettings);
- milvusPasswordInput.addEventListener('input', saveVectorDBSettings);
- vectorDBCollectionInput.addEventListener('input', saveVectorDBSettings);
- milvusOpenAIInput.addEventListener('input', saveVectorDBSettings);
-
- // Test Vector DB connection
- vectorDBTestButton.addEventListener('click', async () => {
- const endpoint = vectorDBEndpointInput.value.trim();
-
- if (!endpoint) {
- vectorDBTestStatus.textContent = 'Please enter an endpoint URL';
- vectorDBTestStatus.style.color = 'var(--color-accent-red)';
- vectorDBTestStatus.style.display = 'block';
- setTimeout(() => {
- vectorDBTestStatus.style.display = 'none';
- }, 3000);
- return;
+ // Generic helper function to get valid model for provider
+ function getValidModelForProvider(
+ currentModel: string,
+ providerModels: ModelOption[],
+ provider: 'openai' | 'litellm' | 'groq' | 'openrouter',
+ modelType: 'mini' | 'nano'
+ ): string {
+ // Check if current model is valid for this provider
+ if (providerModels.some(model => model.value === currentModel)) {
+ return currentModel;
}
- vectorDBTestButton.disabled = true;
- vectorDBTestStatus.textContent = i18nString(UIStrings.testingVectorDBConnection);
- vectorDBTestStatus.style.color = 'var(--color-text-secondary)';
- vectorDBTestStatus.style.display = 'block';
+ // Get defaults from AIChatPanel's DEFAULT_PROVIDER_MODELS
+ const defaults = DEFAULT_PROVIDER_MODELS[provider] || DEFAULT_PROVIDER_MODELS.openai;
+ const defaultModel = modelType === 'mini' ? defaults.mini : defaults.nano;
- try {
- // Import and test the Vector DB client
- const { VectorDBClient } = await import('../tools/VectorDBClient.js');
- const vectorClient = new VectorDBClient({
- endpoint,
- username: vectorDBApiKeyInput.value || 'root',
- password: milvusPasswordInput.value || 'Milvus',
- collection: vectorDBCollectionInput.value || 'bookmarks',
- openaiApiKey: milvusOpenAIInput.value || undefined
- });
-
- const testResult = await vectorClient.testConnection();
-
- if (testResult.success) {
- vectorDBTestStatus.textContent = i18nString(UIStrings.vectorDBConnectionSuccess);
- vectorDBTestStatus.style.color = 'var(--color-accent-green)';
- } else {
- vectorDBTestStatus.textContent = `${i18nString(UIStrings.vectorDBConnectionFailed)}: ${testResult.error}`;
- vectorDBTestStatus.style.color = 'var(--color-accent-red)';
- }
- } catch (error: any) {
- vectorDBTestStatus.textContent = `${i18nString(UIStrings.vectorDBConnectionFailed)}: ${error.message}`;
- vectorDBTestStatus.style.color = 'var(--color-accent-red)';
- } finally {
- vectorDBTestButton.disabled = false;
- setTimeout(() => {
- vectorDBTestStatus.style.display = 'none';
- }, 5000);
+ // Return default if it exists in provider models
+ if (defaultModel && providerModels.some(model => model.value === defaultModel)) {
+ return defaultModel;
}
- });
-
- // Add tracing configuration section
- const tracingSection = document.createElement('div');
- tracingSection.className = 'settings-section tracing-section';
- contentDiv.appendChild(tracingSection);
-
- const tracingSectionTitle = document.createElement('h3');
- tracingSectionTitle.className = 'settings-subtitle';
- tracingSectionTitle.textContent = i18nString(UIStrings.tracingSection);
- tracingSection.appendChild(tracingSectionTitle);
- // Get current tracing configuration
- const currentTracingConfig = getTracingConfig();
-
- // Tracing enabled checkbox
- const tracingEnabledContainer = document.createElement('div');
- tracingEnabledContainer.className = 'tracing-enabled-container';
- tracingSection.appendChild(tracingEnabledContainer);
-
- const tracingEnabledCheckbox = document.createElement('input');
- tracingEnabledCheckbox.type = 'checkbox';
- tracingEnabledCheckbox.id = 'tracing-enabled';
- tracingEnabledCheckbox.className = 'tracing-checkbox';
- tracingEnabledCheckbox.checked = isTracingEnabled();
- tracingEnabledContainer.appendChild(tracingEnabledCheckbox);
-
- const tracingEnabledLabel = document.createElement('label');
- tracingEnabledLabel.htmlFor = 'tracing-enabled';
- tracingEnabledLabel.className = 'tracing-label';
- tracingEnabledLabel.textContent = i18nString(UIStrings.tracingEnabled);
- tracingEnabledContainer.appendChild(tracingEnabledLabel);
-
- const tracingEnabledHint = document.createElement('div');
- tracingEnabledHint.className = 'settings-hint';
- tracingEnabledHint.textContent = i18nString(UIStrings.tracingEnabledHint);
- tracingSection.appendChild(tracingEnabledHint);
-
- // Tracing configuration container (shown when enabled)
- const tracingConfigContainer = document.createElement('div');
- tracingConfigContainer.className = 'tracing-config-container';
- tracingConfigContainer.style.display = tracingEnabledCheckbox.checked ? 'block' : 'none';
- tracingSection.appendChild(tracingConfigContainer);
-
- // Langfuse endpoint
- const endpointLabel = document.createElement('div');
- endpointLabel.className = 'settings-label';
- endpointLabel.textContent = i18nString(UIStrings.langfuseEndpoint);
- tracingConfigContainer.appendChild(endpointLabel);
-
- const endpointHint = document.createElement('div');
- endpointHint.className = 'settings-hint';
- endpointHint.textContent = i18nString(UIStrings.langfuseEndpointHint);
- tracingConfigContainer.appendChild(endpointHint);
-
- const endpointInput = document.createElement('input');
- endpointInput.className = 'settings-input';
- endpointInput.type = 'text';
- endpointInput.placeholder = 'http://localhost:3000';
- endpointInput.value = currentTracingConfig.endpoint || 'http://localhost:3000';
- tracingConfigContainer.appendChild(endpointInput);
-
- // Langfuse public key
- const publicKeyLabel = document.createElement('div');
- publicKeyLabel.className = 'settings-label';
- publicKeyLabel.textContent = i18nString(UIStrings.langfusePublicKey);
- tracingConfigContainer.appendChild(publicKeyLabel);
-
- const publicKeyHint = document.createElement('div');
- publicKeyHint.className = 'settings-hint';
- publicKeyHint.textContent = i18nString(UIStrings.langfusePublicKeyHint);
- tracingConfigContainer.appendChild(publicKeyHint);
-
- const publicKeyInput = document.createElement('input');
- publicKeyInput.className = 'settings-input';
- publicKeyInput.type = 'text';
- publicKeyInput.placeholder = 'pk-lf-...';
- publicKeyInput.value = currentTracingConfig.publicKey || '';
- tracingConfigContainer.appendChild(publicKeyInput);
-
- // Langfuse secret key
- const secretKeyLabel = document.createElement('div');
- secretKeyLabel.className = 'settings-label';
- secretKeyLabel.textContent = i18nString(UIStrings.langfuseSecretKey);
- tracingConfigContainer.appendChild(secretKeyLabel);
-
- const secretKeyHint = document.createElement('div');
- secretKeyHint.className = 'settings-hint';
- secretKeyHint.textContent = i18nString(UIStrings.langfuseSecretKeyHint);
- tracingConfigContainer.appendChild(secretKeyHint);
-
- const secretKeyInput = document.createElement('input');
- secretKeyInput.className = 'settings-input';
- secretKeyInput.type = 'password';
- secretKeyInput.placeholder = 'sk-lf-...';
- secretKeyInput.value = currentTracingConfig.secretKey || '';
- tracingConfigContainer.appendChild(secretKeyInput);
-
- // Test connection button
- const testTracingButton = document.createElement('button');
- testTracingButton.className = 'settings-button test-button';
- testTracingButton.textContent = i18nString(UIStrings.testTracing);
- tracingConfigContainer.appendChild(testTracingButton);
-
- // Test status message
- const testTracingStatus = document.createElement('div');
- testTracingStatus.className = 'settings-status';
- testTracingStatus.style.display = 'none';
- tracingConfigContainer.appendChild(testTracingStatus);
+ // If no valid model found, return empty string to indicate no selection
+ // The UI should handle this by showing a placeholder or the first available option
+ return '';
+ }
+
+ // Function to update Groq model selectors
+ function updateGroqModelSelectors() {
+ logger.debug('Updating Groq model selectors');
+
+ // Get the latest model options filtered for Groq provider
+ const groqModels = getModelOptions('groq');
+ logger.debug('Groq models from getModelOptions:', groqModels);
- // Toggle tracing config visibility
- tracingEnabledCheckbox.addEventListener('change', () => {
- tracingConfigContainer.style.display = tracingEnabledCheckbox.checked ? 'block' : 'none';
- });
+ // Get valid models using generic helper
+ const validMiniModel = getValidModelForProvider(miniModel, groqModels, 'groq', 'mini');
+ const validNanoModel = getValidModelForProvider(nanoModel, groqModels, 'groq', 'nano');
+
+ logger.debug('Groq model selection:', { originalMini: miniModel, validMini: validMiniModel, originalNano: nanoModel, validNano: validNanoModel });
- // Test tracing connection
- testTracingButton.addEventListener('click', async () => {
- testTracingButton.disabled = true;
- testTracingStatus.style.display = 'block';
- testTracingStatus.textContent = 'Testing connection...';
- testTracingStatus.style.backgroundColor = 'var(--color-background-elevation-1)';
- testTracingStatus.style.color = 'var(--color-text-primary)';
+ // Clear any existing model selectors
+ const existingSelectors = groqContent.querySelectorAll('.model-selection-section');
+ existingSelectors.forEach(selector => selector.remove());
+
+ // Create a new model selection section
+ const groqModelSection = document.createElement('div');
+ groqModelSection.className = 'settings-section model-selection-section';
+ groqContent.appendChild(groqModelSection);
+
+ const groqModelSectionTitle = document.createElement('h3');
+ groqModelSectionTitle.className = 'settings-subtitle';
+ groqModelSectionTitle.textContent = 'Model Size Selection';
+ groqModelSection.appendChild(groqModelSectionTitle);
+
+
+ // Create Groq Mini Model selection and store reference
+ SettingsDialog.#groqMiniModelSelect = createModelSelector(
+ groqModelSection,
+ i18nString(UIStrings.miniModelLabel),
+ i18nString(UIStrings.miniModelDescription),
+ 'groq-mini-model-select',
+ groqModels,
+ validMiniModel,
+ i18nString(UIStrings.defaultMiniOption),
+ undefined // No focus handler needed for Groq
+ );
+
+ logger.debug('Created Groq Mini Model Select:', SettingsDialog.#groqMiniModelSelect);
+
+ // Create Groq Nano Model selection and store reference
+ SettingsDialog.#groqNanoModelSelect = createModelSelector(
+ groqModelSection,
+ i18nString(UIStrings.nanoModelLabel),
+ i18nString(UIStrings.nanoModelDescription),
+ 'groq-nano-model-select',
+ groqModels,
+ validNanoModel,
+ i18nString(UIStrings.defaultNanoOption),
+ undefined // No focus handler needed for Groq
+ );
+
+ logger.debug('Created Groq Nano Model Select:', SettingsDialog.#groqNanoModelSelect);
+ }
+
+ // Add click handler for fetch Groq models button
+ fetchGroqModelsButton.addEventListener('click', async () => {
+ fetchGroqModelsButton.disabled = true;
+ fetchGroqModelsStatus.textContent = i18nString(UIStrings.fetchingModels);
+ fetchGroqModelsStatus.style.display = 'block';
+ fetchGroqModelsStatus.style.backgroundColor = 'var(--color-accent-blue-background)';
+ fetchGroqModelsStatus.style.color = 'var(--color-accent-blue)';
try {
- const endpoint = endpointInput.value.trim();
- const publicKey = publicKeyInput.value.trim();
- const secretKey = secretKeyInput.value.trim();
-
- if (!endpoint || !publicKey || !secretKey) {
- throw new Error('All fields are required for testing');
+ const groqApiKey = groqApiKeyInput.value.trim();
+
+ // Fetch Groq models using LLMClient static method
+ const groqModels = await LLMClient.fetchGroqModels(groqApiKey);
+
+ // Convert Groq models to ModelOption format
+ const modelOptions: ModelOption[] = groqModels.map(model => ({
+ value: model.id,
+ label: model.id,
+ type: 'groq' as const
+ }));
+
+ // Update model options with fetched Groq models
+ updateModelOptions(modelOptions, false);
+
+ // Get all Groq models including any custom ones
+ const allGroqModels = getModelOptions('groq');
+ const actualModelCount = groqModels.length;
+
+ // Refresh existing model selectors with new options if they exist
+ if (SettingsDialog.#groqMiniModelSelect) {
+ refreshModelSelectOptions(SettingsDialog.#groqMiniModelSelect, allGroqModels, miniModel, i18nString(UIStrings.defaultMiniOption));
}
-
- // Test the connection with a simple trace
- const testPayload = {
- batch: [{
- id: `test-${Date.now()}`,
- timestamp: new Date().toISOString(),
- type: 'trace-create',
- body: {
- id: `trace-test-${Date.now()}`,
- name: 'Connection Test',
- timestamp: new Date().toISOString()
- }
- }]
- };
-
- const response = await fetch(`${endpoint}/api/public/ingestion`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Basic ' + btoa(`${publicKey}:${secretKey}`)
- },
- body: JSON.stringify(testPayload)
- });
-
- if (response.ok) {
- testTracingStatus.textContent = '✓ Connection successful';
- testTracingStatus.style.backgroundColor = 'var(--color-accent-green-background)';
- testTracingStatus.style.color = 'var(--color-accent-green)';
- } else {
- const errorText = await response.text();
- throw new Error(`HTTP ${response.status}: ${errorText}`);
+ if (SettingsDialog.#groqNanoModelSelect) {
+ refreshModelSelectOptions(SettingsDialog.#groqNanoModelSelect, allGroqModels, nanoModel, i18nString(UIStrings.defaultNanoOption));
}
+
+ fetchGroqModelsStatus.textContent = i18nString(UIStrings.fetchedModels, {PH1: actualModelCount});
+ fetchGroqModelsStatus.style.backgroundColor = 'var(--color-accent-green-background)';
+ fetchGroqModelsStatus.style.color = 'var(--color-accent-green)';
+
+ // Update Groq model selections
+ updateGroqModelSelectors();
+
} catch (error) {
- testTracingStatus.textContent = `✗ ${error instanceof Error ? error.message : 'Connection failed'}`;
- testTracingStatus.style.backgroundColor = 'var(--color-accent-red-background)';
- testTracingStatus.style.color = 'var(--color-accent-red)';
+ logger.error('Failed to fetch Groq models:', error);
+ fetchGroqModelsStatus.textContent = `Error: ${error instanceof Error ? error.message : 'Unknown error'}`;
+ fetchGroqModelsStatus.style.backgroundColor = 'var(--color-accent-red-background)';
+ fetchGroqModelsStatus.style.color = 'var(--color-accent-red)';
} finally {
- testTracingButton.disabled = false;
+ fetchGroqModelsButton.disabled = !groqApiKeyInput.value.trim();
setTimeout(() => {
- testTracingStatus.style.display = 'none';
- }, 5000);
+ fetchGroqModelsStatus.style.display = 'none';
+ }, 3000);
}
});
+
+ // Initialize Groq model selectors
+ updateGroqModelSelectors();
+
+ // Setup OpenRouter content
+ const openrouterSettingsSection = document.createElement('div');
+ openrouterSettingsSection.className = 'settings-section';
+ openrouterContent.appendChild(openrouterSettingsSection);
+
+ // OpenRouter API Key
+ const openrouterApiKeyLabel = document.createElement('div');
+ openrouterApiKeyLabel.className = 'settings-label';
+ openrouterApiKeyLabel.textContent = i18nString(UIStrings.openrouterApiKeyLabel);
+ openrouterSettingsSection.appendChild(openrouterApiKeyLabel);
+
+ const openrouterApiKeyHint = document.createElement('div');
+ openrouterApiKeyHint.className = 'settings-hint';
+ openrouterApiKeyHint.textContent = i18nString(UIStrings.openrouterApiKeyHint);
+ openrouterSettingsSection.appendChild(openrouterApiKeyHint);
+
+ const settingsSavedOpenRouterApiKey = localStorage.getItem(OPENROUTER_API_KEY_STORAGE_KEY) || '';
+ const openrouterApiKeyInput = document.createElement('input');
+ openrouterApiKeyInput.className = 'settings-input openrouter-api-key-input';
+ openrouterApiKeyInput.type = 'password';
+ openrouterApiKeyInput.placeholder = 'Enter your OpenRouter API key';
+ openrouterApiKeyInput.value = settingsSavedOpenRouterApiKey;
+ openrouterSettingsSection.appendChild(openrouterApiKeyInput);
+
+ // OAuth section - alternative to API key
+ const oauthDivider = document.createElement('div');
+ oauthDivider.className = 'settings-divider';
+ oauthDivider.textContent = 'OR';
+ openrouterSettingsSection.appendChild(oauthDivider);
+
+ const oauthButtonContainer = document.createElement('div');
+ oauthButtonContainer.className = 'oauth-button-container';
+ openrouterSettingsSection.appendChild(oauthButtonContainer);
+
+ const oauthButton = document.createElement('button');
+ oauthButton.className = 'settings-button oauth-button';
+ oauthButton.setAttribute('type', 'button');
+ oauthButton.textContent = 'Connect with OpenRouter';
+ oauthButtonContainer.appendChild(oauthButton);
+
+ const oauthStatus = document.createElement('div');
+ oauthStatus.className = 'oauth-status';
+ oauthStatus.style.display = 'none';
+ oauthButtonContainer.appendChild(oauthStatus);
+
+ // Add OAuth-specific styles
+ const oauthStyles = document.createElement('style');
+ oauthStyles.textContent = `
+ .settings-divider {
+ text-align: center;
+ margin: 15px 0;
+ color: var(--color-text-secondary);
+ font-size: 12px;
+ font-weight: bold;
+ }
+ .oauth-button-container {
+ margin-bottom: 10px;
+ }
+ .oauth-button {
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
+ color: white;
+ border: none;
+ padding: 10px 20px;
+ border-radius: 6px;
+ cursor: pointer;
+ font-weight: 500;
+ transition: all 0.3s ease;
+ width: 100%;
+ margin-bottom: 8px;
+ }
+ .oauth-button:hover {
+ transform: translateY(-1px);
+ box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
+ }
+ .oauth-button:disabled {
+ opacity: 0.6;
+ cursor: not-allowed;
+ transform: none;
+ box-shadow: none;
+ }
+ .oauth-button.disconnect {
+ background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
+ }
+ .oauth-status {
+ font-size: 12px;
+ margin-top: 5px;
+ padding: 5px 8px;
+ border-radius: 4px;
+ background: var(--color-background-highlight);
+ }
+ `;
+ document.head.appendChild(oauthStyles);
+
+ // Import OAuth service dynamically when needed
+ let OpenRouterOAuth: any = null;
+ const getOpenRouterOAuth = async () => {
+ if (!OpenRouterOAuth) {
+ const module = await import('../auth/OpenRouterOAuth.js');
+ OpenRouterOAuth = module.OpenRouterOAuth;
+ }
+ return OpenRouterOAuth;
+ };
+
+ // Update OAuth button state
+ const updateOAuthButton = async () => {
+ const OAuth = await getOpenRouterOAuth();
+ if (await OAuth.isOAuthAuthenticated()) {
+ oauthButton.textContent = 'Disconnect OpenRouter';
+ oauthButton.classList.add('disconnect');
+ oauthStatus.textContent = '✓ Connected via OpenRouter account';
+ oauthStatus.style.color = 'var(--color-accent-green)';
+ oauthStatus.style.display = 'block';
+ } else {
+ oauthButton.textContent = 'Connect with OpenRouter';
+ oauthButton.classList.remove('disconnect');
+ oauthStatus.style.display = 'none';
+ }
+ };
+
+ oauthButtonContainer.appendChild(oauthButton);
+ updateOAuthButton();
+
+ // OAuth button click handler
+ oauthButton.addEventListener('click', async () => {
+ const OAuth = await getOpenRouterOAuth();
+ oauthButton.disabled = true;
+
+ try {
+ if (await OAuth.isOAuthAuthenticated()) {
+ // Disconnect
+ if (confirm('Are you sure you want to disconnect your OpenRouter account?')) {
+ await OAuth.revokeToken();
+ updateOAuthButton();
+ }
+ } else {
+ // Connect - provide clear feedback for tab-based flow
+ oauthButton.textContent = 'Redirecting to OpenRouter...';
+ oauthStatus.textContent = 'You will be redirected to OpenRouter to authorize access. The page will return here automatically after authorization.';
+ oauthStatus.style.color = 'var(--color-text-secondary)';
+ oauthStatus.style.display = 'block';
+
+ await OAuth.startAuthFlow();
+ updateOAuthButton();
+ }
+ } catch (error) {
+ console.error('OAuth flow error:', error);
+ oauthStatus.textContent = `Error: ${error instanceof Error ? error.message : 'Unknown error'}`;
+ oauthStatus.style.color = 'var(--color-accent-red)';
+ oauthStatus.style.display = 'block';
+ } finally {
+ oauthButton.disabled = false;
+ if (!await OAuth.isOAuthAuthenticated()) {
+ oauthButton.textContent = 'Connect with OpenRouter';
+ oauthStatus.style.display = 'none';
+ }
+ }
+ });
+
+ // Handle OAuth events
+ const handleOAuthSuccess = () => {
+ updateOAuthButton();
+ oauthStatus.textContent = '✓ Successfully connected to OpenRouter';
+ oauthStatus.style.color = 'var(--color-accent-green)';
+ oauthStatus.style.display = 'block';
+
+ // Trigger chat panel refresh to recognize new credentials
+ const chatPanel = document.querySelector('ai-chat-panel') as any;
+ if (chatPanel && typeof chatPanel.refreshCredentials === 'function') {
+ chatPanel.refreshCredentials();
+ }
+
+ // Auto-save settings and close dialog after successful OAuth
+ onSettingsSaved(); // Notify parent that settings changed
+ setTimeout(() => {
+ dialog.hide(); // Close dialog after showing success message
+ }, 2000); // 2 seconds to show success message
+ };
+
+ const handleOAuthError = (event: Event) => {
+ const customEvent = event as CustomEvent;
+ oauthStatus.textContent = `Error: ${customEvent.detail.error}`;
+ oauthStatus.style.color = 'var(--color-accent-red)';
+ oauthStatus.style.display = 'block';
+ };
+
+ const handleOAuthLogout = () => {
+ // Clear the API key input field
+ openrouterApiKeyInput.value = '';
+
+ // Update OAuth button state
+ updateOAuthButton();
+
+ // Show logout confirmation
+ oauthStatus.textContent = '✓ Disconnected from OpenRouter';
+ oauthStatus.style.color = 'var(--color-text-secondary)';
+ oauthStatus.style.display = 'block';
+
+ // Refresh chat panel to recognize credential removal
+ const chatPanel = document.querySelector('ai-chat-panel') as any;
+ if (chatPanel && typeof chatPanel.refreshCredentials === 'function') {
+ chatPanel.refreshCredentials();
+ }
+
+ // Auto-close dialog after showing disconnect message
+ setTimeout(() => {
+ dialog.hide();
+ }, 2000); // 2 seconds to show disconnect message
+ };
+
+ window.addEventListener('openrouter-oauth-success', handleOAuthSuccess);
+ window.addEventListener('openrouter-oauth-error', handleOAuthError);
+ window.addEventListener('openrouter-oauth-logout', handleOAuthLogout);
+
+ // Update API key input behavior for OAuth compatibility
+ openrouterApiKeyInput.addEventListener('input', async () => {
+ if (openrouterApiKeyInput.value.trim()) {
+ // Switch to manual API key method
+ localStorage.setItem('openrouter_auth_method', 'api_key');
+ const OAuth = await getOpenRouterOAuth();
+ if (await OAuth.isOAuthAuthenticated()) {
+ OAuth.switchToManualApiKey();
+ }
+ }
+ });
+
+ // Fetch OpenRouter models button
+ const openrouterFetchButtonContainer = document.createElement('div');
+ openrouterFetchButtonContainer.className = 'fetch-button-container';
+ openrouterSettingsSection.appendChild(openrouterFetchButtonContainer);
+
+ const fetchOpenRouterModelsButton = document.createElement('button');
+ fetchOpenRouterModelsButton.className = 'settings-button';
+ fetchOpenRouterModelsButton.setAttribute('type', 'button');
+ fetchOpenRouterModelsButton.textContent = i18nString(UIStrings.fetchOpenRouterModelsButton);
+ fetchOpenRouterModelsButton.disabled = !openrouterApiKeyInput.value.trim();
+ openrouterFetchButtonContainer.appendChild(fetchOpenRouterModelsButton);
+
+ const fetchOpenRouterModelsStatus = document.createElement('div');
+ fetchOpenRouterModelsStatus.className = 'settings-status';
+ fetchOpenRouterModelsStatus.style.display = 'none';
+ openrouterFetchButtonContainer.appendChild(fetchOpenRouterModelsStatus);
+
+ // Update button state when API key changes
+ openrouterApiKeyInput.addEventListener('input', () => {
+ fetchOpenRouterModelsButton.disabled = !openrouterApiKeyInput.value.trim();
+ });
+
+ // Function to check cache age and auto-refresh OpenRouter models if stale
+ async function checkAndRefreshOpenRouterCache(): Promise {
+ try {
+ const cacheTimestamp = localStorage.getItem('openrouter_models_cache_timestamp');
+ const now = Date.now();
+
+ // If no timestamp, cache is considered stale
+ if (!cacheTimestamp) {
+ logger.debug('OpenRouter models cache has no timestamp, considering stale');
+ await autoRefreshOpenRouterModels();
+ return;
+ }
+
+ const cacheAge = now - parseInt(cacheTimestamp, 10);
+ const isStale = cacheAge > OPENROUTER_MODELS_CACHE_DURATION_MS;
+
+ if (isStale) {
+ const ageMinutes = Math.round(cacheAge / (1000 * 60));
+ logger.debug(`OpenRouter models cache is stale (${ageMinutes} minutes old), auto-refreshing...`);
+ await autoRefreshOpenRouterModels();
+ } else {
+ const remainingMinutes = Math.round((OPENROUTER_MODELS_CACHE_DURATION_MS - cacheAge) / (1000 * 60));
+ logger.debug(`OpenRouter models cache is fresh (expires in ${remainingMinutes} minutes)`);
+ }
+ } catch (error) {
+ logger.warn('Failed to check OpenRouter models cache age:', error);
+ }
+ }
- // Add evaluation configuration section
- const evaluationSection = document.createElement('div');
- evaluationSection.className = 'settings-section evaluation-section';
- contentDiv.appendChild(evaluationSection);
-
- const evaluationSectionTitle = document.createElement('h3');
- evaluationSectionTitle.className = 'settings-subtitle';
- evaluationSectionTitle.textContent = i18nString(UIStrings.evaluationSection);
- evaluationSection.appendChild(evaluationSectionTitle);
-
- // Get current evaluation configuration
- const currentEvaluationConfig = getEvaluationConfig();
-
- // Evaluation enabled checkbox
- const evaluationEnabledContainer = document.createElement('div');
- evaluationEnabledContainer.className = 'evaluation-enabled-container';
- evaluationSection.appendChild(evaluationEnabledContainer);
-
- const evaluationEnabledCheckbox = document.createElement('input');
- evaluationEnabledCheckbox.type = 'checkbox';
- evaluationEnabledCheckbox.id = 'evaluation-enabled';
- evaluationEnabledCheckbox.className = 'evaluation-checkbox';
- evaluationEnabledCheckbox.checked = isEvaluationEnabled();
- evaluationEnabledContainer.appendChild(evaluationEnabledCheckbox);
-
- const evaluationEnabledLabel = document.createElement('label');
- evaluationEnabledLabel.htmlFor = 'evaluation-enabled';
- evaluationEnabledLabel.className = 'evaluation-label';
- evaluationEnabledLabel.textContent = i18nString(UIStrings.evaluationEnabled);
- evaluationEnabledContainer.appendChild(evaluationEnabledLabel);
-
- const evaluationEnabledHint = document.createElement('div');
- evaluationEnabledHint.className = 'settings-hint';
- evaluationEnabledHint.textContent = i18nString(UIStrings.evaluationEnabledHint);
- evaluationSection.appendChild(evaluationEnabledHint);
-
- // Connection status indicator
- const connectionStatusContainer = document.createElement('div');
- connectionStatusContainer.className = 'connection-status-container';
- connectionStatusContainer.style.display = 'flex';
- connectionStatusContainer.style.alignItems = 'center';
- connectionStatusContainer.style.gap = '8px';
- connectionStatusContainer.style.marginTop = '8px';
- connectionStatusContainer.style.fontSize = '13px';
- evaluationSection.appendChild(connectionStatusContainer);
+ // Function to auto-refresh OpenRouter models silently
+ async function autoRefreshOpenRouterModels(): Promise {
+ try {
+ const openrouterApiKey = openrouterApiKeyInput.value.trim();
+
+ if (!openrouterApiKey) {
+ logger.debug('No OpenRouter API key available for auto-refresh');
+ return;
+ }
+
+ logger.debug('Auto-refreshing OpenRouter models...');
+ const openrouterModels = await LLMClient.fetchOpenRouterModels(openrouterApiKey);
+
+ // Convert OpenRouter models to ModelOption format
+ const modelOptions: ModelOption[] = openrouterModels.map(model => ({
+ value: model.id,
+ label: model.name || model.id,
+ type: 'openrouter' as const
+ }));
+
+ // Store in localStorage with timestamp
+ localStorage.setItem('openrouter_models_cache', JSON.stringify(modelOptions));
+ localStorage.setItem('openrouter_models_cache_timestamp', Date.now().toString());
+
+ // Also update global model options so UI immediately sees models
+ updateModelOptions(modelOptions, false);
+
+ logger.debug(`Auto-refreshed ${modelOptions.length} OpenRouter models`);
+ } catch (error) {
+ logger.warn('Failed to auto-refresh OpenRouter models:', error);
+ }
+ }
- const connectionStatusDot = document.createElement('div');
- connectionStatusDot.className = 'connection-status-dot';
- connectionStatusDot.style.width = '8px';
- connectionStatusDot.style.height = '8px';
- connectionStatusDot.style.borderRadius = '50%';
- connectionStatusDot.style.flexShrink = '0';
- connectionStatusContainer.appendChild(connectionStatusDot);
+ // Function to update OpenRouter model selectors
+ async function updateOpenRouterModelSelectors() {
+ logger.debug('Updating OpenRouter model selectors');
+
+ // Check if OpenRouter models cache is stale and auto-refresh if needed
+ await checkAndRefreshOpenRouterCache();
+
+ // Get the latest model options filtered for OpenRouter provider
+ const openrouterModels = getModelOptions('openrouter');
+ logger.debug('OpenRouter models from getModelOptions:', openrouterModels);
- const connectionStatusText = document.createElement('span');
- connectionStatusText.className = 'connection-status-text';
- connectionStatusContainer.appendChild(connectionStatusText);
+ // Get valid models using generic helper
+ const validMiniModel = getValidModelForProvider(miniModel, openrouterModels, 'openrouter', 'mini');
+ const validNanoModel = getValidModelForProvider(nanoModel, openrouterModels, 'openrouter', 'nano');
+
+ logger.debug('OpenRouter model selection:', { originalMini: miniModel, validMini: validMiniModel, originalNano: nanoModel, validNano: validNanoModel });
- // Function to update connection status
- const updateConnectionStatus = () => {
- const isConnected = isEvaluationConnected();
+ // Clear any existing model selectors
+ const existingSelectors = openrouterContent.querySelectorAll('.model-selection-section');
+ existingSelectors.forEach(selector => selector.remove());
- logger.debug('Updating connection status', { isConnected });
+ // Create a new model selection section
+ const openrouterModelSection = document.createElement('div');
+ openrouterModelSection.className = 'model-selection-section';
+ openrouterContent.appendChild(openrouterModelSection);
- if (isConnected) {
- connectionStatusDot.style.backgroundColor = 'var(--color-accent-green)';
- connectionStatusText.textContent = 'Connected to evaluation server';
- connectionStatusText.style.color = 'var(--color-accent-green)';
- } else {
- connectionStatusDot.style.backgroundColor = 'var(--color-text-disabled)';
- connectionStatusText.textContent = 'Not connected';
- connectionStatusText.style.color = 'var(--color-text-disabled)';
- }
- };
+ // Create Mini Model selection for OpenRouter and store reference
+ SettingsDialog.#openrouterMiniModelSelect = createModelSelector(
+ openrouterModelSection,
+ i18nString(UIStrings.miniModelLabel),
+ i18nString(UIStrings.miniModelDescription),
+ 'openrouter-mini-model-select',
+ openrouterModels,
+ validMiniModel,
+ i18nString(UIStrings.defaultMiniOption),
+ undefined // No focus handler needed for OpenRouter
+ );
+
+ // Create Nano Model selection for OpenRouter and store reference
+ SettingsDialog.#openrouterNanoModelSelect = createModelSelector(
+ openrouterModelSection,
+ i18nString(UIStrings.nanoModelLabel),
+ i18nString(UIStrings.nanoModelDescription),
+ 'openrouter-nano-model-select',
+ openrouterModels,
+ validNanoModel,
+ i18nString(UIStrings.defaultNanoOption),
+ undefined // No focus handler needed for OpenRouter
+ );
+ }
+
+ // Add click handler for fetch OpenRouter models button
+ fetchOpenRouterModelsButton.addEventListener('click', async () => {
+ fetchOpenRouterModelsButton.disabled = true;
+ fetchOpenRouterModelsStatus.textContent = i18nString(UIStrings.fetchingModels);
+ fetchOpenRouterModelsStatus.style.display = 'block';
+ fetchOpenRouterModelsStatus.style.backgroundColor = 'var(--color-accent-blue-background)';
+ fetchOpenRouterModelsStatus.style.color = 'var(--color-accent-blue)';
- // Update status initially and when evaluation is enabled/disabled
- updateConnectionStatus();
+ try {
+ const openrouterApiKey = openrouterApiKeyInput.value.trim();
+
+ // Fetch OpenRouter models using LLMClient static method
+ const openrouterModels = await LLMClient.fetchOpenRouterModels(openrouterApiKey);
+
+ // Convert OpenRouter models to ModelOption format
+ const modelOptions: ModelOption[] = openrouterModels.map(model => ({
+ value: model.id,
+ label: model.name || model.id,
+ type: 'openrouter' as const
+ }));
+
+ // Update model options with fetched OpenRouter models
+ updateModelOptions(modelOptions, false);
+
+ // Update timestamp for cache management
+ localStorage.setItem('openrouter_models_cache_timestamp', Date.now().toString());
+
+ const actualModelCount = openrouterModels.length;
+
+ // Update the model selectors with the new models
+ await updateOpenRouterModelSelectors();
+
+ // Update status to show success
+ fetchOpenRouterModelsStatus.textContent = i18nString(UIStrings.fetchedModels, {PH1: actualModelCount});
+ fetchOpenRouterModelsStatus.style.backgroundColor = 'var(--color-accent-green-background)';
+ fetchOpenRouterModelsStatus.style.color = 'var(--color-accent-green)';
+
+ logger.debug(`Successfully fetched ${actualModelCount} OpenRouter models`);
+ } catch (error) {
+ logger.error('Error fetching OpenRouter models:', error);
+ fetchOpenRouterModelsStatus.textContent = `Error: ${error instanceof Error ? error.message : 'Unknown error'}`;
+ fetchOpenRouterModelsStatus.style.backgroundColor = 'var(--color-accent-red-background)';
+ fetchOpenRouterModelsStatus.style.color = 'var(--color-accent-red)';
+ } finally {
+ fetchOpenRouterModelsButton.disabled = false;
+
+ // Hide status message after 3 seconds
+ setTimeout(() => {
+ fetchOpenRouterModelsStatus.style.display = 'none';
+ }, 3000);
+ }
+ });
+
+ // Initialize OpenRouter model selectors
+ await updateOpenRouterModelSelectors();
+
+ // Add Vector DB configuration section
+ const vectorDBSection = document.createElement('div');
+ vectorDBSection.className = 'settings-section vector-db-section';
+ contentDiv.appendChild(vectorDBSection);
- // Set up periodic status updates every 2 seconds
- const statusUpdateInterval = setInterval(updateConnectionStatus, 2000);
-
- // Evaluation configuration container (shown when enabled)
- const evaluationConfigContainer = document.createElement('div');
- evaluationConfigContainer.className = 'evaluation-config-container';
- evaluationConfigContainer.style.display = evaluationEnabledCheckbox.checked ? 'block' : 'none';
- evaluationSection.appendChild(evaluationConfigContainer);
-
- // Client ID display (read-only)
- const clientIdLabel = document.createElement('div');
- clientIdLabel.className = 'settings-label';
- clientIdLabel.textContent = 'Client ID';
- evaluationConfigContainer.appendChild(clientIdLabel);
-
- const clientIdHint = document.createElement('div');
- clientIdHint.className = 'settings-hint';
- clientIdHint.textContent = 'Unique identifier for this DevTools instance';
- evaluationConfigContainer.appendChild(clientIdHint);
-
- const clientIdInput = document.createElement('input');
- clientIdInput.type = 'text';
- clientIdInput.className = 'settings-input';
- clientIdInput.value = currentEvaluationConfig.clientId || 'Auto-generated on first connection';
- clientIdInput.readOnly = true;
- clientIdInput.style.backgroundColor = 'var(--color-background-elevation-1)';
- clientIdInput.style.cursor = 'default';
- evaluationConfigContainer.appendChild(clientIdInput);
-
- // Evaluation endpoint
- const evaluationEndpointLabel = document.createElement('div');
- evaluationEndpointLabel.className = 'settings-label';
- evaluationEndpointLabel.textContent = i18nString(UIStrings.evaluationEndpoint);
- evaluationConfigContainer.appendChild(evaluationEndpointLabel);
-
- const evaluationEndpointHint = document.createElement('div');
- evaluationEndpointHint.className = 'settings-hint';
- evaluationEndpointHint.textContent = i18nString(UIStrings.evaluationEndpointHint);
- evaluationConfigContainer.appendChild(evaluationEndpointHint);
+ const vectorDBTitle = document.createElement('h3');
+ vectorDBTitle.textContent = i18nString(UIStrings.vectorDBLabel);
+ vectorDBTitle.classList.add('settings-subtitle');
+ vectorDBSection.appendChild(vectorDBTitle);
+
+ // Vector DB enabled checkbox
+ const vectorDBEnabledContainer = document.createElement('div');
+ vectorDBEnabledContainer.className = 'tracing-enabled-container';
+ vectorDBSection.appendChild(vectorDBEnabledContainer);
- const evaluationEndpointInput = document.createElement('input');
- evaluationEndpointInput.type = 'text';
- evaluationEndpointInput.className = 'settings-input';
- evaluationEndpointInput.placeholder = 'ws://localhost:8080';
- evaluationEndpointInput.value = currentEvaluationConfig.endpoint || 'ws://localhost:8080';
- evaluationConfigContainer.appendChild(evaluationEndpointInput);
+ const vectorDBEnabledCheckbox = document.createElement('input');
+ vectorDBEnabledCheckbox.type = 'checkbox';
+ vectorDBEnabledCheckbox.id = 'vector-db-enabled';
+ vectorDBEnabledCheckbox.className = 'tracing-checkbox';
+ vectorDBEnabledCheckbox.checked = localStorage.getItem(VECTOR_DB_ENABLED_KEY) === 'true';
+ vectorDBEnabledContainer.appendChild(vectorDBEnabledCheckbox);
- // ---- MCP Integration Section ----
- const mcpSection = document.createElement('div');
- mcpSection.className = 'settings-section mcp-section';
- // Hide MCP UI: auto-connect is always on; settings are not user-configurable
- mcpSection.style.display = 'none';
- contentDiv.appendChild(mcpSection);
+ const vectorDBEnabledLabel = document.createElement('label');
+ vectorDBEnabledLabel.htmlFor = 'vector-db-enabled';
+ vectorDBEnabledLabel.className = 'tracing-label';
+ vectorDBEnabledLabel.textContent = i18nString(UIStrings.vectorDBEnabled);
+ vectorDBEnabledContainer.appendChild(vectorDBEnabledLabel);
- const mcpSectionTitle = document.createElement('h3');
- mcpSectionTitle.className = 'settings-subtitle';
- mcpSectionTitle.textContent = i18nString(UIStrings.mcpSection);
- mcpSection.appendChild(mcpSectionTitle);
+ const vectorDBEnabledHint = document.createElement('div');
+ vectorDBEnabledHint.className = 'settings-hint';
+ vectorDBEnabledHint.textContent = i18nString(UIStrings.vectorDBEnabledHint);
+ vectorDBSection.appendChild(vectorDBEnabledHint);
- // Current MCP config
- const currentMCPConfig = getMCPConfig();
+ // Vector DB configuration container (shown when enabled)
+ const vectorDBConfigContainer = document.createElement('div');
+ vectorDBConfigContainer.className = 'tracing-config-container';
+ vectorDBConfigContainer.style.display = vectorDBEnabledCheckbox.checked ? 'block' : 'none';
+ vectorDBSection.appendChild(vectorDBConfigContainer);
+
+ // Vector DB Endpoint
+ const vectorDBEndpointDiv = document.createElement('div');
+ vectorDBEndpointDiv.classList.add('settings-field');
+ vectorDBConfigContainer.appendChild(vectorDBEndpointDiv);
+
+ const vectorDBEndpointLabel = document.createElement('label');
+ vectorDBEndpointLabel.textContent = i18nString(UIStrings.vectorDBEndpoint);
+ vectorDBEndpointLabel.classList.add('settings-label');
+ vectorDBEndpointDiv.appendChild(vectorDBEndpointLabel);
+
+ const vectorDBEndpointHint = document.createElement('div');
+ vectorDBEndpointHint.textContent = i18nString(UIStrings.vectorDBEndpointHint);
+ vectorDBEndpointHint.classList.add('settings-hint');
+ vectorDBEndpointDiv.appendChild(vectorDBEndpointHint);
+
+ const vectorDBEndpointInput = document.createElement('input');
+ vectorDBEndpointInput.classList.add('settings-input');
+ vectorDBEndpointInput.type = 'text';
+ vectorDBEndpointInput.placeholder = 'http://localhost:19530';
+ vectorDBEndpointInput.value = localStorage.getItem(MILVUS_ENDPOINT_KEY) || '';
+ vectorDBEndpointDiv.appendChild(vectorDBEndpointInput);
+
+ // Vector DB API Key
+ const vectorDBApiKeyDiv = document.createElement('div');
+ vectorDBApiKeyDiv.classList.add('settings-field');
+ vectorDBConfigContainer.appendChild(vectorDBApiKeyDiv);
+
+ const vectorDBApiKeyLabel = document.createElement('label');
+ vectorDBApiKeyLabel.textContent = i18nString(UIStrings.vectorDBApiKey);
+ vectorDBApiKeyLabel.classList.add('settings-label');
+ vectorDBApiKeyDiv.appendChild(vectorDBApiKeyLabel);
+
+ const vectorDBApiKeyHint = document.createElement('div');
+ vectorDBApiKeyHint.textContent = i18nString(UIStrings.vectorDBApiKeyHint);
+ vectorDBApiKeyHint.classList.add('settings-hint');
+ vectorDBApiKeyDiv.appendChild(vectorDBApiKeyHint);
+
+ const vectorDBApiKeyInput = document.createElement('input');
+ vectorDBApiKeyInput.classList.add('settings-input');
+ vectorDBApiKeyInput.type = 'text';
+ vectorDBApiKeyInput.placeholder = 'root';
+ vectorDBApiKeyInput.value = localStorage.getItem(MILVUS_USERNAME_KEY) || 'root';
+ vectorDBApiKeyDiv.appendChild(vectorDBApiKeyInput);
+
+ // Milvus Password
+ const milvusPasswordDiv = document.createElement('div');
+ milvusPasswordDiv.classList.add('settings-field');
+ vectorDBConfigContainer.appendChild(milvusPasswordDiv);
+
+ const milvusPasswordLabel = document.createElement('label');
+ milvusPasswordLabel.textContent = i18nString(UIStrings.milvusPassword);
+ milvusPasswordLabel.classList.add('settings-label');
+ milvusPasswordDiv.appendChild(milvusPasswordLabel);
+
+ const milvusPasswordHint = document.createElement('div');
+ milvusPasswordHint.textContent = i18nString(UIStrings.milvusPasswordHint);
+ milvusPasswordHint.classList.add('settings-hint');
+ milvusPasswordDiv.appendChild(milvusPasswordHint);
+
+ const milvusPasswordInput = document.createElement('input');
+ milvusPasswordInput.classList.add('settings-input');
+ milvusPasswordInput.type = 'password';
+ milvusPasswordInput.placeholder = 'Milvus (self-hosted) or API token (cloud)';
+ milvusPasswordInput.value = localStorage.getItem(MILVUS_PASSWORD_KEY) || 'Milvus';
+ milvusPasswordDiv.appendChild(milvusPasswordInput);
+
+ // OpenAI API Key for embeddings
+ const milvusOpenAIDiv = document.createElement('div');
+ milvusOpenAIDiv.classList.add('settings-field');
+ vectorDBConfigContainer.appendChild(milvusOpenAIDiv);
+
+ const milvusOpenAILabel = document.createElement('label');
+ milvusOpenAILabel.textContent = i18nString(UIStrings.milvusOpenAIKey);
+ milvusOpenAILabel.classList.add('settings-label');
+ milvusOpenAIDiv.appendChild(milvusOpenAILabel);
+
+ const milvusOpenAIHint = document.createElement('div');
+ milvusOpenAIHint.textContent = i18nString(UIStrings.milvusOpenAIKeyHint);
+ milvusOpenAIHint.classList.add('settings-hint');
+ milvusOpenAIDiv.appendChild(milvusOpenAIHint);
+
+ const milvusOpenAIInput = document.createElement('input');
+ milvusOpenAIInput.classList.add('settings-input');
+ milvusOpenAIInput.type = 'password';
+ milvusOpenAIInput.placeholder = 'sk-...';
+ milvusOpenAIInput.value = localStorage.getItem(MILVUS_OPENAI_KEY) || '';
+ milvusOpenAIDiv.appendChild(milvusOpenAIInput);
+
+ // Vector DB Collection Name
+ const vectorDBCollectionDiv = document.createElement('div');
+ vectorDBCollectionDiv.classList.add('settings-field');
+ vectorDBConfigContainer.appendChild(vectorDBCollectionDiv);
+
+ const vectorDBCollectionLabel = document.createElement('label');
+ vectorDBCollectionLabel.textContent = i18nString(UIStrings.vectorDBCollection);
+ vectorDBCollectionLabel.classList.add('settings-label');
+ vectorDBCollectionDiv.appendChild(vectorDBCollectionLabel);
+
+ const vectorDBCollectionHint = document.createElement('div');
+ vectorDBCollectionHint.textContent = i18nString(UIStrings.vectorDBCollectionHint);
+ vectorDBCollectionHint.classList.add('settings-hint');
+ vectorDBCollectionDiv.appendChild(vectorDBCollectionHint);
+
+ const vectorDBCollectionInput = document.createElement('input');
+ vectorDBCollectionInput.classList.add('settings-input');
+ vectorDBCollectionInput.type = 'text';
+ vectorDBCollectionInput.placeholder = 'bookmarks';
+ vectorDBCollectionInput.value = localStorage.getItem(MILVUS_COLLECTION_KEY) || 'bookmarks';
+ vectorDBCollectionDiv.appendChild(vectorDBCollectionInput);
+
+ // Test Vector DB Connection Button
+ const vectorDBTestDiv = document.createElement('div');
+ vectorDBTestDiv.classList.add('settings-field', 'test-connection-field');
+ vectorDBConfigContainer.appendChild(vectorDBTestDiv);
+
+ const vectorDBTestButton = document.createElement('button');
+ vectorDBTestButton.classList.add('settings-button', 'test-button');
+ vectorDBTestButton.setAttribute('type', 'button');
+ vectorDBTestButton.textContent = i18nString(UIStrings.testVectorDBConnection);
+ vectorDBTestDiv.appendChild(vectorDBTestButton);
+
+ const vectorDBTestStatus = document.createElement('div');
+ vectorDBTestStatus.classList.add('settings-status');
+ vectorDBTestStatus.style.display = 'none';
+ vectorDBTestDiv.appendChild(vectorDBTestStatus);
+
+ // Toggle vector DB config visibility
+ vectorDBEnabledCheckbox.addEventListener('change', () => {
+ vectorDBConfigContainer.style.display = vectorDBEnabledCheckbox.checked ? 'block' : 'none';
+ localStorage.setItem(VECTOR_DB_ENABLED_KEY, vectorDBEnabledCheckbox.checked.toString());
+ });
+
+ // Save Vector DB settings on input change
+ const saveVectorDBSettings = () => {
+ localStorage.setItem(VECTOR_DB_ENABLED_KEY, vectorDBEnabledCheckbox.checked.toString());
+ localStorage.setItem(MILVUS_ENDPOINT_KEY, vectorDBEndpointInput.value);
+ localStorage.setItem(MILVUS_USERNAME_KEY, vectorDBApiKeyInput.value);
+ localStorage.setItem(MILVUS_PASSWORD_KEY, milvusPasswordInput.value);
+ localStorage.setItem(MILVUS_COLLECTION_KEY, vectorDBCollectionInput.value);
+ localStorage.setItem(MILVUS_OPENAI_KEY, milvusOpenAIInput.value);
+ };
+
+ vectorDBEndpointInput.addEventListener('input', saveVectorDBSettings);
+ vectorDBApiKeyInput.addEventListener('input', saveVectorDBSettings);
+ milvusPasswordInput.addEventListener('input', saveVectorDBSettings);
+ vectorDBCollectionInput.addEventListener('input', saveVectorDBSettings);
+ milvusOpenAIInput.addEventListener('input', saveVectorDBSettings);
+
+ // Test Vector DB connection
+ vectorDBTestButton.addEventListener('click', async () => {
+ const endpoint = vectorDBEndpointInput.value.trim();
+
+ if (!endpoint) {
+ vectorDBTestStatus.textContent = 'Please enter an endpoint URL';
+ vectorDBTestStatus.style.color = 'var(--color-accent-red)';
+ vectorDBTestStatus.style.display = 'block';
+ setTimeout(() => {
+ vectorDBTestStatus.style.display = 'none';
+ }, 3000);
+ return;
+ }
+
+ vectorDBTestButton.disabled = true;
+ vectorDBTestStatus.textContent = i18nString(UIStrings.testingVectorDBConnection);
+ vectorDBTestStatus.style.color = 'var(--color-text-secondary)';
+ vectorDBTestStatus.style.display = 'block';
+
+ try {
+ // Import and test the Vector DB client
+ const { VectorDBClient } = await import('../tools/VectorDBClient.js');
+ const vectorClient = new VectorDBClient({
+ endpoint,
+ username: vectorDBApiKeyInput.value || 'root',
+ password: milvusPasswordInput.value || 'Milvus',
+ collection: vectorDBCollectionInput.value || 'bookmarks',
+ openaiApiKey: milvusOpenAIInput.value || undefined
+ });
+
+ const testResult = await vectorClient.testConnection();
+
+ if (testResult.success) {
+ vectorDBTestStatus.textContent = i18nString(UIStrings.vectorDBConnectionSuccess);
+ vectorDBTestStatus.style.color = 'var(--color-accent-green)';
+ } else {
+ vectorDBTestStatus.textContent = `${i18nString(UIStrings.vectorDBConnectionFailed)}: ${testResult.error}`;
+ vectorDBTestStatus.style.color = 'var(--color-accent-red)';
+ }
+ } catch (error: any) {
+ vectorDBTestStatus.textContent = `${i18nString(UIStrings.vectorDBConnectionFailed)}: ${error.message}`;
+ vectorDBTestStatus.style.color = 'var(--color-accent-red)';
+ } finally {
+ vectorDBTestButton.disabled = false;
+ setTimeout(() => {
+ vectorDBTestStatus.style.display = 'none';
+ }, 5000);
+ }
+ });
+
+ // Add tracing configuration section
+ const tracingSection = document.createElement('div');
+ tracingSection.className = 'settings-section tracing-section';
+ contentDiv.appendChild(tracingSection);
- // Enable checkbox
- const mcpEnabledContainer = document.createElement('div');
- mcpEnabledContainer.className = 'mcp-enabled-container';
- mcpSection.appendChild(mcpEnabledContainer);
-
- const mcpEnabledCheckbox = document.createElement('input');
- mcpEnabledCheckbox.type = 'checkbox';
- mcpEnabledCheckbox.id = 'mcp-enabled';
- mcpEnabledCheckbox.className = 'mcp-checkbox';
- mcpEnabledCheckbox.checked = isMCPEnabled();
- mcpEnabledContainer.appendChild(mcpEnabledCheckbox);
-
- const mcpEnabledLabel = document.createElement('label');
- mcpEnabledLabel.htmlFor = 'mcp-enabled';
- mcpEnabledLabel.className = 'mcp-label';
- mcpEnabledLabel.textContent = i18nString(UIStrings.mcpEnabled);
- mcpEnabledContainer.appendChild(mcpEnabledLabel);
-
- const mcpEnabledHint = document.createElement('div');
- mcpEnabledHint.className = 'settings-hint';
- mcpEnabledHint.textContent = i18nString(UIStrings.mcpEnabledHint);
- mcpSection.appendChild(mcpEnabledHint);
+ const tracingSectionTitle = document.createElement('h3');
+ tracingSectionTitle.className = 'settings-subtitle';
+ tracingSectionTitle.textContent = i18nString(UIStrings.tracingSection);
+ tracingSection.appendChild(tracingSectionTitle);
- // Status indicator
- const mcpStatusContainer = document.createElement('div');
- mcpStatusContainer.className = 'connection-status-container';
- mcpStatusContainer.style.display = 'flex';
- mcpStatusContainer.style.alignItems = 'center';
- mcpStatusContainer.style.gap = '8px';
- mcpStatusContainer.style.marginTop = '8px';
- mcpStatusContainer.style.fontSize = '13px';
- mcpSection.appendChild(mcpStatusContainer);
+ // Get current tracing configuration
+ const currentTracingConfig = getTracingConfig();
- const mcpStatusDot = document.createElement('div');
- mcpStatusDot.className = 'connection-status-dot';
- mcpStatusDot.style.width = '8px';
- mcpStatusDot.style.height = '8px';
- mcpStatusDot.style.borderRadius = '50%';
- mcpStatusDot.style.flexShrink = '0';
- mcpStatusContainer.appendChild(mcpStatusDot);
+ // Tracing enabled checkbox
+ const tracingEnabledContainer = document.createElement('div');
+ tracingEnabledContainer.className = 'tracing-enabled-container';
+ tracingSection.appendChild(tracingEnabledContainer);
- const mcpStatusText = document.createElement('span');
- mcpStatusText.className = 'connection-status-text';
- mcpStatusContainer.appendChild(mcpStatusText);
+ const tracingEnabledCheckbox = document.createElement('input');
+ tracingEnabledCheckbox.type = 'checkbox';
+ tracingEnabledCheckbox.id = 'tracing-enabled';
+ tracingEnabledCheckbox.className = 'tracing-checkbox';
+ tracingEnabledCheckbox.checked = isTracingEnabled();
+ tracingEnabledContainer.appendChild(tracingEnabledCheckbox);
- const mcpStatusDetails = document.createElement('div');
- mcpStatusDetails.className = 'settings-hint';
- mcpStatusDetails.style.marginTop = '4px';
- mcpSection.appendChild(mcpStatusDetails);
+ const tracingEnabledLabel = document.createElement('label');
+ tracingEnabledLabel.htmlFor = 'tracing-enabled';
+ tracingEnabledLabel.className = 'tracing-label';
+ tracingEnabledLabel.textContent = i18nString(UIStrings.tracingEnabled);
+ tracingEnabledContainer.appendChild(tracingEnabledLabel);
- const formatTimestamp = (date: Date | undefined): string => {
- if (!date) return '';
- return date.toLocaleString();
- };
+ const tracingEnabledHint = document.createElement('div');
+ tracingEnabledHint.className = 'settings-hint';
+ tracingEnabledHint.textContent = i18nString(UIStrings.tracingEnabledHint);
+ tracingSection.appendChild(tracingEnabledHint);
- const formatMCPError = (error: string, errorType?: string): {message: string, hint?: string} => {
- if (!errorType) return {message: error};
- switch (errorType) {
- case 'connection':
- return {message: `Connection failed: ${error}`, hint: 'Check if the MCP server is running and the endpoint URL is correct.'};
- case 'authentication':
- return {message: `Authentication failed: ${error}`, hint: 'Verify your auth token is correct and has not expired.'};
- case 'configuration':
- return {message: `Configuration error: ${error}`, hint: 'Check your endpoint URL format (should be ws:// or wss://).'};
- case 'network':
- return {message: `Network error: ${error}`, hint: 'Check your internet connection and firewall settings.'};
- case 'server_error':
- return {message: `Server error: ${error}`, hint: 'The MCP server encountered an internal error. Contact the server administrator.'};
- default:
- return {message: error};
- }
- };
+ // Tracing configuration container (shown when enabled)
+ const tracingConfigContainer = document.createElement('div');
+ tracingConfigContainer.className = 'tracing-config-container';
+ tracingConfigContainer.style.display = tracingEnabledCheckbox.checked ? 'block' : 'none';
+ tracingSection.appendChild(tracingConfigContainer);
- const updateMCPStatus = () => {
- const status = MCPRegistry.getStatus();
- if (!status.enabled) {
- mcpStatusDot.style.backgroundColor = 'var(--color-text-disabled)';
- mcpStatusText.textContent = 'Disabled';
- mcpStatusText.style.color = 'var(--color-text-disabled)';
- mcpStatusDetails.textContent = '';
- return;
- }
- const anyConnected = status.servers.some(s => s.connected);
- const toolCount = status.registeredToolNames.length;
- if (anyConnected) {
- mcpStatusDot.style.backgroundColor = 'var(--color-accent-green)';
- mcpStatusText.textContent = `Connected (${toolCount} tools)`;
- mcpStatusText.style.color = 'var(--color-accent-green)';
-
- // Safely build details content without using innerHTML
- mcpStatusDetails.textContent = '';
- if (status.lastConnected) {
- const line = document.createElement('div');
- line.textContent = `Last connected: ${formatTimestamp(status.lastConnected)}`;
- mcpStatusDetails.appendChild(line);
- }
- if (status.lastError) {
- const {message, hint} = formatMCPError(status.lastError, status.lastErrorType);
- const errLine = document.createElement('div');
- const errSpan = document.createElement('span');
- errSpan.style.color = 'var(--color-error-text)';
- errSpan.textContent = message;
- errLine.appendChild(errSpan);
- mcpStatusDetails.appendChild(errLine);
- if (hint) {
- const hintLine = document.createElement('div');
- hintLine.style.color = 'var(--color-text-secondary)';
- hintLine.style.fontSize = '12px';
- hintLine.textContent = hint;
- mcpStatusDetails.appendChild(hintLine);
- }
- }
- } else {
- mcpStatusDot.style.backgroundColor = 'var(--color-text-disabled)';
- mcpStatusText.textContent = 'Not connected';
- mcpStatusText.style.color = 'var(--color-text-disabled)';
-
- // Safely build details content without using innerHTML
- mcpStatusDetails.textContent = '';
- if (status.lastDisconnected) {
- const line = document.createElement('div');
- line.textContent = `Last disconnected: ${formatTimestamp(status.lastDisconnected)}`;
- mcpStatusDetails.appendChild(line);
- }
- if (status.lastError) {
- const {message, hint} = formatMCPError(status.lastError, status.lastErrorType);
- const errLine = document.createElement('div');
- const errSpan = document.createElement('span');
- errSpan.style.color = 'var(--color-error-text)';
- errSpan.textContent = message;
- errLine.appendChild(errSpan);
- mcpStatusDetails.appendChild(errLine);
- if (hint) {
- const hintLine = document.createElement('div');
- hintLine.style.color = 'var(--color-text-secondary)';
- hintLine.style.fontSize = '12px';
- hintLine.textContent = hint;
- mcpStatusDetails.appendChild(hintLine);
- }
- }
- }
- };
- updateMCPStatus();
+ // Langfuse endpoint
+ const endpointLabel = document.createElement('div');
+ endpointLabel.className = 'settings-label';
+ endpointLabel.textContent = i18nString(UIStrings.langfuseEndpoint);
+ tracingConfigContainer.appendChild(endpointLabel);
- // Disconnect button (only shown when connected)
- const mcpDisconnectContainer = document.createElement('div');
- mcpDisconnectContainer.style.marginTop = '8px';
- mcpDisconnectContainer.style.marginBottom = '8px';
- mcpSection.appendChild(mcpDisconnectContainer);
+ const endpointHint = document.createElement('div');
+ endpointHint.className = 'settings-hint';
+ endpointHint.textContent = i18nString(UIStrings.langfuseEndpointHint);
+ tracingConfigContainer.appendChild(endpointHint);
- const mcpDisconnectButton = document.createElement('button');
- mcpDisconnectButton.textContent = 'Disconnect';
- mcpDisconnectButton.className = 'settings-button';
- mcpDisconnectButton.style.backgroundColor = 'var(--color-button-secondary)';
- mcpDisconnectButton.style.border = '1px solid var(--color-button-outline)';
- mcpDisconnectButton.style.color = 'var(--color-text-primary)';
- mcpDisconnectButton.style.padding = '4px 8px';
- mcpDisconnectButton.style.borderRadius = '3px';
- mcpDisconnectButton.style.cursor = 'pointer';
- mcpDisconnectButton.addEventListener('click', async () => {
- try {
- MCPRegistry.dispose();
- updateMCPStatus();
- updateDisconnectButton();
- updateToolsList();
- } catch (err) {
- console.error('Failed to disconnect MCP:', err);
- }
- });
- mcpDisconnectContainer.appendChild(mcpDisconnectButton);
+ const endpointInput = document.createElement('input');
+ endpointInput.className = 'settings-input';
+ endpointInput.type = 'text';
+ endpointInput.placeholder = 'http://localhost:3000';
+ endpointInput.value = currentTracingConfig.endpoint || 'http://localhost:3000';
+ tracingConfigContainer.appendChild(endpointInput);
- const updateDisconnectButton = () => {
- const status = MCPRegistry.getStatus();
- const anyConnected = status.enabled && status.servers.some(s => s.connected);
- mcpDisconnectContainer.style.display = anyConnected ? 'block' : 'none';
- };
- updateDisconnectButton();
+ // Langfuse public key
+ const publicKeyLabel = document.createElement('div');
+ publicKeyLabel.className = 'settings-label';
+ publicKeyLabel.textContent = i18nString(UIStrings.langfusePublicKey);
+ tracingConfigContainer.appendChild(publicKeyLabel);
- // MCP config inputs (visible when enabled)
- const mcpConfigContainer = document.createElement('div');
- mcpConfigContainer.className = 'mcp-config-container';
- mcpConfigContainer.style.display = mcpEnabledCheckbox.checked ? 'block' : 'none';
- mcpSection.appendChild(mcpConfigContainer);
+ const publicKeyHint = document.createElement('div');
+ publicKeyHint.className = 'settings-hint';
+ publicKeyHint.textContent = i18nString(UIStrings.langfusePublicKeyHint);
+ tracingConfigContainer.appendChild(publicKeyHint);
- // Endpoint
- const mcpEndpointLabel = document.createElement('div');
- mcpEndpointLabel.className = 'settings-label';
- mcpEndpointLabel.textContent = i18nString(UIStrings.mcpEndpoint);
- mcpConfigContainer.appendChild(mcpEndpointLabel);
-
- const mcpEndpointHint = document.createElement('div');
- mcpEndpointHint.className = 'settings-hint';
- mcpEndpointHint.textContent = i18nString(UIStrings.mcpEndpointHint);
- mcpConfigContainer.appendChild(mcpEndpointHint);
-
- const mcpEndpointInput = document.createElement('input');
- mcpEndpointInput.type = 'text';
- mcpEndpointInput.className = 'settings-input';
- mcpEndpointInput.placeholder = 'ws://localhost:9000';
- mcpEndpointInput.value = currentMCPConfig.endpoint || '';
- mcpConfigContainer.appendChild(mcpEndpointInput);
-
- // Token
- const mcpTokenLabel = document.createElement('div');
- mcpTokenLabel.className = 'settings-label';
- mcpTokenLabel.textContent = i18nString(UIStrings.mcpToken);
- mcpConfigContainer.appendChild(mcpTokenLabel);
-
- const mcpTokenHint = document.createElement('div');
- mcpTokenHint.className = 'settings-hint';
- mcpTokenHint.textContent = i18nString(UIStrings.mcpTokenHint);
- mcpConfigContainer.appendChild(mcpTokenHint);
-
- const mcpTokenInput = document.createElement('input');
- mcpTokenInput.type = 'password';
- mcpTokenInput.className = 'settings-input';
- mcpTokenInput.placeholder = 'Optional';
- mcpTokenInput.value = currentMCPConfig.token || '';
- mcpConfigContainer.appendChild(mcpTokenInput);
-
- // Connect/Refresh button
- const mcpConnectButton = document.createElement('button');
- mcpConnectButton.className = 'settings-button';
- mcpConnectButton.textContent = i18nString(UIStrings.mcpConnectRefresh);
- mcpConnectButton.addEventListener('click', async () => {
- // Save config then init/refresh
- setMCPConfig({
- enabled: mcpEnabledCheckbox.checked,
- endpoint: mcpEndpointInput.value.trim(),
- token: mcpTokenInput.value.trim() || undefined,
- });
- try {
- await MCPRegistry.init();
- await MCPRegistry.refresh();
- } catch (err) {
- logger.error('MCP connect/refresh failed', err);
- } finally {
- updateMCPStatus();
- updateDisconnectButton();
- updateToolsList();
- onSettingsSaved();
- }
- });
- mcpConfigContainer.appendChild(mcpConnectButton);
+ const publicKeyInput = document.createElement('input');
+ publicKeyInput.className = 'settings-input';
+ publicKeyInput.type = 'text';
+ publicKeyInput.placeholder = 'pk-lf-...';
+ publicKeyInput.value = currentTracingConfig.publicKey || '';
+ tracingConfigContainer.appendChild(publicKeyInput);
- // Autostart checkbox
- // Autostart UI removed: MCP auto-connect is always enabled by the panel
+ // Langfuse secret key
+ const secretKeyLabel = document.createElement('div');
+ secretKeyLabel.className = 'settings-label';
+ secretKeyLabel.textContent = i18nString(UIStrings.langfuseSecretKey);
+ tracingConfigContainer.appendChild(secretKeyLabel);
- // Tool mode selection
- const mcpToolModeLabel = document.createElement('div');
- mcpToolModeLabel.className = 'settings-label';
- mcpToolModeLabel.textContent = i18nString(UIStrings.mcpToolMode);
- mcpConfigContainer.appendChild(mcpToolModeLabel);
+ const secretKeyHint = document.createElement('div');
+ secretKeyHint.className = 'settings-hint';
+ secretKeyHint.textContent = i18nString(UIStrings.langfuseSecretKeyHint);
+ tracingConfigContainer.appendChild(secretKeyHint);
- const mcpToolModeHint = document.createElement('div');
- mcpToolModeHint.className = 'settings-hint';
- mcpToolModeHint.textContent = i18nString(UIStrings.mcpToolModeHint);
- mcpConfigContainer.appendChild(mcpToolModeHint);
+ const secretKeyInput = document.createElement('input');
+ secretKeyInput.className = 'settings-input';
+ secretKeyInput.type = 'password';
+ secretKeyInput.placeholder = 'sk-lf-...';
+ secretKeyInput.value = currentTracingConfig.secretKey || '';
+ tracingConfigContainer.appendChild(secretKeyInput);
- const mcpToolModeSelect = document.createElement('select');
- mcpToolModeSelect.className = 'settings-select';
- mcpConfigContainer.appendChild(mcpToolModeSelect);
+ // Test connection button
+ const testTracingButton = document.createElement('button');
+ testTracingButton.className = 'settings-button test-button';
+ testTracingButton.textContent = i18nString(UIStrings.testTracing);
+ tracingConfigContainer.appendChild(testTracingButton);
- // Tool mode options
- const toolModeOptions = [
- { value: 'all', text: i18nString(UIStrings.mcpToolModeAll) },
- { value: 'router', text: i18nString(UIStrings.mcpToolModeRouter) },
- { value: 'meta', text: i18nString(UIStrings.mcpToolModeMeta) },
- ];
+ // Test status message
+ const testTracingStatus = document.createElement('div');
+ testTracingStatus.className = 'settings-status';
+ testTracingStatus.style.display = 'none';
+ tracingConfigContainer.appendChild(testTracingStatus);
- toolModeOptions.forEach(option => {
- const optionElement = document.createElement('option');
- optionElement.value = option.value;
- optionElement.textContent = option.text;
- if ((currentMCPConfig.toolMode || 'router') === option.value) {
- optionElement.selected = true;
- }
- mcpToolModeSelect.appendChild(optionElement);
+ // Toggle tracing config visibility
+ tracingEnabledCheckbox.addEventListener('change', () => {
+ tracingConfigContainer.style.display = tracingEnabledCheckbox.checked ? 'block' : 'none';
});
- // Ensure the select reflects the currently stored mode even if options were appended later
- mcpToolModeSelect.value = (currentMCPConfig.toolMode || 'router');
+ // Test tracing connection
+ testTracingButton.addEventListener('click', async () => {
+ testTracingButton.disabled = true;
+ testTracingStatus.style.display = 'block';
+ testTracingStatus.textContent = 'Testing connection...';
+ testTracingStatus.style.backgroundColor = 'var(--color-background-elevation-1)';
+ testTracingStatus.style.color = 'var(--color-text-primary)';
- // Handle tool mode changes
- mcpToolModeSelect.addEventListener('change', () => {
- setMCPConfig({
- ...getMCPConfig(),
- toolMode: mcpToolModeSelect.value as 'all' | 'router' | 'meta',
- });
- onSettingsSaved();
- });
+ try {
+ const endpoint = endpointInput.value.trim();
+ const publicKey = publicKeyInput.value.trim();
+ const secretKey = secretKeyInput.value.trim();
- // Advanced budget controls
- const mcpMaxToolsLabel = document.createElement('div');
- mcpMaxToolsLabel.className = 'settings-label';
- mcpMaxToolsLabel.textContent = i18nString(UIStrings.mcpMaxToolsPerTurn);
- mcpConfigContainer.appendChild(mcpMaxToolsLabel);
+ if (!endpoint || !publicKey || !secretKey) {
+ throw new Error('All fields are required for testing');
+ }
- const mcpMaxToolsHint = document.createElement('div');
- mcpMaxToolsHint.className = 'settings-hint';
- mcpMaxToolsHint.textContent = i18nString(UIStrings.mcpMaxToolsPerTurnHint);
- mcpConfigContainer.appendChild(mcpMaxToolsHint);
+ // Test the connection with a simple trace
+ const testPayload = {
+ batch: [{
+ id: `test-${Date.now()}`,
+ timestamp: new Date().toISOString(),
+ type: 'trace-create',
+ body: {
+ id: `trace-test-${Date.now()}`,
+ name: 'Connection Test',
+ timestamp: new Date().toISOString()
+ }
+ }]
+ };
- const mcpMaxToolsInput = document.createElement('input');
- mcpMaxToolsInput.type = 'number';
- mcpMaxToolsInput.className = 'settings-input';
- mcpMaxToolsInput.min = '1';
- mcpMaxToolsInput.max = '100';
- mcpMaxToolsInput.value = String(currentMCPConfig.maxToolsPerTurn || 20);
- mcpConfigContainer.appendChild(mcpMaxToolsInput);
+ const response = await fetch(`${endpoint}/api/public/ingestion`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Basic ' + btoa(`${publicKey}:${secretKey}`)
+ },
+ body: JSON.stringify(testPayload)
+ });
- const mcpMaxMcpLabel = document.createElement('div');
- mcpMaxMcpLabel.className = 'settings-label';
- mcpMaxMcpLabel.textContent = i18nString(UIStrings.mcpMaxMcpPerTurn);
- mcpConfigContainer.appendChild(mcpMaxMcpLabel);
+ if (response.ok) {
+ testTracingStatus.textContent = '✓ Connection successful';
+ testTracingStatus.style.backgroundColor = 'var(--color-accent-green-background)';
+ testTracingStatus.style.color = 'var(--color-accent-green)';
+ } else {
+ const errorText = await response.text();
+ throw new Error(`HTTP ${response.status}: ${errorText}`);
+ }
+ } catch (error) {
+ testTracingStatus.textContent = `✗ ${error instanceof Error ? error.message : 'Connection failed'}`;
+ testTracingStatus.style.backgroundColor = 'var(--color-accent-red-background)';
+ testTracingStatus.style.color = 'var(--color-accent-red)';
+ } finally {
+ testTracingButton.disabled = false;
+ setTimeout(() => {
+ testTracingStatus.style.display = 'none';
+ }, 5000);
+ }
+ });
- const mcpMaxMcpHint = document.createElement('div');
- mcpMaxMcpHint.className = 'settings-hint';
- mcpMaxMcpHint.textContent = i18nString(UIStrings.mcpMaxMcpPerTurnHint);
- mcpConfigContainer.appendChild(mcpMaxMcpHint);
+ // Add evaluation configuration section
+ const evaluationSection = document.createElement('div');
+ evaluationSection.className = 'settings-section evaluation-section';
+ contentDiv.appendChild(evaluationSection);
- const mcpMaxMcpInput = document.createElement('input');
- mcpMaxMcpInput.type = 'number';
- mcpMaxMcpInput.className = 'settings-input';
- mcpMaxMcpInput.min = '1';
- mcpMaxMcpInput.max = '50';
- mcpMaxMcpInput.value = String(currentMCPConfig.maxMcpPerTurn || 8);
- mcpConfigContainer.appendChild(mcpMaxMcpInput);
+ const evaluationSectionTitle = document.createElement('h3');
+ evaluationSectionTitle.className = 'settings-subtitle';
+ evaluationSectionTitle.textContent = i18nString(UIStrings.evaluationSection);
+ evaluationSection.appendChild(evaluationSectionTitle);
- // Handle budget control changes
- const updateBudgetControls = () => {
- const maxTools = Math.max(1, Math.min(100, parseInt(mcpMaxToolsInput.value, 10) || 20));
- const maxMcp = Math.max(1, Math.min(50, parseInt(mcpMaxMcpInput.value, 10) || 8));
- setMCPConfig({
- ...getMCPConfig(),
- maxToolsPerTurn: maxTools,
- maxMcpPerTurn: maxMcp,
- });
- onSettingsSaved();
- };
+ // Get current evaluation configuration
+ const currentEvaluationConfig = getEvaluationConfig();
- mcpMaxToolsInput.addEventListener('change', updateBudgetControls);
- mcpMaxMcpInput.addEventListener('change', updateBudgetControls);
+ // Evaluation enabled checkbox
+ const evaluationEnabledContainer = document.createElement('div');
+ evaluationEnabledContainer.className = 'evaluation-enabled-container';
+ evaluationSection.appendChild(evaluationEnabledContainer);
+
+ const evaluationEnabledCheckbox = document.createElement('input');
+ evaluationEnabledCheckbox.type = 'checkbox';
+ evaluationEnabledCheckbox.id = 'evaluation-enabled';
+ evaluationEnabledCheckbox.className = 'evaluation-checkbox';
+ evaluationEnabledCheckbox.checked = isEvaluationEnabled();
+ evaluationEnabledContainer.appendChild(evaluationEnabledCheckbox);
+
+ const evaluationEnabledLabel = document.createElement('label');
+ evaluationEnabledLabel.htmlFor = 'evaluation-enabled';
+ evaluationEnabledLabel.className = 'evaluation-label';
+ evaluationEnabledLabel.textContent = i18nString(UIStrings.evaluationEnabled);
+ evaluationEnabledContainer.appendChild(evaluationEnabledLabel);
- // Tool management UI
- const mcpToolsSection = document.createElement('div');
- mcpToolsSection.className = 'mcp-tools-section';
- mcpConfigContainer.appendChild(mcpToolsSection);
+ const evaluationEnabledHint = document.createElement('div');
+ evaluationEnabledHint.className = 'settings-hint';
+ evaluationEnabledHint.textContent = i18nString(UIStrings.evaluationEnabledHint);
+ evaluationSection.appendChild(evaluationEnabledHint);
- const mcpToolsLabel = document.createElement('div');
- mcpToolsLabel.className = 'settings-label';
- mcpToolsLabel.textContent = i18nString(UIStrings.mcpDiscoveredTools);
- mcpToolsSection.appendChild(mcpToolsLabel);
+ // Connection status indicator
+ const connectionStatusContainer = document.createElement('div');
+ connectionStatusContainer.className = 'connection-status-container';
+ connectionStatusContainer.style.display = 'flex';
+ connectionStatusContainer.style.alignItems = 'center';
+ connectionStatusContainer.style.gap = '8px';
+ connectionStatusContainer.style.marginTop = '8px';
+ connectionStatusContainer.style.fontSize = '13px';
+ evaluationSection.appendChild(connectionStatusContainer);
- const mcpToolsHint = document.createElement('div');
- mcpToolsHint.className = 'settings-hint';
- mcpToolsHint.textContent = i18nString(UIStrings.mcpDiscoveredToolsHint);
- mcpToolsSection.appendChild(mcpToolsHint);
+ const connectionStatusDot = document.createElement('div');
+ connectionStatusDot.className = 'connection-status-dot';
+ connectionStatusDot.style.width = '8px';
+ connectionStatusDot.style.height = '8px';
+ connectionStatusDot.style.borderRadius = '50%';
+ connectionStatusDot.style.flexShrink = '0';
+ connectionStatusContainer.appendChild(connectionStatusDot);
- const mcpToolsList = document.createElement('div');
- mcpToolsList.className = 'mcp-tools-list';
- mcpToolsSection.appendChild(mcpToolsList);
+ const connectionStatusText = document.createElement('span');
+ connectionStatusText.className = 'connection-status-text';
+ connectionStatusContainer.appendChild(connectionStatusText);
- const updateToolsList = () => {
- const status = MCPRegistry.getStatus();
- mcpToolsList.innerHTML = '';
+ // Function to update connection status
+ const updateConnectionStatus = () => {
+ const isConnected = isEvaluationConnected();
- if (!status.enabled || status.registeredToolNames.length === 0) {
- const noToolsMessage = document.createElement('div');
- noToolsMessage.className = 'mcp-no-tools';
- noToolsMessage.textContent = i18nString(UIStrings.mcpNoTools);
- mcpToolsList.appendChild(noToolsMessage);
- return;
+ logger.debug('Updating connection status', { isConnected });
+
+ if (isConnected) {
+ connectionStatusDot.style.backgroundColor = 'var(--color-accent-green)';
+ connectionStatusText.textContent = 'Connected to evaluation server';
+ connectionStatusText.style.color = 'var(--color-accent-green)';
+ } else {
+ connectionStatusDot.style.backgroundColor = 'var(--color-text-disabled)';
+ connectionStatusText.textContent = 'Not connected';
+ connectionStatusText.style.color = 'var(--color-text-disabled)';
}
+ };
- const currentAllowlist = new Set(currentMCPConfig.toolAllowlist || []);
+ // Update status initially and when evaluation is enabled/disabled
+ updateConnectionStatus();
+
+ // Set up periodic status updates every 2 seconds
+ const statusUpdateInterval = setInterval(updateConnectionStatus, 2000);
- status.registeredToolNames.forEach(toolName => {
- const toolItem = document.createElement('div');
- toolItem.className = 'mcp-tool-item';
+ // Evaluation configuration container (shown when enabled)
+ const evaluationConfigContainer = document.createElement('div');
+ evaluationConfigContainer.className = 'evaluation-config-container';
+ evaluationConfigContainer.style.display = evaluationEnabledCheckbox.checked ? 'block' : 'none';
+ evaluationSection.appendChild(evaluationConfigContainer);
- const toolCheckbox = document.createElement('input');
- toolCheckbox.type = 'checkbox';
- toolCheckbox.id = `mcp-tool-${toolName.replace(/[^a-zA-Z0-9]/g, '-')}`;
- toolCheckbox.className = 'mcp-tool-checkbox';
- toolCheckbox.checked = currentAllowlist.size === 0 || currentAllowlist.has(toolName);
- toolItem.appendChild(toolCheckbox);
+ // Client ID display (read-only)
+ const clientIdLabel = document.createElement('div');
+ clientIdLabel.className = 'settings-label';
+ clientIdLabel.textContent = 'Client ID';
+ evaluationConfigContainer.appendChild(clientIdLabel);
- const toolLabel = document.createElement('label');
- toolLabel.htmlFor = toolCheckbox.id;
- toolLabel.className = 'mcp-tool-label';
- toolLabel.textContent = toolName.replace(/^mcp:[^:]+:/, ''); // Remove namespace prefix
- toolItem.appendChild(toolLabel);
+ const clientIdHint = document.createElement('div');
+ clientIdHint.className = 'settings-hint';
+ clientIdHint.textContent = 'Unique identifier for this DevTools instance';
+ evaluationConfigContainer.appendChild(clientIdHint);
- // Update allowlist when checkbox changes
- toolCheckbox.addEventListener('change', () => {
- const currentConfig = getMCPConfig();
- const allowlist = new Set(currentConfig.toolAllowlist || []);
-
- if (toolCheckbox.checked) {
- allowlist.add(toolName);
- } else {
- allowlist.delete(toolName);
- }
+ const clientIdInput = document.createElement('input');
+ clientIdInput.type = 'text';
+ clientIdInput.className = 'settings-input';
+ clientIdInput.value = currentEvaluationConfig.clientId || 'Auto-generated on first connection';
+ clientIdInput.readOnly = true;
+ clientIdInput.style.backgroundColor = 'var(--color-background-elevation-1)';
+ clientIdInput.style.cursor = 'default';
+ evaluationConfigContainer.appendChild(clientIdInput);
- setMCPConfig({
- ...currentConfig,
- toolAllowlist: Array.from(allowlist),
- });
- });
+ // Evaluation endpoint
+ const evaluationEndpointLabel = document.createElement('div');
+ evaluationEndpointLabel.className = 'settings-label';
+ evaluationEndpointLabel.textContent = i18nString(UIStrings.evaluationEndpoint);
+ evaluationConfigContainer.appendChild(evaluationEndpointLabel);
- mcpToolsList.appendChild(toolItem);
- });
- };
+ const evaluationEndpointHint = document.createElement('div');
+ evaluationEndpointHint.className = 'settings-hint';
+ evaluationEndpointHint.textContent = i18nString(UIStrings.evaluationEndpointHint);
+ evaluationConfigContainer.appendChild(evaluationEndpointHint);
- // Initial tools list update
- updateToolsList();
+ const evaluationEndpointInput = document.createElement('input');
+ evaluationEndpointInput.type = 'text';
+ evaluationEndpointInput.className = 'settings-input';
+ evaluationEndpointInput.placeholder = 'ws://localhost:8080';
+ evaluationEndpointInput.value = currentEvaluationConfig.endpoint || 'ws://localhost:8080';
+ evaluationConfigContainer.appendChild(evaluationEndpointInput);
- // Autostart is deprecated; always auto-connect is handled by the UI layer
- // Toggle visibility on enable/disable
- mcpEnabledCheckbox.addEventListener('change', async () => {
- setMCPConfig({
- enabled: mcpEnabledCheckbox.checked,
- endpoint: mcpEndpointInput.value.trim(),
- token: mcpTokenInput.value.trim() || undefined,
- });
- mcpConfigContainer.style.display = mcpEnabledCheckbox.checked ? 'block' : 'none';
- try {
- await MCPRegistry.init();
- await MCPRegistry.refresh();
- } catch (err) {
- logger.error('MCP toggle failed', err);
- } finally {
- updateMCPStatus();
- updateDisconnectButton();
- updateToolsList();
- onSettingsSaved();
- }
- });
// Evaluation secret key
const evaluationSecretKeyLabel = document.createElement('div');
@@ -3271,9 +3399,7 @@ export class SettingsDialog {
vectorDBSection.style.display = display;
tracingSection.style.display = display;
evaluationSection.style.display = display;
- const mcpSectionEl = contentDiv.querySelector('.mcp-section') as HTMLElement | null;
- if (mcpSectionEl) { mcpSectionEl.style.display = display; }
-
+
// Save state to localStorage
localStorage.setItem(ADVANCED_SETTINGS_ENABLED_KEY, show.toString());
}
@@ -3807,6 +3933,11 @@ export class SettingsDialog {
padding: 16px 20px;
border-bottom: 1px solid var(--color-details-hairline);
}
+
+ @keyframes spin {
+ from { transform: rotate(0deg); }
+ to { transform: rotate(360deg); }
+ }
`;
dialog.contentElement.appendChild(styleElement);
diff --git a/front_end/panels/ai_chat/ui/AIChatPanel.test.ts b/front_end/panels/ai_chat/ui/__tests__/AIChatPanel.test.ts
similarity index 95%
rename from front_end/panels/ai_chat/ui/AIChatPanel.test.ts
rename to front_end/panels/ai_chat/ui/__tests__/AIChatPanel.test.ts
index 58a5a54defc..bf5942c4aa2 100644
--- a/front_end/panels/ai_chat/ui/AIChatPanel.test.ts
+++ b/front_end/panels/ai_chat/ui/__tests__/AIChatPanel.test.ts
@@ -2,24 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import {AIChatPanel, DEFAULT_PROVIDER_MODELS, type ModelOption, resetAIChatPanelInstanceForTesting} from './AIChatPanel.js';
-import {LLMProviderRegistry} from '../LLM/LLMProviderRegistry.js';
-import {AgentService} from '../core/AgentService.js';
-import {Events as AgentEvents} from '../core/AgentService.js';
-import {ChatMessageEntity} from '../models/ChatTypes.js';
-import {raf} from '../../testing/DOMHelpers.js';
-
-declare global {
- function describe(name: string, fn: () => void): void;
- function it(name: string, fn: () => void): void;
- function beforeEach(fn: () => void): void;
- function afterEach(fn: () => void): void;
- namespace assert {
- function strictEqual(actual: unknown, expected: unknown): void;
- function deepEqual(actual: unknown, expected: unknown): void;
- function isNull(value: unknown): void;
- }
-}
+import {AIChatPanel, DEFAULT_PROVIDER_MODELS, type ModelOption, resetAIChatPanelInstanceForTesting} from '../AIChatPanel.js';
+import {LLMProviderRegistry} from '../../LLM/LLMProviderRegistry.js';
+import {AgentService} from '../../core/AgentService.js';
+import {Events as AgentEvents} from '../../core/AgentService.js';
+import {ChatMessageEntity} from '../../models/ChatTypes.js';
+import {raf} from '../../../../testing/DOMHelpers.js';
+
describe('AIChatPanel Model Validation', () => {
let panel: AIChatPanel;
diff --git a/front_end/panels/ai_chat/ui/chatView.css b/front_end/panels/ai_chat/ui/chatView.css
index 91cf88de371..6271d838299 100644
--- a/front_end/panels/ai_chat/ui/chatView.css
+++ b/front_end/panels/ai_chat/ui/chatView.css
@@ -128,6 +128,50 @@ ai-input-bar {
top: -40px; /* Move content slightly up for better visual centering */
}
+/* Example suggestions (chips) in centered view */
+.examples-container {
+ margin: 8px 0 16px 0;
+ padding: 0 8px;
+ width: 100%;
+ max-width: 720px;
+}
+
+.examples-title {
+ font-size: 12px;
+ color: var(--color-text-secondary);
+ margin: 8px 0;
+ text-align: center;
+}
+
+.examples-list {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+ justify-content: center;
+}
+
+.example-chip {
+ padding: 6px 10px;
+ border-radius: 16px;
+ border: 1px solid var(--color-details-hairline);
+ background: var(--color-background-elevation-1);
+ color: var(--color-text-primary);
+ cursor: pointer;
+ font-size: 12px;
+ transition: background-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
+}
+
+.example-chip:hover {
+ background: var(--color-background-elevation-2);
+ transform: translateY(-1px);
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
+ border-color: var(--color-primary-container-border);
+}
+
+.example-chip:active {
+ transform: translateY(0);
+}
+
@keyframes fadeInScale {
from { opacity: 0; transform: scale(0.9); }
to { opacity: 1; transform: scale(1); }
diff --git a/front_end/panels/ai_chat/ui/input/InputBar.ts b/front_end/panels/ai_chat/ui/input/InputBar.ts
index 993d3dfd6b6..cc68cb70fc5 100644
--- a/front_end/panels/ai_chat/ui/input/InputBar.ts
+++ b/front_end/panels/ai_chat/ui/input/InputBar.ts
@@ -41,6 +41,21 @@ export class InputBar extends HTMLElement {
connectedCallback(): void { this.#render(); }
+ // Public API to set the input value programmatically (e.g., from example suggestions)
+ setInputValue(text: string): void {
+ const inputEl = this.querySelector('ai-chat-input') as (HTMLElement & { value?: string, focusInput?: () => void }) | null;
+ if (inputEl) {
+ // Set value via property setter to update the UI
+ (inputEl as any).value = text ?? '';
+ // Focus textarea for immediate editing
+ if (typeof (inputEl as any).focusInput === 'function') {
+ (inputEl as any).focusInput();
+ }
+ // Bubble an inputchange event so parent updates sendDisabled state
+ this.dispatchEvent(new CustomEvent('inputchange', { bubbles: true, detail: { value: text ?? '' } }));
+ }
+ }
+
#emitSendAndClear(detail: any): void {
// Re-emit send upward
this.dispatchEvent(new CustomEvent('send', { bubbles: true, detail }));
diff --git a/front_end/panels/ai_chat/ui/mcp/MCPConnectionsDialog.ts b/front_end/panels/ai_chat/ui/mcp/MCPConnectionsDialog.ts
new file mode 100644
index 00000000000..6156b80683c
--- /dev/null
+++ b/front_end/panels/ai_chat/ui/mcp/MCPConnectionsDialog.ts
@@ -0,0 +1,712 @@
+import * as i18n from '../../../../core/i18n/i18n.js';
+import * as UI from '../../../../ui/legacy/legacy.js';
+import { createLogger } from '../../core/Logger.js';
+import { getMCPProviders, saveMCPProviders, type MCPProviderConfig } from '../../mcp/MCPConfig.js';
+
+const logger = createLogger('MCPConnectionsDialog');
+
+const UIStrings = {
+ title: 'Manage MCP connections',
+ description: 'Configure MCP servers that DevTools can connect to. You can add multiple endpoints and toggle them individually.',
+ addConnection: 'Add connection',
+ saveButton: 'Save connections',
+ cancelButton: 'Cancel',
+ namePlaceholder: 'Display name (optional)',
+ endpointPlaceholder: 'https://your-server/mcp or ws://localhost:9000',
+ authTypeLabel: 'Auth',
+ authTypeOAuth: 'OAuth (PKCE)',
+ authTypeBearer: 'Bearer token',
+ bearerTokenPlaceholder: 'Token (only for bearer)',
+ enabledLabel: 'Enabled',
+ removeButton: 'Remove',
+ validationEndpointRequired: 'Every connection needs an endpoint URL.',
+ validationDuplicateEndpoint: 'Duplicate endpoints detected. Please ensure each connection is unique.',
+ emptyState: 'No MCP connections yet. Add one to get started.',
+};
+
+const str_ = i18n.i18n.registerUIStrings('panels/ai_chat/ui/mcp/MCPConnectionsDialog.ts', UIStrings);
+const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
+
+interface MCPConnectionsDialogOptions {
+ onSave?: () => void | Promise;
+}
+
+export class MCPConnectionsDialog {
+ static show(options: MCPConnectionsDialogOptions = {}): void {
+ const dialog = new MCPConnectionsDialog(options);
+ dialog.show();
+ }
+
+ #dialog: UI.Dialog.Dialog;
+ #options: MCPConnectionsDialogOptions;
+ #providers: MCPProviderConfig[] = [];
+ #listElement!: HTMLElement;
+ #errorElement!: HTMLElement;
+
+ constructor(options: MCPConnectionsDialogOptions) {
+ this.#options = options;
+ this.#dialog = new UI.Dialog.Dialog();
+ this.#providers = getMCPProviders().map(provider => ({ ...provider }));
+ }
+
+ show(): void {
+ this.#dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.MEASURE_CONTENT);
+ this.#dialog.setDimmed(true);
+ this.#dialog.setOutsideClickCallback(() => this.close());
+
+ const content = this.#dialog.contentElement;
+ content.classList.add('mcp-connections-dialog');
+ content.style.display = 'flex';
+ content.style.flexDirection = 'column';
+
+ const styleElement = document.createElement('style');
+ styleElement.textContent = `
+ .mcp-connections-dialog {
+ min-width: 640px;
+ max-width: 90vw;
+ color: var(--color-text-primary);
+ background: var(--color-background);
+ border-radius: 12px;
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 4px 16px rgba(0, 0, 0, 0.08);
+ overflow: hidden;
+ border: 1px solid var(--color-details-hairline);
+ }
+ .mcp-connections-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px 24px;
+ border-bottom: 1px solid var(--color-details-hairline);
+ background: var(--color-background-elevation-1);
+ }
+ .mcp-connections-title {
+ font-size: 18px;
+ font-weight: 600;
+ margin: 0;
+ color: var(--color-text-primary);
+ }
+ .mcp-connections-close {
+ background: none;
+ border: none;
+ cursor: pointer;
+ font-size: 20px;
+ padding: 8px;
+ color: var(--color-text-secondary);
+ border-radius: 6px;
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 32px;
+ height: 32px;
+ }
+ .mcp-connections-close:hover {
+ color: var(--color-text-primary);
+ background: var(--color-background-elevation-2);
+ }
+ .mcp-connections-close:active {
+ transform: scale(0.95);
+ }
+ .mcp-connections-body {
+ padding: 20px 24px 16px;
+ display: flex;
+ flex-direction: column;
+ gap: 16px;
+ height: 65vh;
+ overflow: hidden;
+ }
+ .mcp-connections-description {
+ font-size: 14px;
+ color: var(--color-text-secondary);
+ line-height: 1.4;
+ margin: 0;
+ flex-shrink: 0;
+ }
+ .mcp-connections-scroll-container {
+ flex: 1;
+ overflow-y: auto;
+ margin: 0 -4px;
+ padding: 0 4px;
+ min-height: 200px;
+ }
+ .mcp-connections-list {
+ display: flex;
+ flex-direction: column;
+ gap: 16px;
+ padding-bottom: 8px;
+ }
+ .mcp-connections-actions {
+ flex-shrink: 0;
+ padding-top: 8px;
+ border-top: 1px solid var(--color-details-hairline);
+ }
+ .mcp-connection-card {
+ border: 1px solid var(--color-details-hairline);
+ border-radius: 12px;
+ padding: 20px;
+ display: flex;
+ flex-direction: column;
+ gap: 16px;
+ background: var(--color-background-elevation-1);
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ position: relative;
+ }
+ .mcp-connection-card:hover {
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
+ border-color: var(--color-primary-container-border);
+ }
+ .mcp-connection-row {
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 16px;
+ width: 100%;
+ }
+ .mcp-field {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ }
+ .mcp-field label {
+ font-size: 12px;
+ font-weight: 500;
+ color: var(--color-text-secondary);
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ }
+ .mcp-field input,
+ .mcp-field select {
+ width: 100%;
+ padding: 10px 12px;
+ font-size: 14px;
+ box-sizing: border-box;
+ border: 1px solid var(--color-details-hairline);
+ border-radius: 8px;
+ background: var(--color-background);
+ color: var(--color-text-primary);
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ }
+ .mcp-field select {
+ padding-right: 32px;
+ appearance: none;
+ -webkit-appearance: none;
+ -moz-appearance: none;
+ cursor: pointer;
+ background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
+ background-repeat: no-repeat;
+ background-position: right 8px center;
+ background-size: 16px;
+ }
+ .mcp-field input:focus,
+ .mcp-field select:focus {
+ outline: none;
+ border-color: var(--color-primary);
+ box-shadow: 0 0 0 3px var(--color-primary-shadow);
+ }
+ .mcp-field input:hover,
+ .mcp-field select:hover {
+ border-color: var(--color-primary-container-border);
+ }
+ .mcp-field input::placeholder {
+ color: var(--color-text-secondary);
+ opacity: 0.7;
+ }
+ .mcp-field.token-field,
+ .mcp-field.endpoint-field {
+ grid-column: span 2;
+ }
+ .mcp-connection-actions {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-top: 8px;
+ }
+ .mcp-remove-button {
+ background: none;
+ border: none;
+ color: var(--color-error-text);
+ cursor: pointer;
+ padding: 8px 12px;
+ border-radius: 6px;
+ font-size: 13px;
+ font-weight: 500;
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ }
+ .mcp-remove-button:hover {
+ background: var(--color-error-container);
+ color: var(--sys-color-error);
+ }
+ .mcp-enabled-toggle {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ font-size: 14px;
+ cursor: pointer;
+ user-select: none;
+ }
+ .mcp-toggle-switch {
+ position: relative;
+ width: 44px;
+ height: 24px;
+ background: var(--color-details-hairline);
+ border-radius: 12px;
+ transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ cursor: pointer;
+ }
+ .mcp-toggle-switch.checked {
+ background: var(--color-primary);
+ }
+ .mcp-toggle-slider {
+ position: absolute;
+ top: 2px;
+ left: 2px;
+ width: 20px;
+ height: 20px;
+ background: white;
+ border-radius: 50%;
+ transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
+ }
+ .mcp-toggle-switch.checked .mcp-toggle-slider {
+ transform: translateX(20px);
+ }
+ .mcp-toggle-switch:hover {
+ opacity: 0.8;
+ }
+ .mcp-connections-footer {
+ display: flex;
+ justify-content: flex-end;
+ gap: 12px;
+ padding: 16px 24px 20px;
+ border-top: 1px solid var(--color-details-hairline);
+ background: var(--color-background-elevation-1);
+ }
+ .mcp-primary-button {
+ padding: 10px 20px;
+ background: var(--color-primary);
+ color: var(--color-text-inverted);
+ border: 1px solid var(--color-primary);
+ border-radius: 8px;
+ cursor: pointer;
+ font-size: 14px;
+ font-weight: 500;
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ box-shadow: 0 2px 4px var(--color-primary-shadow);
+ }
+ .mcp-primary-button:hover {
+ background: var(--color-primary-variant);
+ border-color: var(--color-primary-variant);
+ transform: translateY(-1px);
+ box-shadow: 0 4px 8px var(--color-primary-shadow);
+ }
+ .mcp-primary-button:active {
+ transform: translateY(0);
+ box-shadow: 0 1px 2px var(--color-primary-shadow);
+ }
+ .mcp-secondary-button {
+ padding: 10px 20px;
+ border: 1px solid var(--color-details-hairline);
+ background: var(--color-background);
+ color: var(--color-text-primary);
+ border-radius: 8px;
+ cursor: pointer;
+ font-size: 14px;
+ font-weight: 500;
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ }
+ .mcp-secondary-button:hover {
+ background: var(--color-background-elevation-1);
+ border-color: var(--color-primary-container-border);
+ }
+ .mcp-secondary-button:active {
+ transform: scale(0.98);
+ }
+ .mcp-error-banner {
+ display: none;
+ padding: 12px 16px;
+ border-radius: 8px;
+ background: var(--color-error-container);
+ color: var(--sys-color-error);
+ font-size: 14px;
+ border: 1px solid rgba(var(--sys-color-error-rgb), 0.2);
+ margin-bottom: 8px;
+ animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1);
+ }
+ .mcp-empty-state {
+ font-size: 14px;
+ color: var(--color-text-secondary);
+ font-style: italic;
+ text-align: center;
+ padding: 60px 20px;
+ background: var(--color-background-elevation-1);
+ border-radius: 12px;
+ border: 2px dashed var(--color-details-hairline);
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 12px;
+ }
+ .mcp-empty-state::before {
+ content: "🔗";
+ font-size: 32px;
+ opacity: 0.6;
+ }
+ .mcp-password-field {
+ position: relative;
+ }
+ .mcp-password-toggle {
+ position: absolute;
+ right: 8px;
+ top: 50%;
+ transform: translateY(-50%);
+ background: none;
+ border: none;
+ cursor: pointer;
+ padding: 4px;
+ color: var(--color-text-secondary);
+ border-radius: 4px;
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
+ }
+ .mcp-password-toggle:hover {
+ color: var(--color-text-primary);
+ background: var(--color-background-elevation-1);
+ }
+ .mcp-add-connection-button {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ justify-content: center;
+ }
+ .mcp-add-connection-button::before {
+ content: "+";
+ font-size: 18px;
+ font-weight: bold;
+ }
+ @keyframes slideDown {
+ from {
+ opacity: 0;
+ transform: translateY(-10px);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0);
+ }
+ }
+ .mcp-connections-scroll-container::-webkit-scrollbar {
+ width: 8px;
+ }
+ .mcp-connections-scroll-container::-webkit-scrollbar-track {
+ background: var(--color-background-elevation-1);
+ border-radius: 4px;
+ }
+ .mcp-connections-scroll-container::-webkit-scrollbar-thumb {
+ background: var(--color-details-hairline);
+ border-radius: 4px;
+ }
+ .mcp-connections-scroll-container::-webkit-scrollbar-thumb:hover {
+ background: var(--color-text-secondary);
+ }
+ `;
+ content.appendChild(styleElement);
+
+ const header = document.createElement('div');
+ header.className = 'mcp-connections-header';
+ content.appendChild(header);
+
+ const title = document.createElement('h2');
+ title.className = 'mcp-connections-title';
+ title.textContent = i18nString(UIStrings.title);
+ header.appendChild(title);
+
+ const closeButton = document.createElement('button');
+ closeButton.className = 'mcp-connections-close';
+ closeButton.textContent = '×';
+ closeButton.addEventListener('click', () => this.close());
+ header.appendChild(closeButton);
+
+ const body = document.createElement('div');
+ body.className = 'mcp-connections-body';
+ content.appendChild(body);
+
+ const description = document.createElement('div');
+ description.className = 'mcp-connections-description';
+ description.textContent = i18nString(UIStrings.description);
+ body.appendChild(description);
+
+ this.#errorElement = document.createElement('div');
+ this.#errorElement.className = 'mcp-error-banner';
+ body.appendChild(this.#errorElement);
+
+ const scrollContainer = document.createElement('div');
+ scrollContainer.className = 'mcp-connections-scroll-container';
+ body.appendChild(scrollContainer);
+
+ this.#listElement = document.createElement('div');
+ this.#listElement.className = 'mcp-connections-list';
+ scrollContainer.appendChild(this.#listElement);
+
+ const actionsContainer = document.createElement('div');
+ actionsContainer.className = 'mcp-connections-actions';
+ body.appendChild(actionsContainer);
+
+ const addButton = document.createElement('button');
+ addButton.className = 'mcp-secondary-button mcp-add-connection-button';
+ addButton.textContent = i18nString(UIStrings.addConnection);
+ addButton.addEventListener('click', () => {
+ this.#providers.push({
+ id: '',
+ name: '',
+ endpoint: '',
+ authType: 'oauth',
+ enabled: true,
+ });
+ this.renderList();
+ // Auto-scroll to bottom after adding new connection
+ setTimeout(() => {
+ scrollContainer.scrollTop = scrollContainer.scrollHeight;
+ }, 100);
+ });
+ actionsContainer.appendChild(addButton);
+
+ this.renderList();
+
+ const footer = document.createElement('div');
+ footer.className = 'mcp-connections-footer';
+ content.appendChild(footer);
+
+ const cancelButton = document.createElement('button');
+ cancelButton.className = 'mcp-secondary-button';
+ cancelButton.textContent = i18nString(UIStrings.cancelButton);
+ cancelButton.addEventListener('click', () => this.close());
+ footer.appendChild(cancelButton);
+
+ const saveButton = document.createElement('button');
+ saveButton.className = 'mcp-primary-button';
+ saveButton.textContent = i18nString(UIStrings.saveButton);
+ saveButton.addEventListener('click', () => this.handleSave());
+ footer.appendChild(saveButton);
+
+ this.#dialog.show();
+ }
+
+ private renderList(): void {
+ this.#listElement.textContent = '';
+ this.#errorElement.style.display = 'none';
+
+ if (this.#providers.length === 0) {
+ const emptyState = document.createElement('div');
+ emptyState.className = 'mcp-empty-state';
+ emptyState.textContent = i18nString(UIStrings.emptyState);
+ this.#listElement.appendChild(emptyState);
+ return;
+ }
+
+ this.#providers.forEach((provider, index) => {
+ const card = document.createElement('div');
+ card.className = 'mcp-connection-card';
+
+ const row = document.createElement('div');
+ row.className = 'mcp-connection-row';
+
+ const nameField = document.createElement('div');
+ nameField.className = 'mcp-field mcp-field--short';
+ const nameLabel = document.createElement('label');
+ nameLabel.textContent = 'Name';
+ const nameInput = document.createElement('input');
+ nameInput.type = 'text';
+ nameInput.placeholder = i18nString(UIStrings.namePlaceholder);
+ nameInput.value = provider.name || '';
+ nameInput.addEventListener('input', () => {
+ provider.name = nameInput.value.trim() || undefined;
+ });
+ nameField.appendChild(nameLabel);
+ nameField.appendChild(nameInput);
+ row.appendChild(nameField);
+
+ const endpointField = document.createElement('div');
+ endpointField.className = 'mcp-field mcp-field--long';
+ const endpointLabel = document.createElement('label');
+ endpointLabel.textContent = 'Endpoint';
+ const endpointInput = document.createElement('input');
+ endpointInput.type = 'text';
+ endpointInput.placeholder = i18nString(UIStrings.endpointPlaceholder);
+ endpointInput.value = provider.endpoint;
+ endpointInput.addEventListener('input', () => {
+ provider.endpoint = endpointInput.value.trim();
+ });
+ endpointField.appendChild(endpointLabel);
+ endpointField.appendChild(endpointInput);
+ row.appendChild(endpointField);
+
+ const authField = document.createElement('div');
+ authField.className = 'mcp-field';
+ const authLabel = document.createElement('label');
+ authLabel.textContent = i18nString(UIStrings.authTypeLabel);
+ const authSelect = document.createElement('select');
+ const oauthOption = document.createElement('option');
+ oauthOption.value = 'oauth';
+ oauthOption.textContent = i18nString(UIStrings.authTypeOAuth);
+ const bearerOption = document.createElement('option');
+ bearerOption.value = 'bearer';
+ bearerOption.textContent = i18nString(UIStrings.authTypeBearer);
+ authSelect.appendChild(oauthOption);
+ authSelect.appendChild(bearerOption);
+ authSelect.value = provider.authType;
+ authField.appendChild(authLabel);
+ authField.appendChild(authSelect);
+ row.appendChild(authField);
+
+ const tokenField = document.createElement('div');
+ tokenField.className = 'mcp-field token-field';
+ const tokenLabel = document.createElement('label');
+ tokenLabel.textContent = 'Token';
+
+ const tokenInputContainer = document.createElement('div');
+ tokenInputContainer.className = 'mcp-password-field';
+
+ const tokenInput = document.createElement('input');
+ tokenInput.type = 'password';
+ tokenInput.placeholder = i18nString(UIStrings.bearerTokenPlaceholder);
+ tokenInput.value = provider.token || '';
+ tokenInput.style.paddingRight = '36px';
+
+ const toggleButton = document.createElement('button');
+ toggleButton.className = 'mcp-password-toggle';
+ toggleButton.type = 'button';
+ toggleButton.innerHTML = '👁️';
+ toggleButton.title = 'Show/hide token';
+
+ toggleButton.addEventListener('click', () => {
+ if (tokenInput.type === 'password') {
+ tokenInput.type = 'text';
+ toggleButton.innerHTML = '🙈';
+ } else {
+ tokenInput.type = 'password';
+ toggleButton.innerHTML = '👁️';
+ }
+ });
+
+ tokenField.style.display = provider.authType === 'bearer' ? 'flex' : 'none';
+ tokenInput.addEventListener('input', () => {
+ provider.token = tokenInput.value.trim() || undefined;
+ });
+
+ tokenInputContainer.appendChild(tokenInput);
+ tokenInputContainer.appendChild(toggleButton);
+ tokenField.appendChild(tokenLabel);
+ tokenField.appendChild(tokenInputContainer);
+ row.appendChild(tokenField);
+
+ authSelect.addEventListener('change', () => {
+ provider.authType = authSelect.value === 'bearer' ? 'bearer' : 'oauth';
+ tokenField.style.display = provider.authType === 'bearer' ? 'flex' : 'none';
+ if (provider.authType !== 'bearer') {
+ provider.token = undefined;
+ tokenInput.value = '';
+ }
+ });
+
+ const enabledField = document.createElement('div');
+ enabledField.className = 'mcp-field';
+ const enabledToggle = document.createElement('label');
+ enabledToggle.className = 'mcp-enabled-toggle';
+
+ const toggleSwitch = document.createElement('div');
+ toggleSwitch.className = 'mcp-toggle-switch';
+ if (provider.enabled !== false) {
+ toggleSwitch.classList.add('checked');
+ }
+
+ const toggleSlider = document.createElement('div');
+ toggleSlider.className = 'mcp-toggle-slider';
+ toggleSwitch.appendChild(toggleSlider);
+
+ const hiddenCheckbox = document.createElement('input');
+ hiddenCheckbox.type = 'checkbox';
+ hiddenCheckbox.checked = provider.enabled !== false;
+ hiddenCheckbox.style.display = 'none';
+
+ toggleSwitch.addEventListener('click', () => {
+ const isChecked = !hiddenCheckbox.checked;
+ hiddenCheckbox.checked = isChecked;
+ provider.enabled = isChecked;
+ if (isChecked) {
+ toggleSwitch.classList.add('checked');
+ } else {
+ toggleSwitch.classList.remove('checked');
+ }
+ });
+
+ const enabledText = document.createElement('span');
+ enabledText.textContent = i18nString(UIStrings.enabledLabel);
+
+ enabledToggle.appendChild(toggleSwitch);
+ enabledToggle.appendChild(hiddenCheckbox);
+ enabledToggle.appendChild(enabledText);
+ enabledField.appendChild(enabledToggle);
+ row.appendChild(enabledField);
+
+ card.appendChild(row);
+
+ const actions = document.createElement('div');
+ actions.className = 'mcp-connection-actions';
+ const spacer = document.createElement('div');
+ actions.appendChild(spacer);
+
+ const removeButton = document.createElement('button');
+ removeButton.className = 'mcp-remove-button';
+ removeButton.textContent = i18nString(UIStrings.removeButton);
+ removeButton.addEventListener('click', () => {
+ this.#providers.splice(index, 1);
+ this.renderList();
+ });
+ actions.appendChild(removeButton);
+
+ card.appendChild(actions);
+ this.#listElement.appendChild(card);
+ });
+ }
+
+ private async handleSave(): Promise {
+ this.#errorElement.style.display = 'none';
+ const trimmedProviders = this.#providers.map(provider => ({
+ ...provider,
+ endpoint: provider.endpoint.trim(),
+ }));
+
+ if (trimmedProviders.some(provider => !provider.endpoint)) {
+ this.showError(i18nString(UIStrings.validationEndpointRequired));
+ return;
+ }
+
+ const endpoints = new Set();
+ for (const provider of trimmedProviders) {
+ const key = `${provider.endpoint}|${provider.authType}`;
+ if (endpoints.has(key)) {
+ this.showError(i18nString(UIStrings.validationDuplicateEndpoint));
+ return;
+ }
+ endpoints.add(key);
+ }
+
+ try {
+ saveMCPProviders(trimmedProviders);
+ if (this.#options.onSave) {
+ await this.#options.onSave();
+ }
+ this.close();
+ } catch (error) {
+ logger.error('Failed to save MCP connections', error);
+ this.showError(error instanceof Error ? error.message : String(error));
+ }
+ }
+
+ private showError(message: string): void {
+ this.#errorElement.textContent = message;
+ this.#errorElement.style.display = 'block';
+ }
+
+ private close(): void {
+ this.#dialog.hide();
+ }
+}
diff --git a/front_end/panels/ai_chat/ui/mcp/MCPConnectorsCatalogDialog.ts b/front_end/panels/ai_chat/ui/mcp/MCPConnectorsCatalogDialog.ts
new file mode 100644
index 00000000000..2fdb23b95d8
--- /dev/null
+++ b/front_end/panels/ai_chat/ui/mcp/MCPConnectorsCatalogDialog.ts
@@ -0,0 +1,1024 @@
+import * as i18n from '../../../../core/i18n/i18n.js';
+import * as UI from '../../../../ui/legacy/legacy.js';
+import * as Snackbars from '../../../../ui/components/snackbars/snackbars.js';
+import { createLogger } from '../../core/Logger.js';
+import { MCPRegistry, type ConnectionResult } from '../../mcp/MCPRegistry.js';
+import { getMCPProviders, saveMCPProviders, type MCPProviderConfig } from '../../mcp/MCPConfig.js';
+import { MCPConnectionsDialog } from './MCPConnectionsDialog.js';
+
+import mcpConnectorsCatalogDialogStyles from './mcpConnectorsCatalogDialog.css.js';
+
+const logger = createLogger('MCPConnectorsCatalogDialog');
+
+const LOGO_URLS = {
+ sentry: '/bundled/Images/sentry-mcp.svg',
+ atlassian: '/bundled/Images/atlassian-mcp.svg',
+ linear: '/bundled/Images/linear-mcp.svg',
+ notion: '/bundled/Images/notion-mcp.svg',
+ slack: '/bundled/Images/slack-mcp.svg',
+ github: '/bundled/Images/github-mcp.svg',
+ asana: '/bundled/Images/asana-mcp.svg',
+ intercom: '/bundled/Images/intercom-mcp.svg',
+ 'google-drive': '/bundled/Images/google-drive-mcp.svg',
+ huggingface: '/bundled/Images/huggingface-mcp.svg',
+ 'google-sheets': '/bundled/Images/google-sheets-mcp.svg',
+ socket: '/bundled/Images/socket-mcp.svg',
+ invideo: '/bundled/Images/invideo-mcp.svg',
+} as const;
+
+type MCPConnectorLogoId = keyof typeof LOGO_URLS;
+
+const UIStrings = {
+ title: 'MCP Connectors',
+ description: 'Connect to external services and tools to enhance your AI assistant capabilities.',
+ searchPlaceholder: 'Search connectors...',
+ connectionsStatus: '{PH1} of {PH2} connected',
+ addButton: 'Add',
+ added: 'Added!',
+ closeButton: 'Close',
+ manageConnectionsButton: 'Manage connections',
+ manageConnectionsAction: 'Manage',
+ successMessage: 'Added {PH1} connector.',
+ alreadyExists: 'This connector is already configured.',
+ connecting: 'Connecting',
+ oauthInProgress: 'Complete the {PH1} sign-in in the opened tab.',
+ connectionFailed: 'Unable to add {PH1}. Please try again.',
+ connectionFailedWithReason: 'Unable to add {PH1}: {PH2}',
+ connectionError: 'Connection failed',
+ viewDetails: 'View Details',
+ hideDetails: 'Hide Details',
+ errorTypeAuthentication: 'Authentication Required',
+ errorTypeConfiguration: 'Configuration Error',
+ errorTypeNetwork: 'Network Error',
+ errorTypeServerError: 'Server Error',
+ errorTypeConnection: 'Connection Error',
+ errorTypeUnknown: 'Unknown Error',
+ connected: 'Connected',
+ retry: 'Retry',
+ clearError: 'Clear',
+ noResultsFound: 'No connectors found',
+ expand: 'Expand',
+ collapse: 'Collapse',
+};
+
+const str_ = i18n.i18n.registerUIStrings('panels/ai_chat/ui/mcp/MCPConnectorsCatalogDialog.ts', UIStrings);
+const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
+
+interface MCPConnector {
+ id: string;
+ name: string;
+ description: string;
+ logo?: MCPConnectorLogoId;
+ endpoint: string;
+ authType: 'oauth' | 'bearer';
+ category: string;
+}
+
+const MCP_CONNECTORS: MCPConnector[] = [
+ {
+ id: 'invideo',
+ name: 'invideo',
+ description: 'Build video creation capabilities into your applications',
+ logo: 'invideo',
+ endpoint: 'https://mcp.invideo.io/sse',
+ authType: 'oauth',
+ category: 'Media'
+ },
+ // {
+ // id: 'monday',
+ // name: 'Monday',
+ // description: 'Manage monday.com boards by creating items, updating columns, assigning owners, setting timelines, adding CRM activities, and writing summaries',
+ // logo: 'socket', // fallback generic icon
+ // endpoint: 'https://mcp.monday.com/sse',
+ // authType: 'oauth',
+ // category: 'Project Management'
+ // },
+ // ...existing connectors...
+ {
+ id: 'sentry',
+ name: 'Sentry',
+ description: 'Error monitoring & debugging production issues',
+ logo: 'sentry',
+ endpoint: 'https://mcp.sentry.dev/mcp',
+ authType: 'oauth',
+ category: 'Development'
+ },
+ {
+ id: 'linear',
+ name: 'Linear',
+ description: 'Issue tracking & project management',
+ logo: 'linear',
+ endpoint: 'https://mcp.linear.app/mcp',
+ authType: 'oauth',
+ category: 'Project Management'
+ },
+ {
+ id: 'notion',
+ name: 'Notion',
+ description: 'Documentation & knowledge management',
+ logo: 'notion',
+ endpoint: 'https://mcp.notion.com/mcp',
+ authType: 'oauth',
+ category: 'Documentation'
+ },
+ {
+ id: 'intercom',
+ name: 'Intercom',
+ description: 'Customer support & conversations',
+ logo: 'intercom',
+ endpoint: 'https://mcp.intercom.com/mcp',
+ authType: 'oauth',
+ category: 'Communication'
+ },
+ {
+ id: 'huggingface',
+ name: 'Hugging Face',
+ description: 'AI models & machine learning hub',
+ logo: 'huggingface',
+ endpoint: 'https://huggingface.co/mcp',
+ authType: 'oauth',
+ category: 'AI/ML'
+ },
+ {
+ id: 'canva',
+ name: 'Canva',
+ description: 'Browse, summarize, autofill, and even generate new Canva designs directly from Claude',
+ endpoint: 'https://mcp.canva.com/mcp',
+ authType: 'oauth',
+ category: 'Design'
+ },
+ {
+ id: 'jam',
+ name: 'Jam',
+ description: 'Debug faster with AI agents that can access Jam recordings like video, console logs, network requests, and errors',
+ endpoint: 'https://mcp.jam.dev/mcp',
+ authType: 'oauth',
+ category: 'Debugging'
+ },
+];
+
+interface MCPConnectorsCatalogDialogOptions {
+ onClose?: () => void;
+}
+
+export class MCPConnectorsCatalogDialog {
+ static show(options: MCPConnectorsCatalogDialogOptions = {}): void {
+ const dialog = new MCPConnectorsCatalogDialog(options);
+ dialog.show();
+ }
+
+ #dialog: UI.Dialog.Dialog;
+ #options: MCPConnectorsCatalogDialogOptions;
+ #existingProviders: MCPProviderConfig[] = [];
+ #searchQuery = '';
+ #collapsedCategories = new Set();
+ #connectorsContainer: HTMLElement | null = null;
+ #statusElement: HTMLElement | null = null;
+ #connectionErrors = new Map();
+ #connectingConnectorId: string | null = null;
+ #errorResetTimeouts = new Map();
+
+ constructor(options: MCPConnectorsCatalogDialogOptions) {
+ this.#options = options;
+ this.#dialog = new UI.Dialog.Dialog();
+ this.#existingProviders = getMCPProviders();
+ }
+
+ show(): void {
+ this.#dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.MEASURE_CONTENT);
+ this.#dialog.setDimmed(true);
+ this.#dialog.setOutsideClickCallback(() => this.close());
+
+ const content = this.#dialog.contentElement;
+ content.classList.add('mcp-connectors-catalog-dialog');
+ content.style.display = 'flex';
+ content.style.flexDirection = 'column';
+
+ const styleElement = document.createElement('style');
+ styleElement.textContent = mcpConnectorsCatalogDialogStyles;
+ content.appendChild(styleElement);
+
+ const header = document.createElement('div');
+ header.className = 'mcp-catalog-header';
+ content.appendChild(header);
+
+ const title = document.createElement('h2');
+ title.className = 'mcp-catalog-title';
+ title.textContent = i18nString(UIStrings.title);
+ header.appendChild(title);
+
+ const closeButton = document.createElement('button');
+ closeButton.className = 'mcp-catalog-close';
+ closeButton.textContent = '×';
+ closeButton.addEventListener('click', () => this.close());
+ header.appendChild(closeButton);
+
+ // Search section
+ const searchSection = document.createElement('div');
+ searchSection.className = 'mcp-catalog-search-section';
+ content.appendChild(searchSection);
+
+ const searchInput = document.createElement('input');
+ searchInput.className = 'mcp-catalog-search-input';
+ searchInput.type = 'text';
+ searchInput.placeholder = i18nString(UIStrings.searchPlaceholder);
+ searchInput.addEventListener('input', (e) => {
+ this.#searchQuery = (e.target as HTMLInputElement).value.toLowerCase();
+ this.renderConnectors();
+ });
+ searchSection.appendChild(searchInput);
+
+ // Status section
+ const statusSection = document.createElement('div');
+ statusSection.className = 'mcp-catalog-status';
+ content.appendChild(statusSection);
+
+ const statusText = document.createElement('span');
+ statusText.className = 'mcp-catalog-status-count';
+ this.#statusElement = statusText;
+ this.updateConnectionStatus();
+ statusSection.appendChild(statusText);
+
+ const description = document.createElement('span');
+ description.textContent = i18nString(UIStrings.description);
+ statusSection.appendChild(description);
+
+ const body = document.createElement('div');
+ body.className = 'mcp-catalog-body';
+ content.appendChild(body);
+ this.#connectorsContainer = body;
+
+ this.renderConnectors();
+
+ const footer = document.createElement('div');
+ footer.className = 'mcp-catalog-footer';
+ content.appendChild(footer);
+
+ const manageButton = document.createElement('button');
+ manageButton.className = 'mcp-manage-button';
+ manageButton.textContent = i18nString(UIStrings.manageConnectionsButton);
+ manageButton.addEventListener('click', () => this.#openManageConnections());
+ footer.appendChild(manageButton);
+
+ const footerCloseButton = document.createElement('button');
+ footerCloseButton.className = 'mcp-close-button';
+ footerCloseButton.textContent = i18nString(UIStrings.closeButton);
+ footerCloseButton.addEventListener('click', () => this.close());
+ footer.appendChild(footerCloseButton);
+
+ this.#dialog.show();
+ }
+
+ private renderConnectors(): void {
+ if (!this.#connectorsContainer) {
+ return;
+ }
+
+ this.#connectorsContainer.innerHTML = '';
+
+ // Filter connectors based on search
+ const filteredConnectors = MCP_CONNECTORS.filter(connector => {
+ if (!this.#searchQuery) return true;
+ return connector.name.toLowerCase().includes(this.#searchQuery) ||
+ connector.description.toLowerCase().includes(this.#searchQuery) ||
+ connector.category.toLowerCase().includes(this.#searchQuery);
+ });
+
+ if (filteredConnectors.length === 0) {
+ const noResults = document.createElement('div');
+ noResults.className = 'mcp-no-results';
+ noResults.textContent = i18nString(UIStrings.noResultsFound);
+ this.#connectorsContainer.appendChild(noResults);
+ return;
+ }
+
+ // Group connectors by category
+ const categorizedConnectors = filteredConnectors.reduce((acc, connector) => {
+ if (!acc[connector.category]) {
+ acc[connector.category] = [];
+ }
+ acc[connector.category].push(connector);
+ return acc;
+ }, {} as Record);
+
+ // Render each category
+ Object.entries(categorizedConnectors).forEach(([category, connectors]) => {
+ const categorySection = this.createCategorySection(category, connectors);
+ this.#connectorsContainer!.appendChild(categorySection);
+ });
+ }
+
+ private updateConnectionStatus(): void {
+ if (!this.#statusElement) {
+ return;
+ }
+
+ const connectedCount = this.#existingProviders.length;
+ const totalCount = MCP_CONNECTORS.length;
+ this.#statusElement.textContent = i18nString(UIStrings.connectionsStatus, {
+ PH1: connectedCount.toString(),
+ PH2: totalCount.toString()
+ });
+ }
+
+ private showConnectorError(connector: MCPConnector, error: string | Error, item: HTMLElement, toggle: HTMLButtonElement): void {
+ // Extract error details
+ let errorMessage = error instanceof Error ? error.message : error;
+ let errorType = 'unknown';
+ let errorDetails = null;
+
+ if (error instanceof Error && 'context' in error) {
+ const context = (error as any).context;
+ errorDetails = context;
+
+ // Determine error type based on context
+ if (context?.authState === 'oauth_required' || context?.httpStatus === 401) {
+ errorType = 'authentication';
+ } else if (context?.httpStatus === 404) {
+ errorType = 'configuration';
+ } else if (context?.httpStatus === 403) {
+ errorType = 'authentication';
+ } else if (context?.httpStatus >= 500) {
+ errorType = 'server_error';
+ } else if (context?.readyState === 2) {
+ errorType = 'network';
+ }
+ }
+
+ // Store error state with details
+ this.#connectionErrors.set(connector.id, { message: errorMessage, type: errorType, details: errorDetails });
+
+ // Update UI to error state
+ item.classList.add('error');
+ item.classList.remove('connecting', 'connected');
+ toggle.classList.add('error');
+ toggle.classList.remove('connecting', 'enabled');
+ toggle.disabled = true;
+
+ // Add error status dot
+ const toggleContainer = toggle.parentElement as HTMLElement;
+ const existingStatus = toggleContainer.querySelector('.mcp-connector-status');
+ if (existingStatus) {
+ existingStatus.remove();
+ }
+
+ const status = document.createElement('div');
+ status.className = 'mcp-connector-status';
+ const dot = document.createElement('div');
+ dot.className = 'mcp-status-dot error';
+ dot.title = errorMessage;
+ status.appendChild(dot);
+ toggleContainer.appendChild(status);
+
+ // Show error container
+ const errorContainer = item.querySelector('.mcp-connector-error') as HTMLElement;
+ if (errorContainer) {
+ errorContainer.style.display = 'block';
+ errorContainer.innerHTML = '';
+
+ // Error header with type
+ const header = document.createElement('div');
+ header.className = 'mcp-error-header';
+
+ const typeElement = document.createElement('div');
+ typeElement.className = 'mcp-error-type';
+ typeElement.textContent = this.getErrorTypeDisplayName(errorType);
+ header.appendChild(typeElement);
+
+ // Show details toggle if we have details
+ if (errorDetails) {
+ const toggleButton = document.createElement('button');
+ toggleButton.className = 'mcp-error-toggle';
+ toggleButton.textContent = i18nString(UIStrings.viewDetails);
+ toggleButton.addEventListener('click', () => {
+ const detailsElement = errorContainer.querySelector('.mcp-error-details') as HTMLElement;
+ if (detailsElement) {
+ const isVisible = detailsElement.style.display !== 'none';
+ detailsElement.style.display = isVisible ? 'none' : 'block';
+ toggleButton.textContent = i18nString(isVisible ? UIStrings.viewDetails : UIStrings.hideDetails);
+ }
+ });
+ header.appendChild(toggleButton);
+ }
+
+ errorContainer.appendChild(header);
+
+ // Error message
+ const message = document.createElement('div');
+ message.className = 'mcp-error-message';
+ message.textContent = errorMessage;
+ errorContainer.appendChild(message);
+
+ // Error details (initially hidden)
+ if (errorDetails) {
+ const details = document.createElement('div');
+ details.className = 'mcp-error-details';
+ details.style.display = 'none';
+ details.textContent = JSON.stringify(errorDetails, null, 2);
+ errorContainer.appendChild(details);
+ }
+
+ // Actions
+ const actions = document.createElement('div');
+ actions.className = 'mcp-error-actions';
+
+ const retryButton = document.createElement('button');
+ retryButton.className = 'mcp-error-retry-button';
+ retryButton.textContent = i18nString(UIStrings.retry);
+ retryButton.addEventListener('click', () => {
+ this.clearConnectorError(connector, item, toggle);
+ this.toggleConnector(connector, toggle, item);
+ });
+ actions.appendChild(retryButton);
+
+ const clearButton = document.createElement('button');
+ clearButton.className = 'mcp-error-clear-button';
+ clearButton.textContent = i18nString(UIStrings.clearError);
+ clearButton.addEventListener('click', () => {
+ this.clearConnectorError(connector, item, toggle);
+ });
+ actions.appendChild(clearButton);
+
+ errorContainer.appendChild(actions);
+ }
+ }
+
+ private getErrorTypeDisplayName(errorType: string): string {
+ switch (errorType) {
+ case 'authentication': return i18nString(UIStrings.errorTypeAuthentication);
+ case 'configuration': return i18nString(UIStrings.errorTypeConfiguration);
+ case 'network': return i18nString(UIStrings.errorTypeNetwork);
+ case 'server_error': return i18nString(UIStrings.errorTypeServerError);
+ case 'connection': return i18nString(UIStrings.errorTypeConnection);
+ default: return i18nString(UIStrings.errorTypeUnknown);
+ }
+ }
+
+ private clearConnectorError(connector: MCPConnector, item: HTMLElement, toggle: HTMLButtonElement): void {
+ // Clear any pending auto-reset timeout
+ const timeoutId = this.#errorResetTimeouts.get(connector.id);
+ if (timeoutId) {
+ window.clearTimeout(timeoutId);
+ this.#errorResetTimeouts.delete(connector.id);
+ }
+
+ // Remove error state
+ this.#connectionErrors.delete(connector.id);
+
+ // Update UI
+ item.classList.remove('error');
+ toggle.classList.remove('error');
+ toggle.disabled = false;
+
+ // Remove error status dot
+ const toggleContainer = toggle.parentElement as HTMLElement;
+ const existingStatus = toggleContainer.querySelector('.mcp-connector-status');
+ if (existingStatus) {
+ existingStatus.remove();
+ }
+
+ // Hide error container
+ const errorContainer = item.querySelector('.mcp-connector-error') as HTMLElement;
+ if (errorContainer) {
+ errorContainer.style.display = 'none';
+ errorContainer.innerHTML = '';
+ }
+ }
+
+ private setConnectingState(connectorId: string): void {
+ this.#connectingConnectorId = connectorId;
+ this.updateAllConnectorStates();
+ }
+
+ private clearConnectingState(): void {
+ this.#connectingConnectorId = null;
+ this.updateAllConnectorStates();
+ }
+
+ private updateAllConnectorStates(): void {
+ if (!this.#connectorsContainer) {
+ return;
+ }
+
+ const allItems = this.#connectorsContainer.querySelectorAll('.mcp-connector-item');
+ allItems.forEach((item) => {
+ const connectorId = this.getConnectorIdFromItem(item as HTMLElement);
+ if (!connectorId) return;
+
+ const toggle = item.querySelector('.mcp-toggle-switch') as HTMLButtonElement;
+ const isCurrentlyConnecting = this.#connectingConnectorId === connectorId;
+ const hasGlobalConnection = this.#connectingConnectorId && !isCurrentlyConnecting;
+
+ if (hasGlobalConnection) {
+ // Disable other toggles during connection
+ item.classList.add('globally-disabled');
+ toggle.classList.add('disabled');
+ toggle.disabled = true;
+ } else {
+ // Re-enable toggle if no global connection in progress
+ item.classList.remove('globally-disabled');
+ if (!this.#connectionErrors.has(connectorId)) {
+ toggle.classList.remove('disabled');
+ toggle.disabled = false;
+ }
+ }
+ });
+ }
+
+ private getConnectorIdFromItem(item: HTMLElement): string | null {
+ // We'll store the connector ID as a data attribute when creating items
+ return item.getAttribute('data-connector-id');
+ }
+
+ private createCategorySection(category: string, connectors: MCPConnector[]): HTMLElement {
+ const section = document.createElement('div');
+ section.className = 'mcp-category-section';
+
+ // Category header
+ const header = document.createElement('button');
+ header.className = 'mcp-category-header';
+ header.addEventListener('click', () => this.toggleCategory(category, header, connectorsContainer));
+
+ const title = document.createElement('h3');
+ title.className = 'mcp-category-title';
+ title.textContent = category;
+ header.appendChild(title);
+
+ const toggle = document.createElement('span');
+ toggle.className = 'mcp-category-toggle';
+ toggle.textContent = '▼';
+ if (this.#collapsedCategories.has(category)) {
+ toggle.classList.add('collapsed');
+ }
+ header.appendChild(toggle);
+
+ section.appendChild(header);
+
+ // Connectors container
+ const connectorsContainer = document.createElement('div');
+ connectorsContainer.className = 'mcp-category-connectors';
+ if (this.#collapsedCategories.has(category)) {
+ connectorsContainer.classList.add('collapsed');
+ }
+
+ connectors.forEach(connector => {
+ const item = this.createConnectorItem(connector);
+ connectorsContainer.appendChild(item);
+ });
+
+ section.appendChild(connectorsContainer);
+ return section;
+ }
+
+ private toggleCategory(category: string, header: HTMLElement, container: HTMLElement): void {
+ const toggle = header.querySelector('.mcp-category-toggle') as HTMLElement;
+
+ if (this.#collapsedCategories.has(category)) {
+ this.#collapsedCategories.delete(category);
+ container.classList.remove('collapsed');
+ toggle.classList.remove('collapsed');
+ } else {
+ this.#collapsedCategories.add(category);
+ container.classList.add('collapsed');
+ toggle.classList.add('collapsed');
+ }
+ }
+
+ private createConnectorItem(connector: MCPConnector): HTMLElement {
+ const item = document.createElement('div');
+ item.className = 'mcp-connector-item';
+ item.setAttribute('data-connector-id', connector.id);
+
+ const isConnected = this.#existingProviders.some(
+ provider => provider.endpoint === connector.endpoint
+ );
+ const hasError = this.#connectionErrors.has(connector.id);
+ const isConnecting = this.#connectingConnectorId === connector.id;
+
+ if (hasError) {
+ item.classList.add('error');
+ } else if (isConnected) {
+ item.classList.add('connected');
+ } else if (isConnecting) {
+ item.classList.add('connecting');
+ }
+
+ // Logo
+ const logo = document.createElement('div');
+ logo.className = 'mcp-connector-logo';
+ if (connector.logo) {
+ const logoImg = document.createElement('img');
+ logoImg.src = LOGO_URLS[connector.logo];
+ logoImg.alt = `${connector.name} logo`;
+ logoImg.loading = 'lazy';
+ logo.appendChild(logoImg);
+ }
+ item.appendChild(logo);
+
+ // Content
+ const content = document.createElement('div');
+ content.className = 'mcp-connector-content';
+
+ const name = document.createElement('h3');
+ name.className = 'mcp-connector-name';
+ name.textContent = connector.name;
+ content.appendChild(name);
+
+ const description = document.createElement('p');
+ description.className = 'mcp-connector-description';
+ description.textContent = connector.description;
+ content.appendChild(description);
+
+ item.appendChild(content);
+
+ // Toggle switch
+ const toggleContainer = document.createElement('div');
+ toggleContainer.className = 'mcp-connector-toggle';
+
+ const toggle = document.createElement('button');
+ toggle.className = 'mcp-toggle-switch';
+ if (hasError) {
+ toggle.classList.add('error');
+ toggle.disabled = true;
+ } else if (isConnecting) {
+ toggle.classList.add('connecting');
+ toggle.disabled = true;
+ } else if (isConnected) {
+ toggle.classList.add('enabled');
+ }
+
+ // Check if other connections are in progress
+ const hasGlobalConnection = this.#connectingConnectorId && !isConnecting;
+ if (hasGlobalConnection) {
+ toggle.classList.add('disabled');
+ toggle.disabled = true;
+ }
+
+ toggle.addEventListener('click', (e) => {
+ e.stopPropagation();
+ if (!hasError && !this.#connectingConnectorId) {
+ this.toggleConnector(connector, toggle, item);
+ }
+ });
+
+ toggleContainer.appendChild(toggle);
+
+ // Loading indicator (positioned before toggle) or status indicator (positioned after toggle)
+ if (isConnecting) {
+ const loading = document.createElement('div');
+ loading.className = 'mcp-loading-indicator';
+ loading.title = i18nString(UIStrings.connecting);
+ toggleContainer.insertBefore(loading, toggle);
+ }
+
+ // Status indicator for connected items or error items (positioned after toggle)
+ if (hasError) {
+ const status = document.createElement('div');
+ status.className = 'mcp-connector-status';
+ const dot = document.createElement('div');
+ dot.className = 'mcp-status-dot error';
+ const errorInfo = this.#connectionErrors.get(connector.id);
+ dot.title = errorInfo?.message || i18nString(UIStrings.connectionError);
+ status.appendChild(dot);
+ toggleContainer.appendChild(status);
+ } else if (isConnected) {
+ const status = document.createElement('div');
+ status.className = 'mcp-connector-status';
+ const dot = document.createElement('div');
+ dot.className = 'mcp-status-dot';
+ dot.title = i18nString(UIStrings.connected);
+ status.appendChild(dot);
+ toggleContainer.appendChild(status);
+ }
+
+ item.appendChild(toggleContainer);
+
+ // Error container (initially hidden, but show if there's an existing error)
+ const errorContainer = document.createElement('div');
+ errorContainer.className = 'mcp-connector-error';
+ errorContainer.style.display = hasError ? 'block' : 'none';
+
+ if (hasError) {
+ const errorInfo = this.#connectionErrors.get(connector.id);
+ const errorMessage = errorInfo?.message || i18nString(UIStrings.connectionError);
+ const errorType = errorInfo?.type || 'unknown';
+ const errorDetails = errorInfo?.details;
+
+ // Error header with type
+ const header = document.createElement('div');
+ header.className = 'mcp-error-header';
+
+ const typeElement = document.createElement('div');
+ typeElement.className = 'mcp-error-type';
+ typeElement.textContent = this.getErrorTypeDisplayName(errorType);
+ header.appendChild(typeElement);
+
+ // Show details toggle if we have details
+ if (errorDetails) {
+ const toggleButton = document.createElement('button');
+ toggleButton.className = 'mcp-error-toggle';
+ toggleButton.textContent = i18nString(UIStrings.viewDetails);
+ toggleButton.addEventListener('click', () => {
+ const detailsElement = errorContainer.querySelector('.mcp-error-details') as HTMLElement;
+ if (detailsElement) {
+ const isVisible = detailsElement.style.display !== 'none';
+ detailsElement.style.display = isVisible ? 'none' : 'block';
+ toggleButton.textContent = i18nString(isVisible ? UIStrings.viewDetails : UIStrings.hideDetails);
+ }
+ });
+ header.appendChild(toggleButton);
+ }
+
+ errorContainer.appendChild(header);
+
+ // Error message
+ const message = document.createElement('div');
+ message.className = 'mcp-error-message';
+ message.textContent = errorMessage;
+ errorContainer.appendChild(message);
+
+ // Error details (initially hidden)
+ if (errorDetails) {
+ const details = document.createElement('div');
+ details.className = 'mcp-error-details';
+ details.style.display = 'none';
+ details.textContent = JSON.stringify(errorDetails, null, 2);
+ errorContainer.appendChild(details);
+ }
+
+ // Actions
+ const actions = document.createElement('div');
+ actions.className = 'mcp-error-actions';
+
+ const retryButton = document.createElement('button');
+ retryButton.className = 'mcp-error-retry-button';
+ retryButton.textContent = i18nString(UIStrings.retry);
+ retryButton.addEventListener('click', () => {
+ this.clearConnectorError(connector, item, toggle);
+ this.toggleConnector(connector, toggle, item);
+ });
+ actions.appendChild(retryButton);
+
+ const clearButton = document.createElement('button');
+ clearButton.className = 'mcp-error-clear-button';
+ clearButton.textContent = i18nString(UIStrings.clearError);
+ clearButton.addEventListener('click', () => {
+ this.clearConnectorError(connector, item, toggle);
+ });
+ actions.appendChild(clearButton);
+
+ errorContainer.appendChild(actions);
+ }
+
+ item.appendChild(errorContainer);
+
+ return item;
+ }
+
+ private async toggleConnector(connector: MCPConnector, toggle: HTMLButtonElement, item: HTMLElement): Promise {
+ // Prevent toggling if another connection is in progress
+ if (this.#connectingConnectorId && this.#connectingConnectorId !== connector.id) {
+ return;
+ }
+
+ const isCurrentlyConnected = this.#existingProviders.some(
+ provider => provider.endpoint === connector.endpoint
+ );
+
+ if (isCurrentlyConnected) {
+ // Disconnect
+ await this.disconnectConnector(connector, toggle, item);
+ } else {
+ // Connect
+ await this.connectConnector(connector, toggle, item);
+ }
+ }
+
+ private async disconnectConnector(connector: MCPConnector, toggle: HTMLButtonElement, item: HTMLElement): Promise {
+ const previousProviders = this.#existingProviders.map(provider => ({ ...provider }));
+
+ try {
+ // Remove from providers
+ const updatedProviders = this.#existingProviders.filter(
+ provider => provider.endpoint !== connector.endpoint
+ );
+ saveMCPProviders(updatedProviders);
+ this.#existingProviders = getMCPProviders();
+
+ // Update UI
+ toggle.classList.remove('enabled');
+ item.classList.remove('connected');
+
+ // Remove status indicator
+ const statusElement = item.querySelector('.mcp-connector-status');
+ if (statusElement) {
+ statusElement.remove();
+ }
+
+ void await MCPRegistry.init(true);
+ await MCPRegistry.refresh();
+
+ // Update connection status counter
+ this.updateConnectionStatus();
+
+ logger.info(`Disconnected MCP connector: ${connector.name}`);
+
+ } catch (error) {
+ logger.error('Failed to disconnect MCP connector', error);
+
+ // Revert changes
+ try {
+ saveMCPProviders(previousProviders);
+ this.#existingProviders = getMCPProviders();
+ toggle.classList.add('enabled');
+ item.classList.add('connected');
+ } catch (revertError) {
+ logger.error('Failed to revert MCP providers after disconnect failure', revertError);
+ }
+
+ const snackbar = Snackbars.Snackbar.Snackbar.show({
+ message: i18nString(UIStrings.connectionFailed, {PH1: connector.name}),
+ closable: true,
+ });
+ snackbar.dismissTimeout = 4000;
+ }
+ }
+
+ private async connectConnector(connector: MCPConnector, toggle: HTMLButtonElement, item: HTMLElement): Promise {
+ const previousProviders = this.#existingProviders.map(provider => ({ ...provider }));
+
+ // Set global connecting state
+ this.setConnectingState(connector.id);
+
+ const progressSnackbar = Snackbars.Snackbar.Snackbar.show({
+ message: i18nString(UIStrings.oauthInProgress, {PH1: connector.name}),
+ closable: true,
+ });
+
+ const dismissProgressSnackbar = () => {
+ if (!progressSnackbar.isConnected) {
+ return;
+ }
+ const closeButton = progressSnackbar.shadowRoot?.querySelector('.dismiss') as HTMLElement | null;
+ if (closeButton) {
+ closeButton.click();
+ } else {
+ progressSnackbar.remove();
+ }
+ };
+
+ // Update UI to show loading state
+ toggle.classList.add('connecting');
+ toggle.disabled = true;
+ item.classList.add('connecting');
+ item.setAttribute('aria-busy', 'true');
+
+ // Add loading indicator to the left of toggle
+ const toggleContainer = toggle.parentElement as HTMLElement;
+ const existingStatus = toggleContainer.querySelector('.mcp-connector-status, .mcp-loading-indicator');
+ if (existingStatus) {
+ existingStatus.remove();
+ }
+
+ const loading = document.createElement('div');
+ loading.className = 'mcp-loading-indicator';
+ loading.title = i18nString(UIStrings.connecting);
+ toggleContainer.insertBefore(loading, toggle);
+
+ try {
+ const newProvider: MCPProviderConfig = {
+ id: connector.id,
+ name: connector.name,
+ endpoint: connector.endpoint,
+ authType: connector.authType,
+ enabled: true,
+ };
+
+ // Save provider temporarily to test connection
+ const updatedProviders = [...previousProviders, newProvider];
+ saveMCPProviders(updatedProviders);
+ this.#existingProviders = getMCPProviders();
+
+ // Test the connection
+ const connectionResults = await MCPRegistry.init(true);
+ await MCPRegistry.refresh();
+
+ // Find the result for our specific connector
+ const ourResult = connectionResults.find(result =>
+ result.endpoint === connector.endpoint || result.serverId === connector.id
+ );
+
+ // If connection failed, throw error to trigger catch block
+ if (!ourResult || !ourResult.connected) {
+ const error = ourResult?.error || new Error('Connection failed');
+ throw error;
+ }
+
+ // Clear global connecting state
+ this.clearConnectingState();
+
+ // Update UI to connected state
+ toggle.classList.remove('connecting');
+ toggle.classList.add('enabled');
+ toggle.disabled = false;
+ item.classList.remove('connecting');
+ item.classList.add('connected');
+ item.removeAttribute('aria-busy');
+
+ // Replace loading indicator with status indicator
+ const toggleContainer = toggle.parentElement as HTMLElement;
+ const loadingIndicator = toggleContainer.querySelector('.mcp-loading-indicator');
+ if (loadingIndicator) {
+ loadingIndicator.remove();
+ }
+
+ const status = document.createElement('div');
+ status.className = 'mcp-connector-status';
+ const dot = document.createElement('div');
+ dot.className = 'mcp-status-dot';
+ dot.title = i18nString(UIStrings.connected);
+ status.appendChild(dot);
+ toggleContainer.appendChild(status);
+
+ logger.info(`Connected MCP connector: ${connector.name}`);
+
+ // Update connection status counter
+ this.updateConnectionStatus();
+
+ dismissProgressSnackbar();
+
+ const snackbar = Snackbars.Snackbar.Snackbar.show({
+ message: i18nString(UIStrings.successMessage, {PH1: connector.name}),
+ actionProperties: {
+ label: i18nString(UIStrings.manageConnectionsAction),
+ onClick: () => this.#openManageConnections(),
+ },
+ });
+ snackbar.dismissTimeout = 4000;
+
+ } catch (error) {
+ logger.error('Failed to connect MCP connector', error);
+
+ // Clear global connecting state
+ this.clearConnectingState();
+
+ try {
+ saveMCPProviders(previousProviders);
+ this.#existingProviders = getMCPProviders();
+ } catch (revertError) {
+ logger.error('Failed to revert MCP providers after connect failure', revertError);
+ }
+
+ item.removeAttribute('aria-busy');
+
+ // Remove loading indicator
+ const toggleContainer = toggle.parentElement as HTMLElement;
+ const loadingIndicator = toggleContainer.querySelector('.mcp-loading-indicator');
+ if (loadingIndicator) {
+ loadingIndicator.remove();
+ }
+
+ const errorMessage = error instanceof Error && error.message
+ ? error.message
+ : i18nString(UIStrings.connectionError);
+
+ // Show inline error instead of just snackbar
+ this.showConnectorError(connector, errorMessage, item, toggle);
+
+ // Set 90-second auto-reset timeout
+ const timeoutId = window.setTimeout(() => {
+ this.clearConnectorError(connector, item, toggle);
+ logger.info(`Auto-cleared error for ${connector.name} after 90 seconds`);
+ }, 90000);
+ this.#errorResetTimeouts.set(connector.id, timeoutId);
+
+ dismissProgressSnackbar();
+
+ // Still show a snackbar for immediate feedback, but less prominent
+ const snackbar = Snackbars.Snackbar.Snackbar.show({
+ message: i18nString(UIStrings.connectionFailed, {PH1: connector.name}),
+ closable: true,
+ });
+ snackbar.dismissTimeout = 3000;
+ }
+ }
+
+
+ #openManageConnections(): void {
+ this.close();
+ MCPConnectionsDialog.show();
+ }
+
+ private close(): void {
+ // Clean up any pending timeout callbacks
+ this.#errorResetTimeouts.forEach((timeoutId) => {
+ window.clearTimeout(timeoutId);
+ });
+ this.#errorResetTimeouts.clear();
+
+ this.#dialog.hide();
+ if (this.#options.onClose) {
+ this.#options.onClose();
+ }
+ }
+}
diff --git a/front_end/panels/ai_chat/ui/mcp/mcpConnectorsCatalogDialog.css b/front_end/panels/ai_chat/ui/mcp/mcpConnectorsCatalogDialog.css
new file mode 100644
index 00000000000..613d648cb32
--- /dev/null
+++ b/front_end/panels/ai_chat/ui/mcp/mcpConnectorsCatalogDialog.css
@@ -0,0 +1,411 @@
+/*
+ * Copyright 2025 The Chromium Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+.mcp-connectors-catalog-dialog {
+ width: 600px;
+ max-width: 90vw;
+ max-height: 80vh;
+ color: var(--color-text-primary);
+ background: var(--color-background);
+ border-radius: 8px;
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
+ overflow: hidden;
+ border: 1px solid var(--color-details-hairline);
+}
+.mcp-catalog-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 16px 20px;
+ border-bottom: 1px solid var(--color-details-hairline);
+ background: var(--color-background);
+}
+.mcp-catalog-title {
+ font-size: 16px;
+ font-weight: 600;
+ margin: 0;
+ color: var(--color-text-primary);
+}
+.mcp-catalog-close {
+ background: none;
+ border: none;
+ cursor: pointer;
+ font-size: 18px;
+ padding: 6px;
+ color: var(--color-text-secondary);
+ border-radius: 4px;
+ transition: all 0.2s ease;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 28px;
+ height: 28px;
+}
+.mcp-catalog-close:hover {
+ color: var(--color-text-primary);
+ background: var(--color-background-elevation-1);
+}
+.mcp-catalog-body {
+ overflow-y: auto;
+ flex: 1;
+ max-height: 60vh;
+}
+.mcp-catalog-search-section {
+ padding: 16px 20px 0;
+ border-bottom: 1px solid var(--color-details-hairline);
+ background: var(--color-background);
+}
+.mcp-catalog-search-input {
+ width: 100%;
+ padding: 8px 12px;
+ border: 1px solid var(--color-details-hairline);
+ border-radius: 6px;
+ background: var(--color-background);
+ color: var(--color-text-primary);
+ font-size: 14px;
+ outline: none;
+ transition: border-color 0.2s ease;
+}
+.mcp-catalog-search-input:focus {
+ border-color: var(--color-primary);
+}
+.mcp-catalog-search-input::placeholder {
+ color: var(--color-text-secondary);
+}
+.mcp-catalog-status {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 12px 20px;
+ font-size: 13px;
+ color: var(--color-text-secondary);
+ background: var(--color-background-elevation-0);
+ border-bottom: 1px solid var(--color-details-hairline);
+}
+.mcp-catalog-status-count {
+ font-weight: 500;
+}
+.mcp-category-section {
+ border-bottom: 1px solid var(--color-details-hairline-light);
+}
+.mcp-category-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 12px 20px;
+ background: var(--color-background-elevation-0);
+ cursor: pointer;
+ transition: background 0.2s ease;
+ border: none;
+ width: 100%;
+ text-align: left;
+}
+.mcp-category-header:hover {
+ background: var(--color-background-elevation-1);
+}
+.mcp-category-title {
+ font-size: 14px;
+ font-weight: 600;
+ color: var(--color-text-primary);
+ margin: 0;
+}
+.mcp-category-toggle {
+ font-size: 12px;
+ color: var(--color-text-secondary);
+ transform: rotate(0deg);
+ transition: transform 0.2s ease;
+}
+.mcp-category-toggle.collapsed {
+ transform: rotate(-90deg);
+}
+.mcp-category-connectors {
+ background: var(--color-background);
+}
+.mcp-category-connectors.collapsed {
+ display: none;
+}
+.mcp-connector-item {
+ display: flex;
+ align-items: center;
+ padding: 12px 20px;
+ border-bottom: 1px solid var(--color-details-hairline-light);
+ transition: background 0.2s ease;
+ min-height: 60px;
+}
+.mcp-connector-item:hover {
+ background: var(--color-background-elevation-1);
+}
+.mcp-connector-item.connected {
+ background: var(--color-primary-container);
+ border-left: 3px solid var(--color-primary);
+}
+.mcp-connector-item.connecting {
+ background: var(--color-background-elevation-1);
+ opacity: 0.8;
+}
+.mcp-connector-item.error {
+ background: var(--color-background-elevation-1);
+ border-left: 3px solid var(--color-error);
+}
+.mcp-connector-logo {
+ width: 24px;
+ height: 24px;
+ margin-right: 12px;
+ flex-shrink: 0;
+}
+.mcp-connector-logo img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+}
+.mcp-connector-content {
+ flex: 1;
+ min-width: 0;
+}
+.mcp-connector-name {
+ font-size: 14px;
+ font-weight: 500;
+ color: var(--color-text-primary);
+ margin: 0 0 2px 0;
+ line-height: 1.2;
+}
+.mcp-connector-description {
+ font-size: 12px;
+ color: var(--color-text-secondary);
+ margin: 0;
+ line-height: 1.3;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.mcp-connector-toggle {
+ margin-left: 12px;
+ flex-shrink: 0;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+}
+.mcp-toggle-switch {
+ position: relative;
+ width: 36px;
+ height: 20px;
+ background: var(--color-details-hairline);
+ border-radius: 10px;
+ cursor: pointer;
+ transition: background 0.2s ease;
+ border: none;
+ outline: none;
+}
+.mcp-toggle-switch.enabled {
+ background: var(--color-primary);
+}
+.mcp-toggle-switch.connecting {
+ background: var(--color-primary-container-border);
+ cursor: wait;
+}
+.mcp-toggle-switch::after {
+ content: '';
+ position: absolute;
+ top: 2px;
+ left: 2px;
+ width: 16px;
+ height: 16px;
+ background: white;
+ border-radius: 50%;
+ transition: transform 0.2s ease;
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
+}
+.mcp-toggle-switch.enabled::after {
+ transform: translateX(16px);
+}
+.mcp-toggle-switch.error {
+ background: var(--color-error);
+ opacity: 0.6;
+ cursor: not-allowed;
+}
+.mcp-toggle-switch.error::after {
+ background: #ffdddd;
+}
+.mcp-toggle-switch.disabled {
+ background: var(--color-details-hairline);
+ opacity: 0.5;
+ cursor: not-allowed;
+}
+.mcp-toggle-switch.disabled::after {
+ background: var(--color-background-elevation-1);
+}
+.mcp-connector-status {
+ display: flex;
+ align-items: center;
+ font-size: 12px;
+ color: var(--color-text-secondary);
+}
+.mcp-status-dot {
+ width: 6px;
+ height: 6px;
+ border-radius: 50%;
+ background: var(--color-primary);
+ margin-right: 4px;
+ cursor: help;
+}
+.mcp-status-dot.error {
+ background: var(--color-error);
+}
+.mcp-connector-error {
+ margin-top: 8px;
+ padding: 8px 12px;
+ background: var(--color-error-container);
+ border: 1px solid var(--color-error);
+ border-radius: 4px;
+ font-size: 12px;
+ color: var(--color-error-text);
+ line-height: 1.3;
+}
+.mcp-error-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 6px;
+}
+.mcp-error-type {
+ font-weight: 600;
+ color: var(--color-error);
+}
+.mcp-error-message {
+ margin-bottom: 6px;
+}
+.mcp-error-details {
+ background: var(--color-background-elevation-1);
+ border: 1px solid var(--color-details-hairline);
+ border-radius: 3px;
+ padding: 6px 8px;
+ margin: 6px 0;
+ font-family: monospace;
+ font-size: 11px;
+ color: var(--color-text-secondary);
+ max-height: 100px;
+ overflow-y: auto;
+ white-space: pre-wrap;
+ word-break: break-all;
+}
+.mcp-error-actions {
+ display: flex;
+ gap: 8px;
+}
+.mcp-error-toggle {
+ background: none;
+ border: none;
+ color: var(--color-error);
+ font-size: 11px;
+ cursor: pointer;
+ text-decoration: underline;
+ padding: 0;
+}
+.mcp-error-toggle:hover {
+ color: var(--color-error-variant);
+}
+.mcp-error-retry-button, .mcp-error-clear-button {
+ padding: 4px 8px;
+ font-size: 11px;
+ border-radius: 3px;
+ cursor: pointer;
+ border: none;
+ font-weight: 500;
+ transition: all 0.2s ease;
+}
+.mcp-error-retry-button {
+ background: var(--color-error);
+ color: var(--color-text-inverted);
+}
+.mcp-error-retry-button:hover {
+ background: var(--color-error-variant);
+}
+.mcp-error-clear-button {
+ background: var(--color-background);
+ color: var(--color-text-secondary);
+ border: 1px solid var(--color-details-hairline);
+}
+.mcp-error-clear-button:hover {
+ background: var(--color-background-elevation-1);
+}
+.mcp-loading-indicator {
+ display: flex;
+ align-items: center;
+ font-size: 14px;
+ color: var(--color-text-secondary);
+ cursor: help;
+}
+.mcp-loading-indicator::after {
+ content: '...';
+ animation: mcp-loading-dots 1.5s steps(4, end) infinite;
+}
+@keyframes mcp-loading-dots {
+ 0%, 20% { content: ''; }
+ 40% { content: '.'; }
+ 60% { content: '..'; }
+ 80%, 100% { content: '...'; }
+}
+.mcp-connector-item.globally-disabled {
+ opacity: 0.6;
+ pointer-events: none;
+}
+.mcp-no-results {
+ text-align: center;
+ padding: 40px 20px;
+ color: var(--color-text-secondary);
+ font-size: 14px;
+}
+.mcp-catalog-footer {
+ display: flex;
+ justify-content: flex-end;
+ gap: 8px;
+ padding: 12px 20px;
+ border-top: 1px solid var(--color-details-hairline);
+ background: var(--color-background-elevation-0);
+}
+.mcp-manage-button {
+ padding: 8px 16px;
+ border: 1px solid var(--color-primary);
+ background: var(--color-background);
+ color: var(--color-primary);
+ border-radius: 6px;
+ cursor: pointer;
+ font-size: 13px;
+ font-weight: 500;
+ transition: all 0.2s ease;
+}
+.mcp-manage-button:hover {
+ background: var(--color-primary);
+ color: var(--color-text-inverted);
+}
+.mcp-close-button {
+ padding: 8px 16px;
+ border: 1px solid var(--color-details-hairline);
+ background: var(--color-background);
+ color: var(--color-text-primary);
+ border-radius: 6px;
+ cursor: pointer;
+ font-size: 13px;
+ font-weight: 500;
+ transition: all 0.2s ease;
+}
+.mcp-close-button:hover {
+ background: var(--color-background-elevation-1);
+ border-color: var(--color-primary-container-border);
+}
+.mcp-catalog-body::-webkit-scrollbar {
+ width: 6px;
+}
+.mcp-catalog-body::-webkit-scrollbar-track {
+ background: transparent;
+}
+.mcp-catalog-body::-webkit-scrollbar-thumb {
+ background: var(--color-details-hairline);
+ border-radius: 3px;
+}
+.mcp-catalog-body::-webkit-scrollbar-thumb:hover {
+ background: var(--color-text-secondary);
+}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/.tonic_example.js b/front_end/third_party/mcp-sdk/.tonic_example.js
new file mode 100644
index 00000000000..aa11812d87b
--- /dev/null
+++ b/front_end/third_party/mcp-sdk/.tonic_example.js
@@ -0,0 +1,20 @@
+var Ajv = require('ajv');
+var ajv = new Ajv({allErrors: true});
+
+var schema = {
+ "properties": {
+ "foo": { "type": "string" },
+ "bar": { "type": "number", "maximum": 3 }
+ }
+};
+
+var validate = ajv.compile(schema);
+
+test({"foo": "abc", "bar": 2});
+test({"foo": 2, "bar": 4});
+
+function test(data) {
+ var valid = validate(data);
+ if (valid) console.log('Valid!');
+ else console.log('Invalid: ' + ajv.errorsText(validate.errors));
+}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/BUILD.gn b/front_end/third_party/mcp-sdk/BUILD.gn
index b742491f8d9..e088756009f 100644
--- a/front_end/third_party/mcp-sdk/BUILD.gn
+++ b/front_end/third_party/mcp-sdk/BUILD.gn
@@ -16,25 +16,42 @@ devtools_pre_built("mcp-sdk") {
# AJV JSON Schema validator (dependency)
"ajv/dist/ajv.d.ts",
"ajv/dist/ajv.js",
+ "ajv/dist/ajv.bundle.js",
+ "ajv/dist/ajv-esm.js",
"ajv/package.json",
# Zod schema validation library (dependency)
"zod/index.d.ts",
"zod/lib/index.js",
"zod/lib/index.mjs",
+ "zod/zod-esm.js",
+ # Compat wrapper for environments that resolve relative imports under dist/
+ "dist/zod/zod-esm.js",
"zod/package.json",
- # Main MCP SDK files
- "package/dist/client/index.d.ts",
- "package/dist/client/index.js",
- "package/dist/client/sse.d.ts",
- "package/dist/client/sse.js",
- "package/dist/shared/transport.d.ts",
- "package/dist/shared/transport.js",
- "package/dist/shared/protocol.d.ts",
- "package/dist/shared/protocol.js",
- "package/dist/types.d.ts",
- "package/dist/types.js",
+ # Main MCP SDK files (new dist/esm location with patches)
+ "dist/esm/client/auth.d.ts",
+ "dist/esm/client/auth.js",
+ "dist/esm/client/index.d.ts",
+ "dist/esm/client/index.js",
+ "dist/esm/client/sse.d.ts",
+ "dist/esm/client/sse.js",
+ "dist/esm/client/streamableHttp.d.ts",
+ "dist/esm/client/streamableHttp.js",
+ "dist/esm/server/index.d.ts",
+ "dist/esm/server/index.js",
+ "dist/esm/server/auth/errors.d.ts",
+ "dist/esm/server/auth/errors.js",
+ "dist/esm/shared/auth.d.ts",
+ "dist/esm/shared/auth.js",
+ "dist/esm/shared/auth-utils.d.ts",
+ "dist/esm/shared/auth-utils.js",
+ "dist/esm/shared/transport.d.ts",
+ "dist/esm/shared/transport.js",
+ "dist/esm/shared/protocol.d.ts",
+ "dist/esm/shared/protocol.js",
+ "dist/esm/types.d.ts",
+ "dist/esm/types.js",
# EventSource parser dependency
"eventsource-parser/package/dist/index.d.ts",
@@ -47,11 +64,30 @@ devtools_pre_built("mcp-sdk") {
devtools_entrypoint("bundle") {
entrypoint = "mcp-sdk.ts"
- deps = [ ":mcp-sdk" ]
+ deps = [ ":mcp-sdk",
+ # Required by MCPOAuthProvider for navigation & URL monitoring
+ "../../core/sdk:bundle",
+ "../../core/platform:bundle",
+ ]
+
+ visibility = [
+ "../../panels/ai_chat/*",
+ ]
+
+ visibility += devtools_third_party_visibility
+}
+
+devtools_entrypoint("bundle_v2") {
+ entrypoint = "mcp-sdk-v2.ts"
+
+ deps = [ ":mcp-sdk",
+ "../../core/sdk:bundle",
+ "../../core/platform:bundle",
+ ]
visibility = [
"../../panels/ai_chat/*",
]
visibility += devtools_third_party_visibility
-}
\ No newline at end of file
+}
diff --git a/front_end/third_party/mcp-sdk/LICENSE b/front_end/third_party/mcp-sdk/LICENSE
index 136059a2b9f..96ee719987f 100644
--- a/front_end/third_party/mcp-sdk/LICENSE
+++ b/front_end/third_party/mcp-sdk/LICENSE
@@ -1,6 +1,6 @@
-MIT License
+The MIT License (MIT)
-Copyright (c) 2024 Anthropic, PBC
+Copyright (c) 2015-2017 Evgeny Poberezkin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,5 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
\ No newline at end of file
+SOFTWARE.
+
diff --git a/front_end/third_party/mcp-sdk/MCPOAuthProvider.ts b/front_end/third_party/mcp-sdk/MCPOAuthProvider.ts
new file mode 100644
index 00000000000..1897dad2c20
--- /dev/null
+++ b/front_end/third_party/mcp-sdk/MCPOAuthProvider.ts
@@ -0,0 +1,261 @@
+// Copyright 2025 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import type {
+ OAuthClientProvider,
+ OAuthClientMetadata,
+ OAuthClientInformation,
+ OAuthClientInformationFull,
+ OAuthTokens,
+} from './dist/esm/client/auth.js';
+import type { AuthorizationServerMetadata } from './dist/esm/shared/auth.js';
+
+import * as SDK from '../../core/sdk/sdk.js';
+import * as Platform from '../../core/platform/platform.js';
+
+// Minimal MCP server descriptor used by the provider for namespacing
+export interface MCPOAuthServerDescriptor {
+ id: string;
+ endpoint: string;
+}
+
+/**
+ * DevTools OAuth provider for MCP SDK (browser-based, OpenRouter-style flow).
+ *
+ * - Navigates the inspected page to the provider's authorization URL
+ * - Monitors URL changes to capture the authorization code on redirect
+ * - Returns the user to the original page afterwards
+ * - Persists tokens and optional client registration per MCP server id
+ */
+export class MCPOAuthProvider implements OAuthClientProvider {
+ // Use the same callback convention as OpenRouter flow
+ private static readonly DEFAULT_REDIRECT_URI = 'https://localhost:3000/callback';
+
+ // Storage keys are namespaced by server id
+ private readonly TOKENS_KEY: string;
+ private readonly CLIENT_INFO_KEY: string;
+ private readonly CODE_VERIFIER_KEY: string;
+ private readonly STATE_KEY: string;
+ private readonly ORIGINAL_URL_KEY: string;
+
+ private urlChangeCleanup: (() => void) | null = null;
+
+ constructor(private readonly server: MCPOAuthServerDescriptor,
+ private readonly metadata: Partial = {}) {
+ const prefix = `mcp_oauth:${server.id}:`;
+ this.TOKENS_KEY = `${prefix}tokens`;
+ this.CLIENT_INFO_KEY = `${prefix}client_info`;
+ this.CODE_VERIFIER_KEY = `${prefix}code_verifier`;
+ this.STATE_KEY = `${prefix}state`;
+ this.ORIGINAL_URL_KEY = `${prefix}original_url`;
+ }
+
+ get redirectUrl(): string | URL {
+ return MCPOAuthProvider.DEFAULT_REDIRECT_URI;
+ }
+
+ get clientMetadata(): OAuthClientMetadata {
+ const redirect = String(this.redirectUrl);
+ return {
+ redirect_uris: [redirect],
+ client_name: 'browseroperator',
+ grant_types: ['authorization_code', 'refresh_token'],
+ response_types: ['code'],
+ scope: this.metadata.scope ?? 'offline_access',
+ token_endpoint_auth_method: this.metadata.token_endpoint_auth_method,
+ };
+ }
+
+ // Optional state support; we save and later validate on callback
+ state(): string {
+ const state = this.randomState();
+ sessionStorage.setItem(this.STATE_KEY, state);
+ return state;
+ }
+
+ async clientInformation(): Promise {
+ const raw = localStorage.getItem(this.CLIENT_INFO_KEY);
+ return raw ? JSON.parse(raw) as OAuthClientInformation : undefined;
+ }
+
+ async saveClientInformation(info: OAuthClientInformationFull): Promise {
+ localStorage.setItem(this.CLIENT_INFO_KEY, JSON.stringify(info));
+ }
+
+ async tokens(): Promise {
+ const raw = sessionStorage.getItem(this.TOKENS_KEY);
+ return raw ? JSON.parse(raw) as OAuthTokens : undefined;
+ }
+
+ async saveTokens(tokens: OAuthTokens): Promise {
+ sessionStorage.setItem(this.TOKENS_KEY, JSON.stringify(tokens));
+ }
+
+ async saveCodeVerifier(verifier: string): Promise {
+ sessionStorage.setItem(this.CODE_VERIFIER_KEY, verifier);
+ }
+
+ async codeVerifier(): Promise {
+ const v = sessionStorage.getItem(this.CODE_VERIFIER_KEY);
+ if (!v) {
+ throw new Error('Missing PKCE code verifier');
+ }
+ return v;
+ }
+
+ // Optional: allow consumers to customize client authentication per token request
+ async addClientAuthentication(_headers: Headers, _params: URLSearchParams, _url: string | URL, _metadata?: AuthorizationServerMetadata): Promise {
+ // Default no-op. The SDK will apply one of the standard methods based on server metadata.
+ }
+
+ // Provider-directed redirect: navigate inspected page, set up monitoring externally
+ async redirectToAuthorization(authorizationUrl: URL): Promise {
+ // Store original page URL to return to later
+ const original = this.currentPageUrl();
+ if (original) {
+ sessionStorage.setItem(this.ORIGINAL_URL_KEY, original);
+ }
+ // Navigate main frame to provider auth URL
+ await this.navigate(String(authorizationUrl));
+ }
+
+ // Utility exposed to orchestrators: wait until the inspected page hits redirectUrl and return the code
+ async waitForAuthorizationCode(): Promise {
+ return new Promise((resolve, reject) => {
+ const timeout = setTimeout(() => {
+ this.removeListeners();
+ reject(new Error('oauth_timeout'));
+ }, 5 * 60 * 1000);
+
+ const maybeHandleUrl = async (url: string): Promise => {
+ if (!this.isRedirectUrl(url)) {
+ return false;
+ }
+ try {
+ const { code, state } = this.parseAuthCallback(url);
+ const expected = sessionStorage.getItem(this.STATE_KEY);
+ if (expected && state && expected !== state) {
+ throw new Error('oauth_invalid_state');
+ }
+ // Cleanup state now that we used it
+ sessionStorage.removeItem(this.STATE_KEY);
+ // Return user to original page
+ await this.returnToOriginalUrl();
+ clearTimeout(timeout);
+ this.removeListeners();
+ resolve(code);
+ return true;
+ } catch (e) {
+ clearTimeout(timeout);
+ this.removeListeners();
+ reject(e instanceof Error ? e : new Error(String(e)));
+ return true;
+ }
+ };
+
+ const targetsListener = async (event: SDK.TargetManager.TargetManagerEvent) => {
+ try {
+ const targetInfos = event.data as Array<{url?: string}>;
+ for (const info of targetInfos) {
+ if (info.url && await maybeHandleUrl(info.url)) {
+ return;
+ }
+ }
+ } catch {
+ // ignore
+ }
+ };
+ const urlListener = async () => {
+ const url = this.currentPageUrl();
+ if (url) {
+ await maybeHandleUrl(url);
+ }
+ };
+
+ this.urlChangeCleanup = () => {
+ SDK.TargetManager.TargetManager.instance().removeEventListener(
+ SDK.TargetManager.Events.AVAILABLE_TARGETS_CHANGED, targetsListener);
+ SDK.TargetManager.TargetManager.instance().removeEventListener(
+ SDK.TargetManager.Events.INSPECTED_URL_CHANGED, urlListener);
+ };
+
+ SDK.TargetManager.TargetManager.instance().addEventListener(
+ SDK.TargetManager.Events.AVAILABLE_TARGETS_CHANGED, targetsListener);
+ SDK.TargetManager.TargetManager.instance().addEventListener(
+ SDK.TargetManager.Events.INSPECTED_URL_CHANGED, urlListener);
+ });
+ }
+
+ // Helpers
+ private removeListeners(): void {
+ if (this.urlChangeCleanup) {
+ this.urlChangeCleanup();
+ this.urlChangeCleanup = null;
+ }
+ }
+
+ private currentPageUrl(): string | null {
+ const target = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
+ if (!target) {
+ return null;
+ }
+ const rtm = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
+ const frame = rtm?.mainFrame;
+ return frame ? frame.url : null;
+ }
+
+ private async navigate(url: string): Promise {
+ const target = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
+ if (!target) {
+ throw new Error('navigation_failed');
+ }
+ const rtm = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
+ if (!rtm) {
+ throw new Error('navigation_failed');
+ }
+ const result = await rtm.navigate(url as Platform.DevToolsPath.UrlString);
+ if (result.errorText) {
+ throw new Error(`navigation_failed:${result.errorText}`);
+ }
+ }
+
+ private async returnToOriginalUrl(): Promise {
+ const url = sessionStorage.getItem(this.ORIGINAL_URL_KEY);
+ sessionStorage.removeItem(this.ORIGINAL_URL_KEY);
+ if (url) {
+ try {
+ await this.navigate(url);
+ } catch {
+ // ignore
+ }
+ }
+ }
+
+ private isRedirectUrl(candidate: string): boolean {
+ try {
+ const cb = new URL(String(this.redirectUrl));
+ const u = new URL(candidate);
+ return `${u.origin}${u.pathname}` === `${cb.origin}${cb.pathname}`;
+ } catch {
+ return false;
+ }
+ }
+
+ private parseAuthCallback(url: string): { code: string; state?: string } {
+ const u = new URL(url);
+ const code = u.searchParams.get('code');
+ const state = u.searchParams.get('state') ?? undefined;
+ if (!code) {
+ throw new Error('oauth_missing_code');
+ }
+ return { code, state };
+ }
+
+ private randomState(): string {
+ const arr = new Uint8Array(16);
+ crypto.getRandomValues(arr);
+ return Array.from(arr).map(b => b.toString(16).padStart(2, '0')).join('');
+ }
+}
+
diff --git a/front_end/third_party/mcp-sdk/README.chromium b/front_end/third_party/mcp-sdk/README.chromium
index 6aba4904938..49cb649882a 100644
--- a/front_end/third_party/mcp-sdk/README.chromium
+++ b/front_end/third_party/mcp-sdk/README.chromium
@@ -1,7 +1,7 @@
Name: Model Context Protocol SDK
Short Name: mcp-sdk
URL: https://github.com/modelcontextprotocol/typescript-sdk
-Version: 1.12.3
+Version: 1.18.0
License: MIT
License File: LICENSE
Security Critical: no
@@ -13,12 +13,25 @@ to interact with external systems through a standardized protocol.
Dependencies:
- eventsource-parser@3.0.6 (MIT license)
+- ajv@6.12.6 (MIT license)
To update this package:
-wget -qO- https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.12.3.tgz | tar xzf -
+wget -qO- https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.18.0.tgz | tar xzf - --strip-components=1 package/
wget -qO- https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz | tar xzf -
+wget -qO- https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz | tar xzf - -C ajv --strip-components=1
+cd ajv/dist && ln -s ../lib/ajv.d.ts ajv.d.ts && ln -s ../lib/ajv.js ajv.js
Local Modifications:
- Created mcp-sdk.ts wrapper for DevTools integration
- Removed Node.js-specific code paths
-- Modified imports to use DevTools module system
\ No newline at end of file
+- Modified imports to use DevTools module system
+- Updated to use official StreamableHTTPClientTransport instead of custom implementation
+- Created ES module wrapper for ajv UMD bundle:
+ - ajv/dist/ajv-esm.js: exports ajv.bundle.js as ES module
+- Patched SDK files to use ajv-esm wrapper:
+ - dist/esm/client/index.js: import Ajv from "../../ajv/dist/ajv-esm.js"
+ - dist/esm/server/index.js: import Ajv from "../../ajv/dist/ajv-esm.js"
+ - dist/esm/examples/client/simpleStreamableHttp.js: import Ajv from "../../../ajv/dist/ajv-esm.js"
+- Updated build configuration to use new SDK files:
+ - BUILD.gn: updated to reference dist/esm/ instead of package/dist/
+ - devtools_grd_files.gni: updated file paths to include new SDK and ajv files
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/README.md b/front_end/third_party/mcp-sdk/README.md
new file mode 100644
index 00000000000..5aa2078d892
--- /dev/null
+++ b/front_end/third_party/mcp-sdk/README.md
@@ -0,0 +1,1497 @@
+
+
+# Ajv: Another JSON Schema Validator
+
+The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/07.
+
+[](https://travis-ci.org/ajv-validator/ajv)
+[](https://www.npmjs.com/package/ajv)
+[](https://www.npmjs.com/package/ajv/v/7.0.0-beta.0)
+[](https://www.npmjs.com/package/ajv)
+[](https://coveralls.io/github/ajv-validator/ajv?branch=master)
+[](https://gitter.im/ajv-validator/ajv)
+[](https://github.com/sponsors/epoberezkin)
+
+
+## Ajv v7 beta is released
+
+[Ajv version 7.0.0-beta.0](https://github.com/ajv-validator/ajv/tree/v7-beta) is released with these changes:
+
+- to reduce the mistakes in JSON schemas and unexpected validation results, [strict mode](./docs/strict-mode.md) is added - it prohibits ignored or ambiguous JSON Schema elements.
+- to make code injection from untrusted schemas impossible, [code generation](./docs/codegen.md) is fully re-written to be safe.
+- to simplify Ajv extensions, the new keyword API that is used by pre-defined keywords is available to user-defined keywords - it is much easier to define any keywords now, especially with subschemas.
+- schemas are compiled to ES6 code (ES5 code generation is supported with an option).
+- to improve reliability and maintainability the code is migrated to TypeScript.
+
+**Please note**:
+
+- the support for JSON-Schema draft-04 is removed - if you have schemas using "id" attributes you have to replace them with "\$id" (or continue using version 6 that will be supported until 02/28/2021).
+- all formats are separated to ajv-formats package - they have to be explicitely added if you use them.
+
+See [release notes](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0-beta.0) for the details.
+
+To install the new version:
+
+```bash
+npm install ajv@beta
+```
+
+See [Getting started with v7](https://github.com/ajv-validator/ajv/tree/v7-beta#usage) for code example.
+
+
+## Mozilla MOSS grant and OpenJS Foundation
+
+[
](https://www.mozilla.org/en-US/moss/) [
](https://openjsf.org/blog/2020/08/14/ajv-joins-openjs-foundation-as-an-incubation-project/)
+
+Ajv has been awarded a grant from Mozilla’s [Open Source Support (MOSS) program](https://www.mozilla.org/en-US/moss/) in the “Foundational Technology” track! It will sponsor the development of Ajv support of [JSON Schema version 2019-09](https://tools.ietf.org/html/draft-handrews-json-schema-02) and of [JSON Type Definition](https://tools.ietf.org/html/draft-ucarion-json-type-definition-04).
+
+Ajv also joined [OpenJS Foundation](https://openjsf.org/) – having this support will help ensure the longevity and stability of Ajv for all its users.
+
+This [blog post](https://www.poberezkin.com/posts/2020-08-14-ajv-json-validator-mozilla-open-source-grant-openjs-foundation.html) has more details.
+
+I am looking for the long term maintainers of Ajv – working with [ReadySet](https://www.thereadyset.co/), also sponsored by Mozilla, to establish clear guidelines for the role of a "maintainer" and the contribution standards, and to encourage a wider, more inclusive, contribution from the community.
+
+
+## Please [sponsor Ajv development](https://github.com/sponsors/epoberezkin)
+
+Since I asked to support Ajv development 40 people and 6 organizations contributed via GitHub and OpenCollective - this support helped receiving the MOSS grant!
+
+Your continuing support is very important - the funds will be used to develop and maintain Ajv once the next major version is released.
+
+Please sponsor Ajv via:
+- [GitHub sponsors page](https://github.com/sponsors/epoberezkin) (GitHub will match it)
+- [Ajv Open Collective️](https://opencollective.com/ajv)
+
+Thank you.
+
+
+#### Open Collective sponsors
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+## Using version 6
+
+[JSON Schema draft-07](http://json-schema.org/latest/json-schema-validation.html) is published.
+
+[Ajv version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0) that supports draft-07 is released. It may require either migrating your schemas or updating your code (to continue using draft-04 and v5 schemas, draft-06 schemas will be supported without changes).
+
+__Please note__: To use Ajv with draft-06 schemas you need to explicitly add the meta-schema to the validator instance:
+
+```javascript
+ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
+```
+
+To use Ajv with draft-04 schemas in addition to explicitly adding meta-schema you also need to use option schemaId:
+
+```javascript
+var ajv = new Ajv({schemaId: 'id'});
+// If you want to use both draft-04 and draft-06/07 schemas:
+// var ajv = new Ajv({schemaId: 'auto'});
+ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
+```
+
+
+## Contents
+
+- [Performance](#performance)
+- [Features](#features)
+- [Getting started](#getting-started)
+- [Frequently Asked Questions](https://github.com/ajv-validator/ajv/blob/master/FAQ.md)
+- [Using in browser](#using-in-browser)
+ - [Ajv and Content Security Policies (CSP)](#ajv-and-content-security-policies-csp)
+- [Command line interface](#command-line-interface)
+- Validation
+ - [Keywords](#validation-keywords)
+ - [Annotation keywords](#annotation-keywords)
+ - [Formats](#formats)
+ - [Combining schemas with $ref](#ref)
+ - [$data reference](#data-reference)
+ - NEW: [$merge and $patch keywords](#merge-and-patch-keywords)
+ - [Defining custom keywords](#defining-custom-keywords)
+ - [Asynchronous schema compilation](#asynchronous-schema-compilation)
+ - [Asynchronous validation](#asynchronous-validation)
+- [Security considerations](#security-considerations)
+ - [Security contact](#security-contact)
+ - [Untrusted schemas](#untrusted-schemas)
+ - [Circular references in objects](#circular-references-in-javascript-objects)
+ - [Trusted schemas](#security-risks-of-trusted-schemas)
+ - [ReDoS attack](#redos-attack)
+- Modifying data during validation
+ - [Filtering data](#filtering-data)
+ - [Assigning defaults](#assigning-defaults)
+ - [Coercing data types](#coercing-data-types)
+- API
+ - [Methods](#api)
+ - [Options](#options)
+ - [Validation errors](#validation-errors)
+- [Plugins](#plugins)
+- [Related packages](#related-packages)
+- [Some packages using Ajv](#some-packages-using-ajv)
+- [Tests, Contributing, Changes history](#tests)
+- [Support, Code of conduct, License](#open-source-software-support)
+
+
+## Performance
+
+Ajv generates code using [doT templates](https://github.com/olado/doT) to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.
+
+Currently Ajv is the fastest and the most standard compliant validator according to these benchmarks:
+
+- [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark) - 50% faster than the second place
+- [jsck benchmark](https://github.com/pandastrike/jsck#benchmarks) - 20-190% faster
+- [z-schema benchmark](https://rawgit.com/zaggino/z-schema/master/benchmark/results.html)
+- [themis benchmark](https://cdn.rawgit.com/playlyfe/themis/master/benchmark/results.html)
+
+
+Performance of different validators by [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark):
+
+[](https://github.com/ebdrup/json-schema-benchmark/blob/master/README.md#performance)
+
+
+## Features
+
+- Ajv implements full JSON Schema [draft-06/07](http://json-schema.org/) and draft-04 standards:
+ - all validation keywords (see [JSON Schema validation keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md))
+ - full support of remote refs (remote schemas have to be added with `addSchema` or compiled to be available)
+ - support of circular references between schemas
+ - correct string lengths for strings with unicode pairs (can be turned off)
+ - [formats](#formats) defined by JSON Schema draft-07 standard and custom formats (can be turned off)
+ - [validates schemas against meta-schema](#api-validateschema)
+- supports [browsers](#using-in-browser) and Node.js 0.10-14.x
+- [asynchronous loading](#asynchronous-schema-compilation) of referenced schemas during compilation
+- "All errors" validation mode with [option allErrors](#options)
+- [error messages with parameters](#validation-errors) describing error reasons to allow creating custom error messages
+- i18n error messages support with [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) package
+- [filtering data](#filtering-data) from additional properties
+- [assigning defaults](#assigning-defaults) to missing properties and items
+- [coercing data](#coercing-data-types) to the types specified in `type` keywords
+- [custom keywords](#defining-custom-keywords)
+- draft-06/07 keywords `const`, `contains`, `propertyNames` and `if/then/else`
+- draft-06 boolean schemas (`true`/`false` as a schema to always pass/fail).
+- keywords `switch`, `patternRequired`, `formatMaximum` / `formatMinimum` and `formatExclusiveMaximum` / `formatExclusiveMinimum` from [JSON Schema extension proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) with [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package
+- [$data reference](#data-reference) to use values from the validated data as values for the schema keywords
+- [asynchronous validation](#asynchronous-validation) of custom formats and keywords
+
+
+## Install
+
+```
+npm install ajv
+```
+
+
+## Getting started
+
+Try it in the Node.js REPL: https://tonicdev.com/npm/ajv
+
+
+The fastest validation call:
+
+```javascript
+// Node.js require:
+var Ajv = require('ajv');
+// or ESM/TypeScript import
+import Ajv from 'ajv';
+
+var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true}
+var validate = ajv.compile(schema);
+var valid = validate(data);
+if (!valid) console.log(validate.errors);
+```
+
+or with less code
+
+```javascript
+// ...
+var valid = ajv.validate(schema, data);
+if (!valid) console.log(ajv.errors);
+// ...
+```
+
+or
+
+```javascript
+// ...
+var valid = ajv.addSchema(schema, 'mySchema')
+ .validate('mySchema', data);
+if (!valid) console.log(ajv.errorsText());
+// ...
+```
+
+See [API](#api) and [Options](#options) for more details.
+
+Ajv compiles schemas to functions and caches them in all cases (using schema serialized with [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) or a custom function as a key), so that the next time the same schema is used (not necessarily the same object instance) it won't be compiled again.
+
+The best performance is achieved when using compiled functions returned by `compile` or `getSchema` methods (there is no additional function call).
+
+__Please note__: every time a validation function or `ajv.validate` are called `errors` property is overwritten. You need to copy `errors` array reference to another variable if you want to use it later (e.g., in the callback). See [Validation errors](#validation-errors)
+
+__Note for TypeScript users__: `ajv` provides its own TypeScript declarations
+out of the box, so you don't need to install the deprecated `@types/ajv`
+module.
+
+
+## Using in browser
+
+You can require Ajv directly from the code you browserify - in this case Ajv will be a part of your bundle.
+
+If you need to use Ajv in several bundles you can create a separate UMD bundle using `npm run bundle` script (thanks to [siddo420](https://github.com/siddo420)).
+
+Then you need to load Ajv in the browser:
+```html
+
+```
+
+This bundle can be used with different module systems; it creates global `Ajv` if no module system is found.
+
+The browser bundle is available on [cdnjs](https://cdnjs.com/libraries/ajv).
+
+Ajv is tested with these browsers:
+
+[](https://saucelabs.com/u/epoberezkin)
+
+__Please note__: some frameworks, e.g. Dojo, may redefine global require in such way that is not compatible with CommonJS module format. In such case Ajv bundle has to be loaded before the framework and then you can use global Ajv (see issue [#234](https://github.com/ajv-validator/ajv/issues/234)).
+
+
+### Ajv and Content Security Policies (CSP)
+
+If you're using Ajv to compile a schema (the typical use) in a browser document that is loaded with a Content Security Policy (CSP), that policy will require a `script-src` directive that includes the value `'unsafe-eval'`.
+:warning: NOTE, however, that `unsafe-eval` is NOT recommended in a secure CSP[[1]](https://developer.chrome.com/extensions/contentSecurityPolicy#relaxing-eval), as it has the potential to open the document to cross-site scripting (XSS) attacks.
+
+In order to make use of Ajv without easing your CSP, you can [pre-compile a schema using the CLI](https://github.com/ajv-validator/ajv-cli#compile-schemas). This will transpile the schema JSON into a JavaScript file that exports a `validate` function that works simlarly to a schema compiled at runtime.
+
+Note that pre-compilation of schemas is performed using [ajv-pack](https://github.com/ajv-validator/ajv-pack) and there are [some limitations to the schema features it can compile](https://github.com/ajv-validator/ajv-pack#limitations). A successfully pre-compiled schema is equivalent to the same schema compiled at runtime.
+
+
+## Command line interface
+
+CLI is available as a separate npm package [ajv-cli](https://github.com/ajv-validator/ajv-cli). It supports:
+
+- compiling JSON Schemas to test their validity
+- BETA: generating standalone module exporting a validation function to be used without Ajv (using [ajv-pack](https://github.com/ajv-validator/ajv-pack))
+- migrate schemas to draft-07 (using [json-schema-migrate](https://github.com/epoberezkin/json-schema-migrate))
+- validating data file(s) against JSON Schema
+- testing expected validity of data against JSON Schema
+- referenced schemas
+- custom meta-schemas
+- files in JSON, JSON5, YAML, and JavaScript format
+- all Ajv options
+- reporting changes in data after validation in [JSON-patch](https://tools.ietf.org/html/rfc6902) format
+
+
+## Validation keywords
+
+Ajv supports all validation keywords from draft-07 of JSON Schema standard:
+
+- [type](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#type)
+- [for numbers](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-numbers) - maximum, minimum, exclusiveMaximum, exclusiveMinimum, multipleOf
+- [for strings](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-strings) - maxLength, minLength, pattern, format
+- [for arrays](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-arrays) - maxItems, minItems, uniqueItems, items, additionalItems, [contains](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#contains)
+- [for objects](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-objects) - maxProperties, minProperties, required, properties, patternProperties, additionalProperties, dependencies, [propertyNames](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#propertynames)
+- [for all types](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-all-types) - enum, [const](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#const)
+- [compound keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#compound-keywords) - not, oneOf, anyOf, allOf, [if/then/else](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#ifthenelse)
+
+With [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package Ajv also supports validation keywords from [JSON Schema extension proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) for JSON Schema standard:
+
+- [patternRequired](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#patternrequired-proposed) - like `required` but with patterns that some property should match.
+- [formatMaximum, formatMinimum, formatExclusiveMaximum, formatExclusiveMinimum](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#formatmaximum--formatminimum-and-exclusiveformatmaximum--exclusiveformatminimum-proposed) - setting limits for date, time, etc.
+
+See [JSON Schema validation keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md) for more details.
+
+
+## Annotation keywords
+
+JSON Schema specification defines several annotation keywords that describe schema itself but do not perform any validation.
+
+- `title` and `description`: information about the data represented by that schema
+- `$comment` (NEW in draft-07): information for developers. With option `$comment` Ajv logs or passes the comment string to the user-supplied function. See [Options](#options).
+- `default`: a default value of the data instance, see [Assigning defaults](#assigning-defaults).
+- `examples` (NEW in draft-06): an array of data instances. Ajv does not check the validity of these instances against the schema.
+- `readOnly` and `writeOnly` (NEW in draft-07): marks data-instance as read-only or write-only in relation to the source of the data (database, api, etc.).
+- `contentEncoding`: [RFC 2045](https://tools.ietf.org/html/rfc2045#section-6.1 ), e.g., "base64".
+- `contentMediaType`: [RFC 2046](https://tools.ietf.org/html/rfc2046), e.g., "image/png".
+
+__Please note__: Ajv does not implement validation of the keywords `examples`, `contentEncoding` and `contentMediaType` but it reserves them. If you want to create a plugin that implements some of them, it should remove these keywords from the instance.
+
+
+## Formats
+
+Ajv implements formats defined by JSON Schema specification and several other formats. It is recommended NOT to use "format" keyword implementations with untrusted data, as they use potentially unsafe regular expressions - see [ReDoS attack](#redos-attack).
+
+__Please note__: if you need to use "format" keyword to validate untrusted data, you MUST assess their suitability and safety for your validation scenarios.
+
+The following formats are implemented for string validation with "format" keyword:
+
+- _date_: full-date according to [RFC3339](http://tools.ietf.org/html/rfc3339#section-5.6).
+- _time_: time with optional time-zone.
+- _date-time_: date-time from the same source (time-zone is mandatory). `date`, `time` and `date-time` validate ranges in `full` mode and only regexp in `fast` mode (see [options](#options)).
+- _uri_: full URI.
+- _uri-reference_: URI reference, including full and relative URIs.
+- _uri-template_: URI template according to [RFC6570](https://tools.ietf.org/html/rfc6570)
+- _url_ (deprecated): [URL record](https://url.spec.whatwg.org/#concept-url).
+- _email_: email address.
+- _hostname_: host name according to [RFC1034](http://tools.ietf.org/html/rfc1034#section-3.5).
+- _ipv4_: IP address v4.
+- _ipv6_: IP address v6.
+- _regex_: tests whether a string is a valid regular expression by passing it to RegExp constructor.
+- _uuid_: Universally Unique IDentifier according to [RFC4122](http://tools.ietf.org/html/rfc4122).
+- _json-pointer_: JSON-pointer according to [RFC6901](https://tools.ietf.org/html/rfc6901).
+- _relative-json-pointer_: relative JSON-pointer according to [this draft](http://tools.ietf.org/html/draft-luff-relative-json-pointer-00).
+
+__Please note__: JSON Schema draft-07 also defines formats `iri`, `iri-reference`, `idn-hostname` and `idn-email` for URLs, hostnames and emails with international characters. Ajv does not implement these formats. If you create Ajv plugin that implements them please make a PR to mention this plugin here.
+
+There are two modes of format validation: `fast` and `full`. This mode affects formats `date`, `time`, `date-time`, `uri`, `uri-reference`, and `email`. See [Options](#options) for details.
+
+You can add additional formats and replace any of the formats above using [addFormat](#api-addformat) method.
+
+The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can allow specific format(s) that will be ignored. See [Options](#options) for details.
+
+You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js).
+
+
+## Combining schemas with $ref
+
+You can structure your validation logic across multiple schema files and have schemas reference each other using `$ref` keyword.
+
+Example:
+
+```javascript
+var schema = {
+ "$id": "http://example.com/schemas/schema.json",
+ "type": "object",
+ "properties": {
+ "foo": { "$ref": "defs.json#/definitions/int" },
+ "bar": { "$ref": "defs.json#/definitions/str" }
+ }
+};
+
+var defsSchema = {
+ "$id": "http://example.com/schemas/defs.json",
+ "definitions": {
+ "int": { "type": "integer" },
+ "str": { "type": "string" }
+ }
+};
+```
+
+Now to compile your schema you can either pass all schemas to Ajv instance:
+
+```javascript
+var ajv = new Ajv({schemas: [schema, defsSchema]});
+var validate = ajv.getSchema('http://example.com/schemas/schema.json');
+```
+
+or use `addSchema` method:
+
+```javascript
+var ajv = new Ajv;
+var validate = ajv.addSchema(defsSchema)
+ .compile(schema);
+```
+
+See [Options](#options) and [addSchema](#api) method.
+
+__Please note__:
+- `$ref` is resolved as the uri-reference using schema $id as the base URI (see the example).
+- References can be recursive (and mutually recursive) to implement the schemas for different data structures (such as linked lists, trees, graphs, etc.).
+- You don't have to host your schema files at the URIs that you use as schema $id. These URIs are only used to identify the schemas, and according to JSON Schema specification validators should not expect to be able to download the schemas from these URIs.
+- The actual location of the schema file in the file system is not used.
+- You can pass the identifier of the schema as the second parameter of `addSchema` method or as a property name in `schemas` option. This identifier can be used instead of (or in addition to) schema $id.
+- You cannot have the same $id (or the schema identifier) used for more than one schema - the exception will be thrown.
+- You can implement dynamic resolution of the referenced schemas using `compileAsync` method. In this way you can store schemas in any system (files, web, database, etc.) and reference them without explicitly adding to Ajv instance. See [Asynchronous schema compilation](#asynchronous-schema-compilation).
+
+
+## $data reference
+
+With `$data` option you can use values from the validated data as the values for the schema keywords. See [proposal](https://github.com/json-schema-org/json-schema-spec/issues/51) for more information about how it works.
+
+`$data` reference is supported in the keywords: const, enum, format, maximum/minimum, exclusiveMaximum / exclusiveMinimum, maxLength / minLength, maxItems / minItems, maxProperties / minProperties, formatMaximum / formatMinimum, formatExclusiveMaximum / formatExclusiveMinimum, multipleOf, pattern, required, uniqueItems.
+
+The value of "$data" should be a [JSON-pointer](https://tools.ietf.org/html/rfc6901) to the data (the root is always the top level data object, even if the $data reference is inside a referenced subschema) or a [relative JSON-pointer](http://tools.ietf.org/html/draft-luff-relative-json-pointer-00) (it is relative to the current point in data; if the $data reference is inside a referenced subschema it cannot point to the data outside of the root level for this subschema).
+
+Examples.
+
+This schema requires that the value in property `smaller` is less or equal than the value in the property larger:
+
+```javascript
+var ajv = new Ajv({$data: true});
+
+var schema = {
+ "properties": {
+ "smaller": {
+ "type": "number",
+ "maximum": { "$data": "1/larger" }
+ },
+ "larger": { "type": "number" }
+ }
+};
+
+var validData = {
+ smaller: 5,
+ larger: 7
+};
+
+ajv.validate(schema, validData); // true
+```
+
+This schema requires that the properties have the same format as their field names:
+
+```javascript
+var schema = {
+ "additionalProperties": {
+ "type": "string",
+ "format": { "$data": "0#" }
+ }
+};
+
+var validData = {
+ 'date-time': '1963-06-19T08:30:06.283185Z',
+ email: 'joe.bloggs@example.com'
+}
+```
+
+`$data` reference is resolved safely - it won't throw even if some property is undefined. If `$data` resolves to `undefined` the validation succeeds (with the exclusion of `const` keyword). If `$data` resolves to incorrect type (e.g. not "number" for maximum keyword) the validation fails.
+
+
+## $merge and $patch keywords
+
+With the package [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) you can use the keywords `$merge` and `$patch` that allow extending JSON Schemas with patches using formats [JSON Merge Patch (RFC 7396)](https://tools.ietf.org/html/rfc7396) and [JSON Patch (RFC 6902)](https://tools.ietf.org/html/rfc6902).
+
+To add keywords `$merge` and `$patch` to Ajv instance use this code:
+
+```javascript
+require('ajv-merge-patch')(ajv);
+```
+
+Examples.
+
+Using `$merge`:
+
+```json
+{
+ "$merge": {
+ "source": {
+ "type": "object",
+ "properties": { "p": { "type": "string" } },
+ "additionalProperties": false
+ },
+ "with": {
+ "properties": { "q": { "type": "number" } }
+ }
+ }
+}
+```
+
+Using `$patch`:
+
+```json
+{
+ "$patch": {
+ "source": {
+ "type": "object",
+ "properties": { "p": { "type": "string" } },
+ "additionalProperties": false
+ },
+ "with": [
+ { "op": "add", "path": "/properties/q", "value": { "type": "number" } }
+ ]
+ }
+}
+```
+
+The schemas above are equivalent to this schema:
+
+```json
+{
+ "type": "object",
+ "properties": {
+ "p": { "type": "string" },
+ "q": { "type": "number" }
+ },
+ "additionalProperties": false
+}
+```
+
+The properties `source` and `with` in the keywords `$merge` and `$patch` can use absolute or relative `$ref` to point to other schemas previously added to the Ajv instance or to the fragments of the current schema.
+
+See the package [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) for more information.
+
+
+## Defining custom keywords
+
+The advantages of using custom keywords are:
+
+- allow creating validation scenarios that cannot be expressed using JSON Schema
+- simplify your schemas
+- help bringing a bigger part of the validation logic to your schemas
+- make your schemas more expressive, less verbose and closer to your application domain
+- implement custom data processors that modify your data (`modifying` option MUST be used in keyword definition) and/or create side effects while the data is being validated
+
+If a keyword is used only for side-effects and its validation result is pre-defined, use option `valid: true/false` in keyword definition to simplify both generated code (no error handling in case of `valid: true`) and your keyword functions (no need to return any validation result).
+
+The concerns you have to be aware of when extending JSON Schema standard with custom keywords are the portability and understanding of your schemas. You will have to support these custom keywords on other platforms and to properly document these keywords so that everybody can understand them in your schemas.
+
+You can define custom keywords with [addKeyword](#api-addkeyword) method. Keywords are defined on the `ajv` instance level - new instances will not have previously defined keywords.
+
+Ajv allows defining keywords with:
+- validation function
+- compilation function
+- macro function
+- inline compilation function that should return code (as string) that will be inlined in the currently compiled schema.
+
+Example. `range` and `exclusiveRange` keywords using compiled schema:
+
+```javascript
+ajv.addKeyword('range', {
+ type: 'number',
+ compile: function (sch, parentSchema) {
+ var min = sch[0];
+ var max = sch[1];
+
+ return parentSchema.exclusiveRange === true
+ ? function (data) { return data > min && data < max; }
+ : function (data) { return data >= min && data <= max; }
+ }
+});
+
+var schema = { "range": [2, 4], "exclusiveRange": true };
+var validate = ajv.compile(schema);
+console.log(validate(2.01)); // true
+console.log(validate(3.99)); // true
+console.log(validate(2)); // false
+console.log(validate(4)); // false
+```
+
+Several custom keywords (typeof, instanceof, range and propertyNames) are defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package - they can be used for your schemas and as a starting point for your own custom keywords.
+
+See [Defining custom keywords](https://github.com/ajv-validator/ajv/blob/master/CUSTOM.md) for more details.
+
+
+## Asynchronous schema compilation
+
+During asynchronous compilation remote references are loaded using supplied function. See `compileAsync` [method](#api-compileAsync) and `loadSchema` [option](#options).
+
+Example:
+
+```javascript
+var ajv = new Ajv({ loadSchema: loadSchema });
+
+ajv.compileAsync(schema).then(function (validate) {
+ var valid = validate(data);
+ // ...
+});
+
+function loadSchema(uri) {
+ return request.json(uri).then(function (res) {
+ if (res.statusCode >= 400)
+ throw new Error('Loading error: ' + res.statusCode);
+ return res.body;
+ });
+}
+```
+
+__Please note__: [Option](#options) `missingRefs` should NOT be set to `"ignore"` or `"fail"` for asynchronous compilation to work.
+
+
+## Asynchronous validation
+
+Example in Node.js REPL: https://tonicdev.com/esp/ajv-asynchronous-validation
+
+You can define custom formats and keywords that perform validation asynchronously by accessing database or some other service. You should add `async: true` in the keyword or format definition (see [addFormat](#api-addformat), [addKeyword](#api-addkeyword) and [Defining custom keywords](#defining-custom-keywords)).
+
+If your schema uses asynchronous formats/keywords or refers to some schema that contains them it should have `"$async": true` keyword so that Ajv can compile it correctly. If asynchronous format/keyword or reference to asynchronous schema is used in the schema without `$async` keyword Ajv will throw an exception during schema compilation.
+
+__Please note__: all asynchronous subschemas that are referenced from the current or other schemas should have `"$async": true` keyword as well, otherwise the schema compilation will fail.
+
+Validation function for an asynchronous custom format/keyword should return a promise that resolves with `true` or `false` (or rejects with `new Ajv.ValidationError(errors)` if you want to return custom errors from the keyword function).
+
+Ajv compiles asynchronous schemas to [es7 async functions](http://tc39.github.io/ecmascript-asyncawait/) that can optionally be transpiled with [nodent](https://github.com/MatAtBread/nodent). Async functions are supported in Node.js 7+ and all modern browsers. You can also supply any other transpiler as a function via `processCode` option. See [Options](#options).
+
+The compiled validation function has `$async: true` property (if the schema is asynchronous), so you can differentiate these functions if you are using both synchronous and asynchronous schemas.
+
+Validation result will be a promise that resolves with validated data or rejects with an exception `Ajv.ValidationError` that contains the array of validation errors in `errors` property.
+
+
+Example:
+
+```javascript
+var ajv = new Ajv;
+// require('ajv-async')(ajv);
+
+ajv.addKeyword('idExists', {
+ async: true,
+ type: 'number',
+ validate: checkIdExists
+});
+
+
+function checkIdExists(schema, data) {
+ return knex(schema.table)
+ .select('id')
+ .where('id', data)
+ .then(function (rows) {
+ return !!rows.length; // true if record is found
+ });
+}
+
+var schema = {
+ "$async": true,
+ "properties": {
+ "userId": {
+ "type": "integer",
+ "idExists": { "table": "users" }
+ },
+ "postId": {
+ "type": "integer",
+ "idExists": { "table": "posts" }
+ }
+ }
+};
+
+var validate = ajv.compile(schema);
+
+validate({ userId: 1, postId: 19 })
+.then(function (data) {
+ console.log('Data is valid', data); // { userId: 1, postId: 19 }
+})
+.catch(function (err) {
+ if (!(err instanceof Ajv.ValidationError)) throw err;
+ // data is invalid
+ console.log('Validation errors:', err.errors);
+});
+```
+
+### Using transpilers with asynchronous validation functions.
+
+[ajv-async](https://github.com/ajv-validator/ajv-async) uses [nodent](https://github.com/MatAtBread/nodent) to transpile async functions. To use another transpiler you should separately install it (or load its bundle in the browser).
+
+
+#### Using nodent
+
+```javascript
+var ajv = new Ajv;
+require('ajv-async')(ajv);
+// in the browser if you want to load ajv-async bundle separately you can:
+// window.ajvAsync(ajv);
+var validate = ajv.compile(schema); // transpiled es7 async function
+validate(data).then(successFunc).catch(errorFunc);
+```
+
+
+#### Using other transpilers
+
+```javascript
+var ajv = new Ajv({ processCode: transpileFunc });
+var validate = ajv.compile(schema); // transpiled es7 async function
+validate(data).then(successFunc).catch(errorFunc);
+```
+
+See [Options](#options).
+
+
+## Security considerations
+
+JSON Schema, if properly used, can replace data sanitisation. It doesn't replace other API security considerations. It also introduces additional security aspects to consider.
+
+
+##### Security contact
+
+To report a security vulnerability, please use the
+[Tidelift security contact](https://tidelift.com/security).
+Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerabilities via GitHub issues.
+
+
+##### Untrusted schemas
+
+Ajv treats JSON schemas as trusted as your application code. This security model is based on the most common use case, when the schemas are static and bundled together with the application.
+
+If your schemas are received from untrusted sources (or generated from untrusted data) there are several scenarios you need to prevent:
+- compiling schemas can cause stack overflow (if they are too deep)
+- compiling schemas can be slow (e.g. [#557](https://github.com/ajv-validator/ajv/issues/557))
+- validating certain data can be slow
+
+It is difficult to predict all the scenarios, but at the very least it may help to limit the size of untrusted schemas (e.g. limit JSON string length) and also the maximum schema object depth (that can be high for relatively small JSON strings). You also may want to mitigate slow regular expressions in `pattern` and `patternProperties` keywords.
+
+Regardless the measures you take, using untrusted schemas increases security risks.
+
+
+##### Circular references in JavaScript objects
+
+Ajv does not support schemas and validated data that have circular references in objects. See [issue #802](https://github.com/ajv-validator/ajv/issues/802).
+
+An attempt to compile such schemas or validate such data would cause stack overflow (or will not complete in case of asynchronous validation). Depending on the parser you use, untrusted data can lead to circular references.
+
+
+##### Security risks of trusted schemas
+
+Some keywords in JSON Schemas can lead to very slow validation for certain data. These keywords include (but may be not limited to):
+
+- `pattern` and `format` for large strings - in some cases using `maxLength` can help mitigate it, but certain regular expressions can lead to exponential validation time even with relatively short strings (see [ReDoS attack](#redos-attack)).
+- `patternProperties` for large property names - use `propertyNames` to mitigate, but some regular expressions can have exponential evaluation time as well.
+- `uniqueItems` for large non-scalar arrays - use `maxItems` to mitigate
+
+__Please note__: The suggestions above to prevent slow validation would only work if you do NOT use `allErrors: true` in production code (using it would continue validation after validation errors).
+
+You can validate your JSON schemas against [this meta-schema](https://github.com/ajv-validator/ajv/blob/master/lib/refs/json-schema-secure.json) to check that these recommendations are followed:
+
+```javascript
+const isSchemaSecure = ajv.compile(require('ajv/lib/refs/json-schema-secure.json'));
+
+const schema1 = {format: 'email'};
+isSchemaSecure(schema1); // false
+
+const schema2 = {format: 'email', maxLength: MAX_LENGTH};
+isSchemaSecure(schema2); // true
+```
+
+__Please note__: following all these recommendation is not a guarantee that validation of untrusted data is safe - it can still lead to some undesirable results.
+
+
+##### Content Security Policies (CSP)
+See [Ajv and Content Security Policies (CSP)](#ajv-and-content-security-policies-csp)
+
+
+## ReDoS attack
+
+Certain regular expressions can lead to the exponential evaluation time even with relatively short strings.
+
+Please assess the regular expressions you use in the schemas on their vulnerability to this attack - see [safe-regex](https://github.com/substack/safe-regex), for example.
+
+__Please note__: some formats that Ajv implements use [regular expressions](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js) that can be vulnerable to ReDoS attack, so if you use Ajv to validate data from untrusted sources __it is strongly recommended__ to consider the following:
+
+- making assessment of "format" implementations in Ajv.
+- using `format: 'fast'` option that simplifies some of the regular expressions (although it does not guarantee that they are safe).
+- replacing format implementations provided by Ajv with your own implementations of "format" keyword that either uses different regular expressions or another approach to format validation. Please see [addFormat](#api-addformat) method.
+- disabling format validation by ignoring "format" keyword with option `format: false`
+
+Whatever mitigation you choose, please assume all formats provided by Ajv as potentially unsafe and make your own assessment of their suitability for your validation scenarios.
+
+
+## Filtering data
+
+With [option `removeAdditional`](#options) (added by [andyscott](https://github.com/andyscott)) you can filter data during the validation.
+
+This option modifies original data.
+
+Example:
+
+```javascript
+var ajv = new Ajv({ removeAdditional: true });
+var schema = {
+ "additionalProperties": false,
+ "properties": {
+ "foo": { "type": "number" },
+ "bar": {
+ "additionalProperties": { "type": "number" },
+ "properties": {
+ "baz": { "type": "string" }
+ }
+ }
+ }
+}
+
+var data = {
+ "foo": 0,
+ "additional1": 1, // will be removed; `additionalProperties` == false
+ "bar": {
+ "baz": "abc",
+ "additional2": 2 // will NOT be removed; `additionalProperties` != false
+ },
+}
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // { "foo": 0, "bar": { "baz": "abc", "additional2": 2 }
+```
+
+If `removeAdditional` option in the example above were `"all"` then both `additional1` and `additional2` properties would have been removed.
+
+If the option were `"failing"` then property `additional1` would have been removed regardless of its value and property `additional2` would have been removed only if its value were failing the schema in the inner `additionalProperties` (so in the example above it would have stayed because it passes the schema, but any non-number would have been removed).
+
+__Please note__: If you use `removeAdditional` option with `additionalProperties` keyword inside `anyOf`/`oneOf` keywords your validation can fail with this schema, for example:
+
+```json
+{
+ "type": "object",
+ "oneOf": [
+ {
+ "properties": {
+ "foo": { "type": "string" }
+ },
+ "required": [ "foo" ],
+ "additionalProperties": false
+ },
+ {
+ "properties": {
+ "bar": { "type": "integer" }
+ },
+ "required": [ "bar" ],
+ "additionalProperties": false
+ }
+ ]
+}
+```
+
+The intention of the schema above is to allow objects with either the string property "foo" or the integer property "bar", but not with both and not with any other properties.
+
+With the option `removeAdditional: true` the validation will pass for the object `{ "foo": "abc"}` but will fail for the object `{"bar": 1}`. It happens because while the first subschema in `oneOf` is validated, the property `bar` is removed because it is an additional property according to the standard (because it is not included in `properties` keyword in the same schema).
+
+While this behaviour is unexpected (issues [#129](https://github.com/ajv-validator/ajv/issues/129), [#134](https://github.com/ajv-validator/ajv/issues/134)), it is correct. To have the expected behaviour (both objects are allowed and additional properties are removed) the schema has to be refactored in this way:
+
+```json
+{
+ "type": "object",
+ "properties": {
+ "foo": { "type": "string" },
+ "bar": { "type": "integer" }
+ },
+ "additionalProperties": false,
+ "oneOf": [
+ { "required": [ "foo" ] },
+ { "required": [ "bar" ] }
+ ]
+}
+```
+
+The schema above is also more efficient - it will compile into a faster function.
+
+
+## Assigning defaults
+
+With [option `useDefaults`](#options) Ajv will assign values from `default` keyword in the schemas of `properties` and `items` (when it is the array of schemas) to the missing properties and items.
+
+With the option value `"empty"` properties and items equal to `null` or `""` (empty string) will be considered missing and assigned defaults.
+
+This option modifies original data.
+
+__Please note__: the default value is inserted in the generated validation code as a literal, so the value inserted in the data will be the deep clone of the default in the schema.
+
+
+Example 1 (`default` in `properties`):
+
+```javascript
+var ajv = new Ajv({ useDefaults: true });
+var schema = {
+ "type": "object",
+ "properties": {
+ "foo": { "type": "number" },
+ "bar": { "type": "string", "default": "baz" }
+ },
+ "required": [ "foo", "bar" ]
+};
+
+var data = { "foo": 1 };
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // { "foo": 1, "bar": "baz" }
+```
+
+Example 2 (`default` in `items`):
+
+```javascript
+var schema = {
+ "type": "array",
+ "items": [
+ { "type": "number" },
+ { "type": "string", "default": "foo" }
+ ]
+}
+
+var data = [ 1 ];
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // [ 1, "foo" ]
+```
+
+`default` keywords in other cases are ignored:
+
+- not in `properties` or `items` subschemas
+- in schemas inside `anyOf`, `oneOf` and `not` (see [#42](https://github.com/ajv-validator/ajv/issues/42))
+- in `if` subschema of `switch` keyword
+- in schemas generated by custom macro keywords
+
+The [`strictDefaults` option](#options) customizes Ajv's behavior for the defaults that Ajv ignores (`true` raises an error, and `"log"` outputs a warning).
+
+
+## Coercing data types
+
+When you are validating user inputs all your data properties are usually strings. The option `coerceTypes` allows you to have your data types coerced to the types specified in your schema `type` keywords, both to pass the validation and to use the correctly typed data afterwards.
+
+This option modifies original data.
+
+__Please note__: if you pass a scalar value to the validating function its type will be coerced and it will pass the validation, but the value of the variable you pass won't be updated because scalars are passed by value.
+
+
+Example 1:
+
+```javascript
+var ajv = new Ajv({ coerceTypes: true });
+var schema = {
+ "type": "object",
+ "properties": {
+ "foo": { "type": "number" },
+ "bar": { "type": "boolean" }
+ },
+ "required": [ "foo", "bar" ]
+};
+
+var data = { "foo": "1", "bar": "false" };
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // { "foo": 1, "bar": false }
+```
+
+Example 2 (array coercions):
+
+```javascript
+var ajv = new Ajv({ coerceTypes: 'array' });
+var schema = {
+ "properties": {
+ "foo": { "type": "array", "items": { "type": "number" } },
+ "bar": { "type": "boolean" }
+ }
+};
+
+var data = { "foo": "1", "bar": ["false"] };
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // { "foo": [1], "bar": false }
+```
+
+The coercion rules, as you can see from the example, are different from JavaScript both to validate user input as expected and to have the coercion reversible (to correctly validate cases where different types are defined in subschemas of "anyOf" and other compound keywords).
+
+See [Coercion rules](https://github.com/ajv-validator/ajv/blob/master/COERCION.md) for details.
+
+
+## API
+
+##### new Ajv(Object options) -> Object
+
+Create Ajv instance.
+
+
+##### .compile(Object schema) -> Function<Object data>
+
+Generate validating function and cache the compiled schema for future use.
+
+Validating function returns a boolean value. This function has properties `errors` and `schema`. Errors encountered during the last validation are assigned to `errors` property (it is assigned `null` if there was no errors). `schema` property contains the reference to the original schema.
+
+The schema passed to this method will be validated against meta-schema unless `validateSchema` option is false. If schema is invalid, an error will be thrown. See [options](#options).
+
+
+##### .compileAsync(Object schema [, Boolean meta] [, Function callback]) -> Promise
+
+Asynchronous version of `compile` method that loads missing remote schemas using asynchronous function in `options.loadSchema`. This function returns a Promise that resolves to a validation function. An optional callback passed to `compileAsync` will be called with 2 parameters: error (or null) and validating function. The returned promise will reject (and the callback will be called with an error) when:
+
+- missing schema can't be loaded (`loadSchema` returns a Promise that rejects).
+- a schema containing a missing reference is loaded, but the reference cannot be resolved.
+- schema (or some loaded/referenced schema) is invalid.
+
+The function compiles schema and loads the first missing schema (or meta-schema) until all missing schemas are loaded.
+
+You can asynchronously compile meta-schema by passing `true` as the second parameter.
+
+See example in [Asynchronous compilation](#asynchronous-schema-compilation).
+
+
+##### .validate(Object schema|String key|String ref, data) -> Boolean
+
+Validate data using passed schema (it will be compiled and cached).
+
+Instead of the schema you can use the key that was previously passed to `addSchema`, the schema id if it was present in the schema or any previously resolved reference.
+
+Validation errors will be available in the `errors` property of Ajv instance (`null` if there were no errors).
+
+__Please note__: every time this method is called the errors are overwritten so you need to copy them to another variable if you want to use them later.
+
+If the schema is asynchronous (has `$async` keyword on the top level) this method returns a Promise. See [Asynchronous validation](#asynchronous-validation).
+
+
+##### .addSchema(Array<Object>|Object schema [, String key]) -> Ajv
+
+Add schema(s) to validator instance. This method does not compile schemas (but it still validates them). Because of that dependencies can be added in any order and circular dependencies are supported. It also prevents unnecessary compilation of schemas that are containers for other schemas but not used as a whole.
+
+Array of schemas can be passed (schemas should have ids), the second parameter will be ignored.
+
+Key can be passed that can be used to reference the schema and will be used as the schema id if there is no id inside the schema. If the key is not passed, the schema id will be used as the key.
+
+
+Once the schema is added, it (and all the references inside it) can be referenced in other schemas and used to validate data.
+
+Although `addSchema` does not compile schemas, explicit compilation is not required - the schema will be compiled when it is used first time.
+
+By default the schema is validated against meta-schema before it is added, and if the schema does not pass validation the exception is thrown. This behaviour is controlled by `validateSchema` option.
+
+__Please note__: Ajv uses the [method chaining syntax](https://en.wikipedia.org/wiki/Method_chaining) for all methods with the prefix `add*` and `remove*`.
+This allows you to do nice things like the following.
+
+```javascript
+var validate = new Ajv().addSchema(schema).addFormat(name, regex).getSchema(uri);
+```
+
+##### .addMetaSchema(Array<Object>|Object schema [, String key]) -> Ajv
+
+Adds meta schema(s) that can be used to validate other schemas. That function should be used instead of `addSchema` because there may be instance options that would compile a meta schema incorrectly (at the moment it is `removeAdditional` option).
+
+There is no need to explicitly add draft-07 meta schema (http://json-schema.org/draft-07/schema) - it is added by default, unless option `meta` is set to `false`. You only need to use it if you have a changed meta-schema that you want to use to validate your schemas. See `validateSchema`.
+
+
+##### .validateSchema(Object schema) -> Boolean
+
+Validates schema. This method should be used to validate schemas rather than `validate` due to the inconsistency of `uri` format in JSON Schema standard.
+
+By default this method is called automatically when the schema is added, so you rarely need to use it directly.
+
+If schema doesn't have `$schema` property, it is validated against draft 6 meta-schema (option `meta` should not be false).
+
+If schema has `$schema` property, then the schema with this id (that should be previously added) is used to validate passed schema.
+
+Errors will be available at `ajv.errors`.
+
+
+##### .getSchema(String key) -> Function<Object data>
+
+Retrieve compiled schema previously added with `addSchema` by the key passed to `addSchema` or by its full reference (id). The returned validating function has `schema` property with the reference to the original schema.
+
+
+##### .removeSchema([Object schema|String key|String ref|RegExp pattern]) -> Ajv
+
+Remove added/cached schema. Even if schema is referenced by other schemas it can be safely removed as dependent schemas have local references.
+
+Schema can be removed using:
+- key passed to `addSchema`
+- it's full reference (id)
+- RegExp that should match schema id or key (meta-schemas won't be removed)
+- actual schema object that will be stable-stringified to remove schema from cache
+
+If no parameter is passed all schemas but meta-schemas will be removed and the cache will be cleared.
+
+
+##### .addFormat(String name, String|RegExp|Function|Object format) -> Ajv
+
+Add custom format to validate strings or numbers. It can also be used to replace pre-defined formats for Ajv instance.
+
+Strings are converted to RegExp.
+
+Function should return validation result as `true` or `false`.
+
+If object is passed it should have properties `validate`, `compare` and `async`:
+
+- _validate_: a string, RegExp or a function as described above.
+- _compare_: an optional comparison function that accepts two strings and compares them according to the format meaning. This function is used with keywords `formatMaximum`/`formatMinimum` (defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package). It should return `1` if the first value is bigger than the second value, `-1` if it is smaller and `0` if it is equal.
+- _async_: an optional `true` value if `validate` is an asynchronous function; in this case it should return a promise that resolves with a value `true` or `false`.
+- _type_: an optional type of data that the format applies to. It can be `"string"` (default) or `"number"` (see https://github.com/ajv-validator/ajv/issues/291#issuecomment-259923858). If the type of data is different, the validation will pass.
+
+Custom formats can be also added via `formats` option.
+
+
+##### .addKeyword(String keyword, Object definition) -> Ajv
+
+Add custom validation keyword to Ajv instance.
+
+Keyword should be different from all standard JSON Schema keywords and different from previously defined keywords. There is no way to redefine keywords or to remove keyword definition from the instance.
+
+Keyword must start with a letter, `_` or `$`, and may continue with letters, numbers, `_`, `$`, or `-`.
+It is recommended to use an application-specific prefix for keywords to avoid current and future name collisions.
+
+Example Keywords:
+- `"xyz-example"`: valid, and uses prefix for the xyz project to avoid name collisions.
+- `"example"`: valid, but not recommended as it could collide with future versions of JSON Schema etc.
+- `"3-example"`: invalid as numbers are not allowed to be the first character in a keyword
+
+Keyword definition is an object with the following properties:
+
+- _type_: optional string or array of strings with data type(s) that the keyword applies to. If not present, the keyword will apply to all types.
+- _validate_: validating function
+- _compile_: compiling function
+- _macro_: macro function
+- _inline_: compiling function that returns code (as string)
+- _schema_: an optional `false` value used with "validate" keyword to not pass schema
+- _metaSchema_: an optional meta-schema for keyword schema
+- _dependencies_: an optional list of properties that must be present in the parent schema - it will be checked during schema compilation
+- _modifying_: `true` MUST be passed if keyword modifies data
+- _statements_: `true` can be passed in case inline keyword generates statements (as opposed to expression)
+- _valid_: pass `true`/`false` to pre-define validation result, the result returned from validation function will be ignored. This option cannot be used with macro keywords.
+- _$data_: an optional `true` value to support [$data reference](#data-reference) as the value of custom keyword. The reference will be resolved at validation time. If the keyword has meta-schema it would be extended to allow $data and it will be used to validate the resolved value. Supporting $data reference requires that keyword has validating function (as the only option or in addition to compile, macro or inline function).
+- _async_: an optional `true` value if the validation function is asynchronous (whether it is compiled or passed in _validate_ property); in this case it should return a promise that resolves with a value `true` or `false`. This option is ignored in case of "macro" and "inline" keywords.
+- _errors_: an optional boolean or string `"full"` indicating whether keyword returns errors. If this property is not set Ajv will determine if the errors were set in case of failed validation.
+
+_compile_, _macro_ and _inline_ are mutually exclusive, only one should be used at a time. _validate_ can be used separately or in addition to them to support $data reference.
+
+__Please note__: If the keyword is validating data type that is different from the type(s) in its definition, the validation function will not be called (and expanded macro will not be used), so there is no need to check for data type inside validation function or inside schema returned by macro function (unless you want to enforce a specific type and for some reason do not want to use a separate `type` keyword for that). In the same way as standard keywords work, if the keyword does not apply to the data type being validated, the validation of this keyword will succeed.
+
+See [Defining custom keywords](#defining-custom-keywords) for more details.
+
+
+##### .getKeyword(String keyword) -> Object|Boolean
+
+Returns custom keyword definition, `true` for pre-defined keywords and `false` if the keyword is unknown.
+
+
+##### .removeKeyword(String keyword) -> Ajv
+
+Removes custom or pre-defined keyword so you can redefine them.
+
+While this method can be used to extend pre-defined keywords, it can also be used to completely change their meaning - it may lead to unexpected results.
+
+__Please note__: schemas compiled before the keyword is removed will continue to work without changes. To recompile schemas use `removeSchema` method and compile them again.
+
+
+##### .errorsText([Array<Object> errors [, Object options]]) -> String
+
+Returns the text with all errors in a String.
+
+Options can have properties `separator` (string used to separate errors, ", " by default) and `dataVar` (the variable name that dataPaths are prefixed with, "data" by default).
+
+
+## Options
+
+Defaults:
+
+```javascript
+{
+ // validation and reporting options:
+ $data: false,
+ allErrors: false,
+ verbose: false,
+ $comment: false, // NEW in Ajv version 6.0
+ jsonPointers: false,
+ uniqueItems: true,
+ unicode: true,
+ nullable: false,
+ format: 'fast',
+ formats: {},
+ unknownFormats: true,
+ schemas: {},
+ logger: undefined,
+ // referenced schema options:
+ schemaId: '$id',
+ missingRefs: true,
+ extendRefs: 'ignore', // recommended 'fail'
+ loadSchema: undefined, // function(uri: string): Promise {}
+ // options to modify validated data:
+ removeAdditional: false,
+ useDefaults: false,
+ coerceTypes: false,
+ // strict mode options
+ strictDefaults: false,
+ strictKeywords: false,
+ strictNumbers: false,
+ // asynchronous validation options:
+ transpile: undefined, // requires ajv-async package
+ // advanced options:
+ meta: true,
+ validateSchema: true,
+ addUsedSchema: true,
+ inlineRefs: true,
+ passContext: false,
+ loopRequired: Infinity,
+ ownProperties: false,
+ multipleOfPrecision: false,
+ errorDataPath: 'object', // deprecated
+ messages: true,
+ sourceCode: false,
+ processCode: undefined, // function (str: string, schema: object): string {}
+ cache: new Cache,
+ serialize: undefined
+}
+```
+
+##### Validation and reporting options
+
+- _$data_: support [$data references](#data-reference). Draft 6 meta-schema that is added by default will be extended to allow them. If you want to use another meta-schema you need to use $dataMetaSchema method to add support for $data reference. See [API](#api).
+- _allErrors_: check all rules collecting all errors. Default is to return after the first error.
+- _verbose_: include the reference to the part of the schema (`schema` and `parentSchema`) and validated data in errors (false by default).
+- _$comment_ (NEW in Ajv version 6.0): log or pass the value of `$comment` keyword to a function. Option values:
+ - `false` (default): ignore $comment keyword.
+ - `true`: log the keyword value to console.
+ - function: pass the keyword value, its schema path and root schema to the specified function
+- _jsonPointers_: set `dataPath` property of errors using [JSON Pointers](https://tools.ietf.org/html/rfc6901) instead of JavaScript property access notation.
+- _uniqueItems_: validate `uniqueItems` keyword (true by default).
+- _unicode_: calculate correct length of strings with unicode pairs (true by default). Pass `false` to use `.length` of strings that is faster, but gives "incorrect" lengths of strings with unicode pairs - each unicode pair is counted as two characters.
+- _nullable_: support keyword "nullable" from [Open API 3 specification](https://swagger.io/docs/specification/data-models/data-types/).
+- _format_: formats validation mode. Option values:
+ - `"fast"` (default) - simplified and fast validation (see [Formats](#formats) for details of which formats are available and affected by this option).
+ - `"full"` - more restrictive and slow validation. E.g., 25:00:00 and 2015/14/33 will be invalid time and date in 'full' mode but it will be valid in 'fast' mode.
+ - `false` - ignore all format keywords.
+- _formats_: an object with custom formats. Keys and values will be passed to `addFormat` method.
+- _keywords_: an object with custom keywords. Keys and values will be passed to `addKeyword` method.
+- _unknownFormats_: handling of unknown formats. Option values:
+ - `true` (default) - if an unknown format is encountered the exception is thrown during schema compilation. If `format` keyword value is [$data reference](#data-reference) and it is unknown the validation will fail.
+ - `[String]` - an array of unknown format names that will be ignored. This option can be used to allow usage of third party schemas with format(s) for which you don't have definitions, but still fail if another unknown format is used. If `format` keyword value is [$data reference](#data-reference) and it is not in this array the validation will fail.
+ - `"ignore"` - to log warning during schema compilation and always pass validation (the default behaviour in versions before 5.0.0). This option is not recommended, as it allows to mistype format name and it won't be validated without any error message. This behaviour is required by JSON Schema specification.
+- _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object.
+- _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. See [Error logging](#error-logging). Option values:
+ - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown.
+ - `false` - logging is disabled.
+
+
+##### Referenced schema options
+
+- _schemaId_: this option defines which keywords are used as schema URI. Option value:
+ - `"$id"` (default) - only use `$id` keyword as schema URI (as specified in JSON Schema draft-06/07), ignore `id` keyword (if it is present a warning will be logged).
+ - `"id"` - only use `id` keyword as schema URI (as specified in JSON Schema draft-04), ignore `$id` keyword (if it is present a warning will be logged).
+ - `"auto"` - use both `$id` and `id` keywords as schema URI. If both are present (in the same schema object) and different the exception will be thrown during schema compilation.
+- _missingRefs_: handling of missing referenced schemas. Option values:
+ - `true` (default) - if the reference cannot be resolved during compilation the exception is thrown. The thrown error has properties `missingRef` (with hash fragment) and `missingSchema` (without it). Both properties are resolved relative to the current base id (usually schema id, unless it was substituted).
+ - `"ignore"` - to log error during compilation and always pass validation.
+ - `"fail"` - to log error and successfully compile schema but fail validation if this rule is checked.
+- _extendRefs_: validation of other keywords when `$ref` is present in the schema. Option values:
+ - `"ignore"` (default) - when `$ref` is used other keywords are ignored (as per [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03#section-3) standard). A warning will be logged during the schema compilation.
+ - `"fail"` (recommended) - if other validation keywords are used together with `$ref` the exception will be thrown when the schema is compiled. This option is recommended to make sure schema has no keywords that are ignored, which can be confusing.
+ - `true` - validate all keywords in the schemas with `$ref` (the default behaviour in versions before 5.0.0).
+- _loadSchema_: asynchronous function that will be used to load remote schemas when `compileAsync` [method](#api-compileAsync) is used and some reference is missing (option `missingRefs` should NOT be 'fail' or 'ignore'). This function should accept remote schema uri as a parameter and return a Promise that resolves to a schema. See example in [Asynchronous compilation](#asynchronous-schema-compilation).
+
+
+##### Options to modify validated data
+
+- _removeAdditional_: remove additional properties - see example in [Filtering data](#filtering-data). This option is not used if schema is added with `addMetaSchema` method. Option values:
+ - `false` (default) - not to remove additional properties
+ - `"all"` - all additional properties are removed, regardless of `additionalProperties` keyword in schema (and no validation is made for them).
+ - `true` - only additional properties with `additionalProperties` keyword equal to `false` are removed.
+ - `"failing"` - additional properties that fail schema validation will be removed (where `additionalProperties` keyword is `false` or schema).
+- _useDefaults_: replace missing or undefined properties and items with the values from corresponding `default` keywords. Default behaviour is to ignore `default` keywords. This option is not used if schema is added with `addMetaSchema` method. See examples in [Assigning defaults](#assigning-defaults). Option values:
+ - `false` (default) - do not use defaults
+ - `true` - insert defaults by value (object literal is used).
+ - `"empty"` - in addition to missing or undefined, use defaults for properties and items that are equal to `null` or `""` (an empty string).
+ - `"shared"` (deprecated) - insert defaults by reference. If the default is an object, it will be shared by all instances of validated data. If you modify the inserted default in the validated data, it will be modified in the schema as well.
+- _coerceTypes_: change data type of data to match `type` keyword. See the example in [Coercing data types](#coercing-data-types) and [coercion rules](https://github.com/ajv-validator/ajv/blob/master/COERCION.md). Option values:
+ - `false` (default) - no type coercion.
+ - `true` - coerce scalar data types.
+ - `"array"` - in addition to coercions between scalar types, coerce scalar data to an array with one element and vice versa (as required by the schema).
+
+
+##### Strict mode options
+
+- _strictDefaults_: report ignored `default` keywords in schemas. Option values:
+ - `false` (default) - ignored defaults are not reported
+ - `true` - if an ignored default is present, throw an error
+ - `"log"` - if an ignored default is present, log warning
+- _strictKeywords_: report unknown keywords in schemas. Option values:
+ - `false` (default) - unknown keywords are not reported
+ - `true` - if an unknown keyword is present, throw an error
+ - `"log"` - if an unknown keyword is present, log warning
+- _strictNumbers_: validate numbers strictly, failing validation for NaN and Infinity. Option values:
+ - `false` (default) - NaN or Infinity will pass validation for numeric types
+ - `true` - NaN or Infinity will not pass validation for numeric types
+
+##### Asynchronous validation options
+
+- _transpile_: Requires [ajv-async](https://github.com/ajv-validator/ajv-async) package. It determines whether Ajv transpiles compiled asynchronous validation function. Option values:
+ - `undefined` (default) - transpile with [nodent](https://github.com/MatAtBread/nodent) if async functions are not supported.
+ - `true` - always transpile with nodent.
+ - `false` - do not transpile; if async functions are not supported an exception will be thrown.
+
+
+##### Advanced options
+
+- _meta_: add [meta-schema](http://json-schema.org/documentation.html) so it can be used by other schemas (true by default). If an object is passed, it will be used as the default meta-schema for schemas that have no `$schema` keyword. This default meta-schema MUST have `$schema` keyword.
+- _validateSchema_: validate added/compiled schemas against meta-schema (true by default). `$schema` property in the schema can be http://json-schema.org/draft-07/schema or absent (draft-07 meta-schema will be used) or can be a reference to the schema previously added with `addMetaSchema` method. Option values:
+ - `true` (default) - if the validation fails, throw the exception.
+ - `"log"` - if the validation fails, log error.
+ - `false` - skip schema validation.
+- _addUsedSchema_: by default methods `compile` and `validate` add schemas to the instance if they have `$id` (or `id`) property that doesn't start with "#". If `$id` is present and it is not unique the exception will be thrown. Set this option to `false` to skip adding schemas to the instance and the `$id` uniqueness check when these methods are used. This option does not affect `addSchema` method.
+- _inlineRefs_: Affects compilation of referenced schemas. Option values:
+ - `true` (default) - the referenced schemas that don't have refs in them are inlined, regardless of their size - that substantially improves performance at the cost of the bigger size of compiled schema functions.
+ - `false` - to not inline referenced schemas (they will be compiled as separate functions).
+ - integer number - to limit the maximum number of keywords of the schema that will be inlined.
+- _passContext_: pass validation context to custom keyword functions. If this option is `true` and you pass some context to the compiled validation function with `validate.call(context, data)`, the `context` will be available as `this` in your custom keywords. By default `this` is Ajv instance.
+- _loopRequired_: by default `required` keyword is compiled into a single expression (or a sequence of statements in `allErrors` mode). In case of a very large number of properties in this keyword it may result in a very big validation function. Pass integer to set the number of properties above which `required` keyword will be validated in a loop - smaller validation function size but also worse performance.
+- _ownProperties_: by default Ajv iterates over all enumerable object properties; when this option is `true` only own enumerable object properties (i.e. found directly on the object rather than on its prototype) are iterated. Contributed by @mbroadst.
+- _multipleOfPrecision_: by default `multipleOf` keyword is validated by comparing the result of division with parseInt() of that result. It works for dividers that are bigger than 1. For small dividers such as 0.01 the result of the division is usually not integer (even when it should be integer, see issue [#84](https://github.com/ajv-validator/ajv/issues/84)). If you need to use fractional dividers set this option to some positive integer N to have `multipleOf` validated using this formula: `Math.abs(Math.round(division) - division) < 1e-N` (it is slower but allows for float arithmetics deviations).
+- _errorDataPath_ (deprecated): set `dataPath` to point to 'object' (default) or to 'property' when validating keywords `required`, `additionalProperties` and `dependencies`.
+- _messages_: Include human-readable messages in errors. `true` by default. `false` can be passed when custom messages are used (e.g. with [ajv-i18n](https://github.com/ajv-validator/ajv-i18n)).
+- _sourceCode_: add `sourceCode` property to validating function (for debugging; this code can be different from the result of toString call).
+- _processCode_: an optional function to process generated code before it is passed to Function constructor. It can be used to either beautify (the validating function is generated without line-breaks) or to transpile code. Starting from version 5.0.0 this option replaced options:
+ - `beautify` that formatted the generated function using [js-beautify](https://github.com/beautify-web/js-beautify). If you want to beautify the generated code pass a function calling `require('js-beautify').js_beautify` as `processCode: code => js_beautify(code)`.
+ - `transpile` that transpiled asynchronous validation function. You can still use `transpile` option with [ajv-async](https://github.com/ajv-validator/ajv-async) package. See [Asynchronous validation](#asynchronous-validation) for more information.
+- _cache_: an optional instance of cache to store compiled schemas using stable-stringified schema as a key. For example, set-associative cache [sacjs](https://github.com/epoberezkin/sacjs) can be used. If not passed then a simple hash is used which is good enough for the common use case (a limited number of statically defined schemas). Cache should have methods `put(key, value)`, `get(key)`, `del(key)` and `clear()`.
+- _serialize_: an optional function to serialize schema to cache key. Pass `false` to use schema itself as a key (e.g., if WeakMap used as a cache). By default [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used.
+
+
+## Validation errors
+
+In case of validation failure, Ajv assigns the array of errors to `errors` property of validation function (or to `errors` property of Ajv instance when `validate` or `validateSchema` methods were called). In case of [asynchronous validation](#asynchronous-validation), the returned promise is rejected with exception `Ajv.ValidationError` that has `errors` property.
+
+
+### Error objects
+
+Each error is an object with the following properties:
+
+- _keyword_: validation keyword.
+- _dataPath_: the path to the part of the data that was validated. By default `dataPath` uses JavaScript property access notation (e.g., `".prop[1].subProp"`). When the option `jsonPointers` is true (see [Options](#options)) `dataPath` will be set using JSON pointer standard (e.g., `"/prop/1/subProp"`).
+- _schemaPath_: the path (JSON-pointer as a URI fragment) to the schema of the keyword that failed validation.
+- _params_: the object with the additional information about error that can be used to create custom error messages (e.g., using [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) package). See below for parameters set by all keywords.
+- _message_: the standard error message (can be excluded with option `messages` set to false).
+- _schema_: the schema of the keyword (added with `verbose` option).
+- _parentSchema_: the schema containing the keyword (added with `verbose` option)
+- _data_: the data validated by the keyword (added with `verbose` option).
+
+__Please note__: `propertyNames` keyword schema validation errors have an additional property `propertyName`, `dataPath` points to the object. After schema validation for each property name, if it is invalid an additional error is added with the property `keyword` equal to `"propertyNames"`.
+
+
+### Error parameters
+
+Properties of `params` object in errors depend on the keyword that failed validation.
+
+- `maxItems`, `minItems`, `maxLength`, `minLength`, `maxProperties`, `minProperties` - property `limit` (number, the schema of the keyword).
+- `additionalItems` - property `limit` (the maximum number of allowed items in case when `items` keyword is an array of schemas and `additionalItems` is false).
+- `additionalProperties` - property `additionalProperty` (the property not used in `properties` and `patternProperties` keywords).
+- `dependencies` - properties:
+ - `property` (dependent property),
+ - `missingProperty` (required missing dependency - only the first one is reported currently)
+ - `deps` (required dependencies, comma separated list as a string),
+ - `depsCount` (the number of required dependencies).
+- `format` - property `format` (the schema of the keyword).
+- `maximum`, `minimum` - properties:
+ - `limit` (number, the schema of the keyword),
+ - `exclusive` (boolean, the schema of `exclusiveMaximum` or `exclusiveMinimum`),
+ - `comparison` (string, comparison operation to compare the data to the limit, with the data on the left and the limit on the right; can be "<", "<=", ">", ">=")
+- `multipleOf` - property `multipleOf` (the schema of the keyword)
+- `pattern` - property `pattern` (the schema of the keyword)
+- `required` - property `missingProperty` (required property that is missing).
+- `propertyNames` - property `propertyName` (an invalid property name).
+- `patternRequired` (in ajv-keywords) - property `missingPattern` (required pattern that did not match any property).
+- `type` - property `type` (required type(s), a string, can be a comma-separated list)
+- `uniqueItems` - properties `i` and `j` (indices of duplicate items).
+- `const` - property `allowedValue` pointing to the value (the schema of the keyword).
+- `enum` - property `allowedValues` pointing to the array of values (the schema of the keyword).
+- `$ref` - property `ref` with the referenced schema URI.
+- `oneOf` - property `passingSchemas` (array of indices of passing schemas, null if no schema passes).
+- custom keywords (in case keyword definition doesn't create errors) - property `keyword` (the keyword name).
+
+
+### Error logging
+
+Using the `logger` option when initiallizing Ajv will allow you to define custom logging. Here you can build upon the exisiting logging. The use of other logging packages is supported as long as the package or its associated wrapper exposes the required methods. If any of the required methods are missing an exception will be thrown.
+- **Required Methods**: `log`, `warn`, `error`
+
+```javascript
+var otherLogger = new OtherLogger();
+var ajv = new Ajv({
+ logger: {
+ log: console.log.bind(console),
+ warn: function warn() {
+ otherLogger.logWarn.apply(otherLogger, arguments);
+ },
+ error: function error() {
+ otherLogger.logError.apply(otherLogger, arguments);
+ console.error.apply(console, arguments);
+ }
+ }
+});
+```
+
+
+## Plugins
+
+Ajv can be extended with plugins that add custom keywords, formats or functions to process generated code. When such plugin is published as npm package it is recommended that it follows these conventions:
+
+- it exports a function
+- this function accepts ajv instance as the first parameter and returns the same instance to allow chaining
+- this function can accept an optional configuration as the second parameter
+
+If you have published a useful plugin please submit a PR to add it to the next section.
+
+
+## Related packages
+
+- [ajv-async](https://github.com/ajv-validator/ajv-async) - plugin to configure async validation mode
+- [ajv-bsontype](https://github.com/BoLaMN/ajv-bsontype) - plugin to validate mongodb's bsonType formats
+- [ajv-cli](https://github.com/jessedc/ajv-cli) - command line interface
+- [ajv-errors](https://github.com/ajv-validator/ajv-errors) - plugin for custom error messages
+- [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) - internationalised error messages
+- [ajv-istanbul](https://github.com/ajv-validator/ajv-istanbul) - plugin to instrument generated validation code to measure test coverage of your schemas
+- [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) - plugin with custom validation keywords (select, typeof, etc.)
+- [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) - plugin with keywords $merge and $patch
+- [ajv-pack](https://github.com/ajv-validator/ajv-pack) - produces a compact module exporting validation functions
+- [ajv-formats-draft2019](https://github.com/luzlab/ajv-formats-draft2019) - format validators for draft2019 that aren't already included in ajv (ie. `idn-hostname`, `idn-email`, `iri`, `iri-reference` and `duration`).
+
+## Some packages using Ajv
+
+- [webpack](https://github.com/webpack/webpack) - a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser
+- [jsonscript-js](https://github.com/JSONScript/jsonscript-js) - the interpreter for [JSONScript](http://www.jsonscript.org) - scripted processing of existing endpoints and services
+- [osprey-method-handler](https://github.com/mulesoft-labs/osprey-method-handler) - Express middleware for validating requests and responses based on a RAML method object, used in [osprey](https://github.com/mulesoft/osprey) - validating API proxy generated from a RAML definition
+- [har-validator](https://github.com/ahmadnassri/har-validator) - HTTP Archive (HAR) validator
+- [jsoneditor](https://github.com/josdejong/jsoneditor) - a web-based tool to view, edit, format, and validate JSON http://jsoneditoronline.org
+- [JSON Schema Lint](https://github.com/nickcmaynard/jsonschemalint) - a web tool to validate JSON/YAML document against a single JSON Schema http://jsonschemalint.com
+- [objection](https://github.com/vincit/objection.js) - SQL-friendly ORM for Node.js
+- [table](https://github.com/gajus/table) - formats data into a string table
+- [ripple-lib](https://github.com/ripple/ripple-lib) - a JavaScript API for interacting with [Ripple](https://ripple.com) in Node.js and the browser
+- [restbase](https://github.com/wikimedia/restbase) - distributed storage with REST API & dispatcher for backend services built to provide a low-latency & high-throughput API for Wikipedia / Wikimedia content
+- [hippie-swagger](https://github.com/CacheControl/hippie-swagger) - [Hippie](https://github.com/vesln/hippie) wrapper that provides end to end API testing with swagger validation
+- [react-form-controlled](https://github.com/seeden/react-form-controlled) - React controlled form components with validation
+- [rabbitmq-schema](https://github.com/tjmehta/rabbitmq-schema) - a schema definition module for RabbitMQ graphs and messages
+- [@query/schema](https://www.npmjs.com/package/@query/schema) - stream filtering with a URI-safe query syntax parsing to JSON Schema
+- [chai-ajv-json-schema](https://github.com/peon374/chai-ajv-json-schema) - chai plugin to us JSON Schema with expect in mocha tests
+- [grunt-jsonschema-ajv](https://github.com/SignpostMarv/grunt-jsonschema-ajv) - Grunt plugin for validating files against JSON Schema
+- [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) - extract text from bundle into a file
+- [electron-builder](https://github.com/electron-userland/electron-builder) - a solution to package and build a ready for distribution Electron app
+- [addons-linter](https://github.com/mozilla/addons-linter) - Mozilla Add-ons Linter
+- [gh-pages-generator](https://github.com/epoberezkin/gh-pages-generator) - multi-page site generator converting markdown files to GitHub pages
+- [ESLint](https://github.com/eslint/eslint) - the pluggable linting utility for JavaScript and JSX
+
+
+## Tests
+
+```
+npm install
+git submodule update --init
+npm test
+```
+
+## Contributing
+
+All validation functions are generated using doT templates in [dot](https://github.com/ajv-validator/ajv/tree/master/lib/dot) folder. Templates are precompiled so doT is not a run-time dependency.
+
+`npm run build` - compiles templates to [dotjs](https://github.com/ajv-validator/ajv/tree/master/lib/dotjs) folder.
+
+`npm run watch` - automatically compiles templates when files in dot folder change
+
+Please see [Contributing guidelines](https://github.com/ajv-validator/ajv/blob/master/CONTRIBUTING.md)
+
+
+## Changes history
+
+See https://github.com/ajv-validator/ajv/releases
+
+__Please note__: [Changes in version 7.0.0-beta](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0-beta.0)
+
+[Version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0).
+
+## Code of conduct
+
+Please review and follow the [Code of conduct](https://github.com/ajv-validator/ajv/blob/master/CODE_OF_CONDUCT.md).
+
+Please report any unacceptable behaviour to ajv.validator@gmail.com - it will be reviewed by the project team.
+
+
+## Open-source software support
+
+Ajv is a part of [Tidelift subscription](https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=readme) - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers.
+
+
+## License
+
+[MIT](https://github.com/ajv-validator/ajv/blob/master/LICENSE)
diff --git a/front_end/third_party/mcp-sdk/ajv/.runkit_example.js b/front_end/third_party/mcp-sdk/ajv/.runkit_example.js
deleted file mode 100644
index 0d578d5d51e..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/.runkit_example.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const Ajv = require("ajv")
-const ajv = new Ajv({allErrors: true})
-
-const schema = {
- type: "object",
- properties: {
- foo: {type: "string"},
- bar: {type: "number", maximum: 3},
- },
- required: ["foo", "bar"],
- additionalProperties: false,
-}
-
-const validate = ajv.compile(schema)
-
-test({foo: "abc", bar: 2})
-test({foo: 2, bar: 4})
-
-function test(data) {
- const valid = validate(data)
- if (valid) console.log("Valid!")
- else console.log("Invalid: " + ajv.errorsText(validate.errors))
-}
diff --git a/front_end/third_party/mcp-sdk/ajv/.tonic_example.js b/front_end/third_party/mcp-sdk/ajv/.tonic_example.js
new file mode 100644
index 00000000000..aa11812d87b
--- /dev/null
+++ b/front_end/third_party/mcp-sdk/ajv/.tonic_example.js
@@ -0,0 +1,20 @@
+var Ajv = require('ajv');
+var ajv = new Ajv({allErrors: true});
+
+var schema = {
+ "properties": {
+ "foo": { "type": "string" },
+ "bar": { "type": "number", "maximum": 3 }
+ }
+};
+
+var validate = ajv.compile(schema);
+
+test({"foo": "abc", "bar": 2});
+test({"foo": 2, "bar": 4});
+
+function test(data) {
+ var valid = validate(data);
+ if (valid) console.log('Valid!');
+ else console.log('Invalid: ' + ajv.errorsText(validate.errors));
+}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/LICENSE b/front_end/third_party/mcp-sdk/ajv/LICENSE
index 139162ad2c3..96ee719987f 100644
--- a/front_end/third_party/mcp-sdk/ajv/LICENSE
+++ b/front_end/third_party/mcp-sdk/ajv/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2015-2021 Evgeny Poberezkin
+Copyright (c) 2015-2017 Evgeny Poberezkin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/front_end/third_party/mcp-sdk/ajv/README.md b/front_end/third_party/mcp-sdk/ajv/README.md
index d8ee276cefb..5aa2078d892 100644
--- a/front_end/third_party/mcp-sdk/ajv/README.md
+++ b/front_end/third_party/mcp-sdk/ajv/README.md
@@ -1,63 +1,70 @@
-
+
-
+# Ajv: Another JSON Schema Validator
-# Ajv JSON schema validator
+The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/07.
-The fastest JSON validator for Node.js and browser.
-
-Supports JSON Schema draft-04/06/07/2019-09/2020-12 ([draft-04 support](https://ajv.js.org/json-schema.html#draft-04) requires ajv-draft-04 package) and JSON Type Definition [RFC8927](https://datatracker.ietf.org/doc/rfc8927/).
-
-[](https://github.com/ajv-validator/ajv/actions?query=workflow%3Abuild)
+[](https://travis-ci.org/ajv-validator/ajv)
[](https://www.npmjs.com/package/ajv)
+[](https://www.npmjs.com/package/ajv/v/7.0.0-beta.0)
[](https://www.npmjs.com/package/ajv)
[](https://coveralls.io/github/ajv-validator/ajv?branch=master)
-[](https://simplex.chat/contact#/?v=1-2&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2F8KvvURM6J38Gdq9dCuPswMOkMny0xCOJ%23%2F%3Fv%3D1-2%26dh%3DMCowBQYDK2VuAyEAr8rPVRuMOXv6kwF2yUAap-eoVg-9ssOFCi1fIrxTUw0%253D%26srv%3Do5vmywmrnaxalvz6wi3zicyftgio6psuvyniis6gco6bp6ekl4cqj4id.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%224pwLRgWHU9tlroMWHz0uOg%3D%3D%22%7D)
[](https://gitter.im/ajv-validator/ajv)
[](https://github.com/sponsors/epoberezkin)
-## Ajv sponsors
-[
](https://www.mozilla.org)
[
](https://opencollective.com/ajv)
+## Ajv v7 beta is released
-[
](https://opensource.microsoft.com)
[
](https://opencollective.com/ajv)
[
](https://opencollective.com/ajv)
+[Ajv version 7.0.0-beta.0](https://github.com/ajv-validator/ajv/tree/v7-beta) is released with these changes:
-[
](https://retool.com/?utm_source=sponsor&utm_campaign=ajv)
[
](https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=enterprise)
[
](https://github.com/simplex-chat/simplex-chat)
[
](https://opencollective.com/ajv)
+- to reduce the mistakes in JSON schemas and unexpected validation results, [strict mode](./docs/strict-mode.md) is added - it prohibits ignored or ambiguous JSON Schema elements.
+- to make code injection from untrusted schemas impossible, [code generation](./docs/codegen.md) is fully re-written to be safe.
+- to simplify Ajv extensions, the new keyword API that is used by pre-defined keywords is available to user-defined keywords - it is much easier to define any keywords now, especially with subschemas.
+- schemas are compiled to ES6 code (ES5 code generation is supported with an option).
+- to improve reliability and maintainability the code is migrated to TypeScript.
-## Contributing
+**Please note**:
+
+- the support for JSON-Schema draft-04 is removed - if you have schemas using "id" attributes you have to replace them with "\$id" (or continue using version 6 that will be supported until 02/28/2021).
+- all formats are separated to ajv-formats package - they have to be explicitely added if you use them.
+
+See [release notes](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0-beta.0) for the details.
+
+To install the new version:
+
+```bash
+npm install ajv@beta
+```
-More than 100 people contributed to Ajv, and we would love to have you join the development. We welcome implementing new features that will benefit many users and ideas to improve our documentation.
+See [Getting started with v7](https://github.com/ajv-validator/ajv/tree/v7-beta#usage) for code example.
-Please review [Contributing guidelines](./CONTRIBUTING.md) and [Code components](https://ajv.js.org/components.html).
-## Documentation
+## Mozilla MOSS grant and OpenJS Foundation
-All documentation is available on the [Ajv website](https://ajv.js.org).
+[
](https://www.mozilla.org/en-US/moss/) [
](https://openjsf.org/blog/2020/08/14/ajv-joins-openjs-foundation-as-an-incubation-project/)
-Some useful site links:
+Ajv has been awarded a grant from Mozilla’s [Open Source Support (MOSS) program](https://www.mozilla.org/en-US/moss/) in the “Foundational Technology” track! It will sponsor the development of Ajv support of [JSON Schema version 2019-09](https://tools.ietf.org/html/draft-handrews-json-schema-02) and of [JSON Type Definition](https://tools.ietf.org/html/draft-ucarion-json-type-definition-04).
-- [Getting started](https://ajv.js.org/guide/getting-started.html)
-- [JSON Schema vs JSON Type Definition](https://ajv.js.org/guide/schema-language.html)
-- [API reference](https://ajv.js.org/api.html)
-- [Strict mode](https://ajv.js.org/strict-mode.html)
-- [Standalone validation code](https://ajv.js.org/standalone.html)
-- [Security considerations](https://ajv.js.org/security.html)
-- [Command line interface](https://ajv.js.org/packages/ajv-cli.html)
-- [Frequently Asked Questions](https://ajv.js.org/faq.html)
+Ajv also joined [OpenJS Foundation](https://openjsf.org/) – having this support will help ensure the longevity and stability of Ajv for all its users.
-## Please [sponsor Ajv development](https://github.com/sponsors/epoberezkin)
+This [blog post](https://www.poberezkin.com/posts/2020-08-14-ajv-json-validator-mozilla-open-source-grant-openjs-foundation.html) has more details.
+
+I am looking for the long term maintainers of Ajv – working with [ReadySet](https://www.thereadyset.co/), also sponsored by Mozilla, to establish clear guidelines for the role of a "maintainer" and the contribution standards, and to encourage a wider, more inclusive, contribution from the community.
+
+
+## Please [sponsor Ajv development](https://github.com/sponsors/epoberezkin)
Since I asked to support Ajv development 40 people and 6 organizations contributed via GitHub and OpenCollective - this support helped receiving the MOSS grant!
Your continuing support is very important - the funds will be used to develop and maintain Ajv once the next major version is released.
Please sponsor Ajv via:
-
- [GitHub sponsors page](https://github.com/sponsors/epoberezkin) (GitHub will match it)
-- [Ajv Open Collective](https://opencollective.com/ajv)
+- [Ajv Open Collective️](https://opencollective.com/ajv)
Thank you.
+
#### Open Collective sponsors
@@ -72,25 +79,73 @@ Thank you.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+## Using version 6
+
+[JSON Schema draft-07](http://json-schema.org/latest/json-schema-validation.html) is published.
+
+[Ajv version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0) that supports draft-07 is released. It may require either migrating your schemas or updating your code (to continue using draft-04 and v5 schemas, draft-06 schemas will be supported without changes).
+
+__Please note__: To use Ajv with draft-06 schemas you need to explicitly add the meta-schema to the validator instance:
+
+```javascript
+ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
+```
+
+To use Ajv with draft-04 schemas in addition to explicitly adding meta-schema you also need to use option schemaId:
+
+```javascript
+var ajv = new Ajv({schemaId: 'id'});
+// If you want to use both draft-04 and draft-06/07 schemas:
+// var ajv = new Ajv({schemaId: 'auto'});
+ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
+```
+
+
+## Contents
+
+- [Performance](#performance)
+- [Features](#features)
+- [Getting started](#getting-started)
+- [Frequently Asked Questions](https://github.com/ajv-validator/ajv/blob/master/FAQ.md)
+- [Using in browser](#using-in-browser)
+ - [Ajv and Content Security Policies (CSP)](#ajv-and-content-security-policies-csp)
+- [Command line interface](#command-line-interface)
+- Validation
+ - [Keywords](#validation-keywords)
+ - [Annotation keywords](#annotation-keywords)
+ - [Formats](#formats)
+ - [Combining schemas with $ref](#ref)
+ - [$data reference](#data-reference)
+ - NEW: [$merge and $patch keywords](#merge-and-patch-keywords)
+ - [Defining custom keywords](#defining-custom-keywords)
+ - [Asynchronous schema compilation](#asynchronous-schema-compilation)
+ - [Asynchronous validation](#asynchronous-validation)
+- [Security considerations](#security-considerations)
+ - [Security contact](#security-contact)
+ - [Untrusted schemas](#untrusted-schemas)
+ - [Circular references in objects](#circular-references-in-javascript-objects)
+ - [Trusted schemas](#security-risks-of-trusted-schemas)
+ - [ReDoS attack](#redos-attack)
+- Modifying data during validation
+ - [Filtering data](#filtering-data)
+ - [Assigning defaults](#assigning-defaults)
+ - [Coercing data types](#coercing-data-types)
+- API
+ - [Methods](#api)
+ - [Options](#options)
+ - [Validation errors](#validation-errors)
+- [Plugins](#plugins)
+- [Related packages](#related-packages)
+- [Some packages using Ajv](#some-packages-using-ajv)
+- [Tests, Contributing, Changes history](#tests)
+- [Support, Code of conduct, License](#open-source-software-support)
+
## Performance
-Ajv generates code to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.
+Ajv generates code using [doT templates](https://github.com/olado/doT) to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.
Currently Ajv is the fastest and the most standard compliant validator according to these benchmarks:
@@ -99,109 +154,1344 @@ Currently Ajv is the fastest and the most standard compliant validator according
- [z-schema benchmark](https://rawgit.com/zaggino/z-schema/master/benchmark/results.html)
- [themis benchmark](https://cdn.rawgit.com/playlyfe/themis/master/benchmark/results.html)
+
Performance of different validators by [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark):
-[](https://github.com/ebdrup/json-schema-benchmark/blob/master/README.md#performance)
+[](https://github.com/ebdrup/json-schema-benchmark/blob/master/README.md#performance)
+
## Features
-- Ajv implements JSON Schema [draft-06/07/2019-09/2020-12](http://json-schema.org/) standards (draft-04 is supported in v6):
- - all validation keywords (see [JSON Schema validation keywords](https://ajv.js.org/json-schema.html))
- - [OpenAPI](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md) extensions:
- - NEW: keyword [discriminator](https://ajv.js.org/json-schema.html#discriminator).
- - keyword [nullable](https://ajv.js.org/json-schema.html#nullable).
- - full support of remote references (remote schemas have to be added with `addSchema` or compiled to be available)
- - support of recursive references between schemas
- - correct string lengths for strings with unicode pairs
- - JSON Schema [formats](https://ajv.js.org/guide/formats.html) (with [ajv-formats](https://github.com/ajv-validator/ajv-formats) plugin).
- - [validates schemas against meta-schema](https://ajv.js.org/api.html#api-validateschema)
-- NEW: supports [JSON Type Definition](https://datatracker.ietf.org/doc/rfc8927/):
- - all keywords (see [JSON Type Definition schema forms](https://ajv.js.org/json-type-definition.html))
- - meta-schema for JTD schemas
- - "union" keyword and user-defined keywords (can be used inside "metadata" member of the schema)
-- supports [browsers](https://ajv.js.org/guide/environments.html#browsers) and Node.js 10.x - current
-- [asynchronous loading](https://ajv.js.org/guide/managing-schemas.html#asynchronous-schema-loading) of referenced schemas during compilation
-- "All errors" validation mode with [option allErrors](https://ajv.js.org/options.html#allerrors)
-- [error messages with parameters](https://ajv.js.org/api.html#validation-errors) describing error reasons to allow error message generation
+- Ajv implements full JSON Schema [draft-06/07](http://json-schema.org/) and draft-04 standards:
+ - all validation keywords (see [JSON Schema validation keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md))
+ - full support of remote refs (remote schemas have to be added with `addSchema` or compiled to be available)
+ - support of circular references between schemas
+ - correct string lengths for strings with unicode pairs (can be turned off)
+ - [formats](#formats) defined by JSON Schema draft-07 standard and custom formats (can be turned off)
+ - [validates schemas against meta-schema](#api-validateschema)
+- supports [browsers](#using-in-browser) and Node.js 0.10-14.x
+- [asynchronous loading](#asynchronous-schema-compilation) of referenced schemas during compilation
+- "All errors" validation mode with [option allErrors](#options)
+- [error messages with parameters](#validation-errors) describing error reasons to allow creating custom error messages
- i18n error messages support with [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) package
-- [removing-additional-properties](https://ajv.js.org/guide/modifying-data.html#removing-additional-properties)
-- [assigning defaults](https://ajv.js.org/guide/modifying-data.html#assigning-defaults) to missing properties and items
-- [coercing data](https://ajv.js.org/guide/modifying-data.html#coercing-data-types) to the types specified in `type` keywords
-- [user-defined keywords](https://ajv.js.org/guide/user-keywords.html)
-- additional extension keywords with [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package
-- [\$data reference](https://ajv.js.org/guide/combining-schemas.html#data-reference) to use values from the validated data as values for the schema keywords
-- [asynchronous validation](https://ajv.js.org/guide/async-validation.html) of user-defined formats and keywords
+- [filtering data](#filtering-data) from additional properties
+- [assigning defaults](#assigning-defaults) to missing properties and items
+- [coercing data](#coercing-data-types) to the types specified in `type` keywords
+- [custom keywords](#defining-custom-keywords)
+- draft-06/07 keywords `const`, `contains`, `propertyNames` and `if/then/else`
+- draft-06 boolean schemas (`true`/`false` as a schema to always pass/fail).
+- keywords `switch`, `patternRequired`, `formatMaximum` / `formatMinimum` and `formatExclusiveMaximum` / `formatExclusiveMinimum` from [JSON Schema extension proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) with [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package
+- [$data reference](#data-reference) to use values from the validated data as values for the schema keywords
+- [asynchronous validation](#asynchronous-validation) of custom formats and keywords
-## Install
-To install version 8:
+## Install
```
npm install ajv
```
+
## Getting started
-Try it in the Node.js REPL: https://runkit.com/npm/ajv
+Try it in the Node.js REPL: https://tonicdev.com/npm/ajv
-In JavaScript:
+
+The fastest validation call:
```javascript
-// or ESM/TypeScript import
-import Ajv from "ajv"
// Node.js require:
-const Ajv = require("ajv")
+var Ajv = require('ajv');
+// or ESM/TypeScript import
+import Ajv from 'ajv';
+
+var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true}
+var validate = ajv.compile(schema);
+var valid = validate(data);
+if (!valid) console.log(validate.errors);
+```
+
+or with less code
+
+```javascript
+// ...
+var valid = ajv.validate(schema, data);
+if (!valid) console.log(ajv.errors);
+// ...
+```
+
+or
+
+```javascript
+// ...
+var valid = ajv.addSchema(schema, 'mySchema')
+ .validate('mySchema', data);
+if (!valid) console.log(ajv.errorsText());
+// ...
+```
+
+See [API](#api) and [Options](#options) for more details.
+
+Ajv compiles schemas to functions and caches them in all cases (using schema serialized with [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) or a custom function as a key), so that the next time the same schema is used (not necessarily the same object instance) it won't be compiled again.
+
+The best performance is achieved when using compiled functions returned by `compile` or `getSchema` methods (there is no additional function call).
+
+__Please note__: every time a validation function or `ajv.validate` are called `errors` property is overwritten. You need to copy `errors` array reference to another variable if you want to use it later (e.g., in the callback). See [Validation errors](#validation-errors)
+
+__Note for TypeScript users__: `ajv` provides its own TypeScript declarations
+out of the box, so you don't need to install the deprecated `@types/ajv`
+module.
+
+
+## Using in browser
+
+You can require Ajv directly from the code you browserify - in this case Ajv will be a part of your bundle.
+
+If you need to use Ajv in several bundles you can create a separate UMD bundle using `npm run bundle` script (thanks to [siddo420](https://github.com/siddo420)).
+
+Then you need to load Ajv in the browser:
+```html
+
+```
+
+This bundle can be used with different module systems; it creates global `Ajv` if no module system is found.
+
+The browser bundle is available on [cdnjs](https://cdnjs.com/libraries/ajv).
-const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
+Ajv is tested with these browsers:
-const schema = {
- type: "object",
- properties: {
- foo: {type: "integer"},
- bar: {type: "string"},
+[](https://saucelabs.com/u/epoberezkin)
+
+__Please note__: some frameworks, e.g. Dojo, may redefine global require in such way that is not compatible with CommonJS module format. In such case Ajv bundle has to be loaded before the framework and then you can use global Ajv (see issue [#234](https://github.com/ajv-validator/ajv/issues/234)).
+
+
+### Ajv and Content Security Policies (CSP)
+
+If you're using Ajv to compile a schema (the typical use) in a browser document that is loaded with a Content Security Policy (CSP), that policy will require a `script-src` directive that includes the value `'unsafe-eval'`.
+:warning: NOTE, however, that `unsafe-eval` is NOT recommended in a secure CSP[[1]](https://developer.chrome.com/extensions/contentSecurityPolicy#relaxing-eval), as it has the potential to open the document to cross-site scripting (XSS) attacks.
+
+In order to make use of Ajv without easing your CSP, you can [pre-compile a schema using the CLI](https://github.com/ajv-validator/ajv-cli#compile-schemas). This will transpile the schema JSON into a JavaScript file that exports a `validate` function that works simlarly to a schema compiled at runtime.
+
+Note that pre-compilation of schemas is performed using [ajv-pack](https://github.com/ajv-validator/ajv-pack) and there are [some limitations to the schema features it can compile](https://github.com/ajv-validator/ajv-pack#limitations). A successfully pre-compiled schema is equivalent to the same schema compiled at runtime.
+
+
+## Command line interface
+
+CLI is available as a separate npm package [ajv-cli](https://github.com/ajv-validator/ajv-cli). It supports:
+
+- compiling JSON Schemas to test their validity
+- BETA: generating standalone module exporting a validation function to be used without Ajv (using [ajv-pack](https://github.com/ajv-validator/ajv-pack))
+- migrate schemas to draft-07 (using [json-schema-migrate](https://github.com/epoberezkin/json-schema-migrate))
+- validating data file(s) against JSON Schema
+- testing expected validity of data against JSON Schema
+- referenced schemas
+- custom meta-schemas
+- files in JSON, JSON5, YAML, and JavaScript format
+- all Ajv options
+- reporting changes in data after validation in [JSON-patch](https://tools.ietf.org/html/rfc6902) format
+
+
+## Validation keywords
+
+Ajv supports all validation keywords from draft-07 of JSON Schema standard:
+
+- [type](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#type)
+- [for numbers](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-numbers) - maximum, minimum, exclusiveMaximum, exclusiveMinimum, multipleOf
+- [for strings](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-strings) - maxLength, minLength, pattern, format
+- [for arrays](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-arrays) - maxItems, minItems, uniqueItems, items, additionalItems, [contains](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#contains)
+- [for objects](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-objects) - maxProperties, minProperties, required, properties, patternProperties, additionalProperties, dependencies, [propertyNames](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#propertynames)
+- [for all types](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-all-types) - enum, [const](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#const)
+- [compound keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#compound-keywords) - not, oneOf, anyOf, allOf, [if/then/else](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#ifthenelse)
+
+With [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package Ajv also supports validation keywords from [JSON Schema extension proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) for JSON Schema standard:
+
+- [patternRequired](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#patternrequired-proposed) - like `required` but with patterns that some property should match.
+- [formatMaximum, formatMinimum, formatExclusiveMaximum, formatExclusiveMinimum](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#formatmaximum--formatminimum-and-exclusiveformatmaximum--exclusiveformatminimum-proposed) - setting limits for date, time, etc.
+
+See [JSON Schema validation keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md) for more details.
+
+
+## Annotation keywords
+
+JSON Schema specification defines several annotation keywords that describe schema itself but do not perform any validation.
+
+- `title` and `description`: information about the data represented by that schema
+- `$comment` (NEW in draft-07): information for developers. With option `$comment` Ajv logs or passes the comment string to the user-supplied function. See [Options](#options).
+- `default`: a default value of the data instance, see [Assigning defaults](#assigning-defaults).
+- `examples` (NEW in draft-06): an array of data instances. Ajv does not check the validity of these instances against the schema.
+- `readOnly` and `writeOnly` (NEW in draft-07): marks data-instance as read-only or write-only in relation to the source of the data (database, api, etc.).
+- `contentEncoding`: [RFC 2045](https://tools.ietf.org/html/rfc2045#section-6.1 ), e.g., "base64".
+- `contentMediaType`: [RFC 2046](https://tools.ietf.org/html/rfc2046), e.g., "image/png".
+
+__Please note__: Ajv does not implement validation of the keywords `examples`, `contentEncoding` and `contentMediaType` but it reserves them. If you want to create a plugin that implements some of them, it should remove these keywords from the instance.
+
+
+## Formats
+
+Ajv implements formats defined by JSON Schema specification and several other formats. It is recommended NOT to use "format" keyword implementations with untrusted data, as they use potentially unsafe regular expressions - see [ReDoS attack](#redos-attack).
+
+__Please note__: if you need to use "format" keyword to validate untrusted data, you MUST assess their suitability and safety for your validation scenarios.
+
+The following formats are implemented for string validation with "format" keyword:
+
+- _date_: full-date according to [RFC3339](http://tools.ietf.org/html/rfc3339#section-5.6).
+- _time_: time with optional time-zone.
+- _date-time_: date-time from the same source (time-zone is mandatory). `date`, `time` and `date-time` validate ranges in `full` mode and only regexp in `fast` mode (see [options](#options)).
+- _uri_: full URI.
+- _uri-reference_: URI reference, including full and relative URIs.
+- _uri-template_: URI template according to [RFC6570](https://tools.ietf.org/html/rfc6570)
+- _url_ (deprecated): [URL record](https://url.spec.whatwg.org/#concept-url).
+- _email_: email address.
+- _hostname_: host name according to [RFC1034](http://tools.ietf.org/html/rfc1034#section-3.5).
+- _ipv4_: IP address v4.
+- _ipv6_: IP address v6.
+- _regex_: tests whether a string is a valid regular expression by passing it to RegExp constructor.
+- _uuid_: Universally Unique IDentifier according to [RFC4122](http://tools.ietf.org/html/rfc4122).
+- _json-pointer_: JSON-pointer according to [RFC6901](https://tools.ietf.org/html/rfc6901).
+- _relative-json-pointer_: relative JSON-pointer according to [this draft](http://tools.ietf.org/html/draft-luff-relative-json-pointer-00).
+
+__Please note__: JSON Schema draft-07 also defines formats `iri`, `iri-reference`, `idn-hostname` and `idn-email` for URLs, hostnames and emails with international characters. Ajv does not implement these formats. If you create Ajv plugin that implements them please make a PR to mention this plugin here.
+
+There are two modes of format validation: `fast` and `full`. This mode affects formats `date`, `time`, `date-time`, `uri`, `uri-reference`, and `email`. See [Options](#options) for details.
+
+You can add additional formats and replace any of the formats above using [addFormat](#api-addformat) method.
+
+The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can allow specific format(s) that will be ignored. See [Options](#options) for details.
+
+You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js).
+
+
+## Combining schemas with $ref
+
+You can structure your validation logic across multiple schema files and have schemas reference each other using `$ref` keyword.
+
+Example:
+
+```javascript
+var schema = {
+ "$id": "http://example.com/schemas/schema.json",
+ "type": "object",
+ "properties": {
+ "foo": { "$ref": "defs.json#/definitions/int" },
+ "bar": { "$ref": "defs.json#/definitions/str" }
+ }
+};
+
+var defsSchema = {
+ "$id": "http://example.com/schemas/defs.json",
+ "definitions": {
+ "int": { "type": "integer" },
+ "str": { "type": "string" }
+ }
+};
+```
+
+Now to compile your schema you can either pass all schemas to Ajv instance:
+
+```javascript
+var ajv = new Ajv({schemas: [schema, defsSchema]});
+var validate = ajv.getSchema('http://example.com/schemas/schema.json');
+```
+
+or use `addSchema` method:
+
+```javascript
+var ajv = new Ajv;
+var validate = ajv.addSchema(defsSchema)
+ .compile(schema);
+```
+
+See [Options](#options) and [addSchema](#api) method.
+
+__Please note__:
+- `$ref` is resolved as the uri-reference using schema $id as the base URI (see the example).
+- References can be recursive (and mutually recursive) to implement the schemas for different data structures (such as linked lists, trees, graphs, etc.).
+- You don't have to host your schema files at the URIs that you use as schema $id. These URIs are only used to identify the schemas, and according to JSON Schema specification validators should not expect to be able to download the schemas from these URIs.
+- The actual location of the schema file in the file system is not used.
+- You can pass the identifier of the schema as the second parameter of `addSchema` method or as a property name in `schemas` option. This identifier can be used instead of (or in addition to) schema $id.
+- You cannot have the same $id (or the schema identifier) used for more than one schema - the exception will be thrown.
+- You can implement dynamic resolution of the referenced schemas using `compileAsync` method. In this way you can store schemas in any system (files, web, database, etc.) and reference them without explicitly adding to Ajv instance. See [Asynchronous schema compilation](#asynchronous-schema-compilation).
+
+
+## $data reference
+
+With `$data` option you can use values from the validated data as the values for the schema keywords. See [proposal](https://github.com/json-schema-org/json-schema-spec/issues/51) for more information about how it works.
+
+`$data` reference is supported in the keywords: const, enum, format, maximum/minimum, exclusiveMaximum / exclusiveMinimum, maxLength / minLength, maxItems / minItems, maxProperties / minProperties, formatMaximum / formatMinimum, formatExclusiveMaximum / formatExclusiveMinimum, multipleOf, pattern, required, uniqueItems.
+
+The value of "$data" should be a [JSON-pointer](https://tools.ietf.org/html/rfc6901) to the data (the root is always the top level data object, even if the $data reference is inside a referenced subschema) or a [relative JSON-pointer](http://tools.ietf.org/html/draft-luff-relative-json-pointer-00) (it is relative to the current point in data; if the $data reference is inside a referenced subschema it cannot point to the data outside of the root level for this subschema).
+
+Examples.
+
+This schema requires that the value in property `smaller` is less or equal than the value in the property larger:
+
+```javascript
+var ajv = new Ajv({$data: true});
+
+var schema = {
+ "properties": {
+ "smaller": {
+ "type": "number",
+ "maximum": { "$data": "1/larger" }
+ },
+ "larger": { "type": "number" }
+ }
+};
+
+var validData = {
+ smaller: 5,
+ larger: 7
+};
+
+ajv.validate(schema, validData); // true
+```
+
+This schema requires that the properties have the same format as their field names:
+
+```javascript
+var schema = {
+ "additionalProperties": {
+ "type": "string",
+ "format": { "$data": "0#" }
+ }
+};
+
+var validData = {
+ 'date-time': '1963-06-19T08:30:06.283185Z',
+ email: 'joe.bloggs@example.com'
+}
+```
+
+`$data` reference is resolved safely - it won't throw even if some property is undefined. If `$data` resolves to `undefined` the validation succeeds (with the exclusion of `const` keyword). If `$data` resolves to incorrect type (e.g. not "number" for maximum keyword) the validation fails.
+
+
+## $merge and $patch keywords
+
+With the package [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) you can use the keywords `$merge` and `$patch` that allow extending JSON Schemas with patches using formats [JSON Merge Patch (RFC 7396)](https://tools.ietf.org/html/rfc7396) and [JSON Patch (RFC 6902)](https://tools.ietf.org/html/rfc6902).
+
+To add keywords `$merge` and `$patch` to Ajv instance use this code:
+
+```javascript
+require('ajv-merge-patch')(ajv);
+```
+
+Examples.
+
+Using `$merge`:
+
+```json
+{
+ "$merge": {
+ "source": {
+ "type": "object",
+ "properties": { "p": { "type": "string" } },
+ "additionalProperties": false
+ },
+ "with": {
+ "properties": { "q": { "type": "number" } }
+ }
+ }
+}
+```
+
+Using `$patch`:
+
+```json
+{
+ "$patch": {
+ "source": {
+ "type": "object",
+ "properties": { "p": { "type": "string" } },
+ "additionalProperties": false
+ },
+ "with": [
+ { "op": "add", "path": "/properties/q", "value": { "type": "number" } }
+ ]
+ }
+}
+```
+
+The schemas above are equivalent to this schema:
+
+```json
+{
+ "type": "object",
+ "properties": {
+ "p": { "type": "string" },
+ "q": { "type": "number" }
},
- required: ["foo"],
- additionalProperties: false,
+ "additionalProperties": false
}
+```
-const data = {
- foo: 1,
- bar: "abc",
+The properties `source` and `with` in the keywords `$merge` and `$patch` can use absolute or relative `$ref` to point to other schemas previously added to the Ajv instance or to the fragments of the current schema.
+
+See the package [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) for more information.
+
+
+## Defining custom keywords
+
+The advantages of using custom keywords are:
+
+- allow creating validation scenarios that cannot be expressed using JSON Schema
+- simplify your schemas
+- help bringing a bigger part of the validation logic to your schemas
+- make your schemas more expressive, less verbose and closer to your application domain
+- implement custom data processors that modify your data (`modifying` option MUST be used in keyword definition) and/or create side effects while the data is being validated
+
+If a keyword is used only for side-effects and its validation result is pre-defined, use option `valid: true/false` in keyword definition to simplify both generated code (no error handling in case of `valid: true`) and your keyword functions (no need to return any validation result).
+
+The concerns you have to be aware of when extending JSON Schema standard with custom keywords are the portability and understanding of your schemas. You will have to support these custom keywords on other platforms and to properly document these keywords so that everybody can understand them in your schemas.
+
+You can define custom keywords with [addKeyword](#api-addkeyword) method. Keywords are defined on the `ajv` instance level - new instances will not have previously defined keywords.
+
+Ajv allows defining keywords with:
+- validation function
+- compilation function
+- macro function
+- inline compilation function that should return code (as string) that will be inlined in the currently compiled schema.
+
+Example. `range` and `exclusiveRange` keywords using compiled schema:
+
+```javascript
+ajv.addKeyword('range', {
+ type: 'number',
+ compile: function (sch, parentSchema) {
+ var min = sch[0];
+ var max = sch[1];
+
+ return parentSchema.exclusiveRange === true
+ ? function (data) { return data > min && data < max; }
+ : function (data) { return data >= min && data <= max; }
+ }
+});
+
+var schema = { "range": [2, 4], "exclusiveRange": true };
+var validate = ajv.compile(schema);
+console.log(validate(2.01)); // true
+console.log(validate(3.99)); // true
+console.log(validate(2)); // false
+console.log(validate(4)); // false
+```
+
+Several custom keywords (typeof, instanceof, range and propertyNames) are defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package - they can be used for your schemas and as a starting point for your own custom keywords.
+
+See [Defining custom keywords](https://github.com/ajv-validator/ajv/blob/master/CUSTOM.md) for more details.
+
+
+## Asynchronous schema compilation
+
+During asynchronous compilation remote references are loaded using supplied function. See `compileAsync` [method](#api-compileAsync) and `loadSchema` [option](#options).
+
+Example:
+
+```javascript
+var ajv = new Ajv({ loadSchema: loadSchema });
+
+ajv.compileAsync(schema).then(function (validate) {
+ var valid = validate(data);
+ // ...
+});
+
+function loadSchema(uri) {
+ return request.json(uri).then(function (res) {
+ if (res.statusCode >= 400)
+ throw new Error('Loading error: ' + res.statusCode);
+ return res.body;
+ });
}
+```
+
+__Please note__: [Option](#options) `missingRefs` should NOT be set to `"ignore"` or `"fail"` for asynchronous compilation to work.
+
+
+## Asynchronous validation
+
+Example in Node.js REPL: https://tonicdev.com/esp/ajv-asynchronous-validation
-const validate = ajv.compile(schema)
-const valid = validate(data)
-if (!valid) console.log(validate.errors)
+You can define custom formats and keywords that perform validation asynchronously by accessing database or some other service. You should add `async: true` in the keyword or format definition (see [addFormat](#api-addformat), [addKeyword](#api-addkeyword) and [Defining custom keywords](#defining-custom-keywords)).
+
+If your schema uses asynchronous formats/keywords or refers to some schema that contains them it should have `"$async": true` keyword so that Ajv can compile it correctly. If asynchronous format/keyword or reference to asynchronous schema is used in the schema without `$async` keyword Ajv will throw an exception during schema compilation.
+
+__Please note__: all asynchronous subschemas that are referenced from the current or other schemas should have `"$async": true` keyword as well, otherwise the schema compilation will fail.
+
+Validation function for an asynchronous custom format/keyword should return a promise that resolves with `true` or `false` (or rejects with `new Ajv.ValidationError(errors)` if you want to return custom errors from the keyword function).
+
+Ajv compiles asynchronous schemas to [es7 async functions](http://tc39.github.io/ecmascript-asyncawait/) that can optionally be transpiled with [nodent](https://github.com/MatAtBread/nodent). Async functions are supported in Node.js 7+ and all modern browsers. You can also supply any other transpiler as a function via `processCode` option. See [Options](#options).
+
+The compiled validation function has `$async: true` property (if the schema is asynchronous), so you can differentiate these functions if you are using both synchronous and asynchronous schemas.
+
+Validation result will be a promise that resolves with validated data or rejects with an exception `Ajv.ValidationError` that contains the array of validation errors in `errors` property.
+
+
+Example:
+
+```javascript
+var ajv = new Ajv;
+// require('ajv-async')(ajv);
+
+ajv.addKeyword('idExists', {
+ async: true,
+ type: 'number',
+ validate: checkIdExists
+});
+
+
+function checkIdExists(schema, data) {
+ return knex(schema.table)
+ .select('id')
+ .where('id', data)
+ .then(function (rows) {
+ return !!rows.length; // true if record is found
+ });
+}
+
+var schema = {
+ "$async": true,
+ "properties": {
+ "userId": {
+ "type": "integer",
+ "idExists": { "table": "users" }
+ },
+ "postId": {
+ "type": "integer",
+ "idExists": { "table": "posts" }
+ }
+ }
+};
+
+var validate = ajv.compile(schema);
+
+validate({ userId: 1, postId: 19 })
+.then(function (data) {
+ console.log('Data is valid', data); // { userId: 1, postId: 19 }
+})
+.catch(function (err) {
+ if (!(err instanceof Ajv.ValidationError)) throw err;
+ // data is invalid
+ console.log('Validation errors:', err.errors);
+});
```
-Learn how to use Ajv and see more examples in the [Guide: getting started](https://ajv.js.org/guide/getting-started.html)
+### Using transpilers with asynchronous validation functions.
-## Changes history
+[ajv-async](https://github.com/ajv-validator/ajv-async) uses [nodent](https://github.com/MatAtBread/nodent) to transpile async functions. To use another transpiler you should separately install it (or load its bundle in the browser).
-See [https://github.com/ajv-validator/ajv/releases](https://github.com/ajv-validator/ajv/releases)
-**Please note**: [Changes in version 8.0.0](https://github.com/ajv-validator/ajv/releases/tag/v8.0.0)
+#### Using nodent
-[Version 7.0.0](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0)
+```javascript
+var ajv = new Ajv;
+require('ajv-async')(ajv);
+// in the browser if you want to load ajv-async bundle separately you can:
+// window.ajvAsync(ajv);
+var validate = ajv.compile(schema); // transpiled es7 async function
+validate(data).then(successFunc).catch(errorFunc);
+```
-[Version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0).
-## Code of conduct
+#### Using other transpilers
-Please review and follow the [Code of conduct](./CODE_OF_CONDUCT.md).
+```javascript
+var ajv = new Ajv({ processCode: transpileFunc });
+var validate = ajv.compile(schema); // transpiled es7 async function
+validate(data).then(successFunc).catch(errorFunc);
+```
-Please report any unacceptable behaviour to ajv.validator@gmail.com - it will be reviewed by the project team.
+See [Options](#options).
+
+
+## Security considerations
-## Security contact
+JSON Schema, if properly used, can replace data sanitisation. It doesn't replace other API security considerations. It also introduces additional security aspects to consider.
+
+
+##### Security contact
To report a security vulnerability, please use the
[Tidelift security contact](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerabilities via GitHub issues.
+
+##### Untrusted schemas
+
+Ajv treats JSON schemas as trusted as your application code. This security model is based on the most common use case, when the schemas are static and bundled together with the application.
+
+If your schemas are received from untrusted sources (or generated from untrusted data) there are several scenarios you need to prevent:
+- compiling schemas can cause stack overflow (if they are too deep)
+- compiling schemas can be slow (e.g. [#557](https://github.com/ajv-validator/ajv/issues/557))
+- validating certain data can be slow
+
+It is difficult to predict all the scenarios, but at the very least it may help to limit the size of untrusted schemas (e.g. limit JSON string length) and also the maximum schema object depth (that can be high for relatively small JSON strings). You also may want to mitigate slow regular expressions in `pattern` and `patternProperties` keywords.
+
+Regardless the measures you take, using untrusted schemas increases security risks.
+
+
+##### Circular references in JavaScript objects
+
+Ajv does not support schemas and validated data that have circular references in objects. See [issue #802](https://github.com/ajv-validator/ajv/issues/802).
+
+An attempt to compile such schemas or validate such data would cause stack overflow (or will not complete in case of asynchronous validation). Depending on the parser you use, untrusted data can lead to circular references.
+
+
+##### Security risks of trusted schemas
+
+Some keywords in JSON Schemas can lead to very slow validation for certain data. These keywords include (but may be not limited to):
+
+- `pattern` and `format` for large strings - in some cases using `maxLength` can help mitigate it, but certain regular expressions can lead to exponential validation time even with relatively short strings (see [ReDoS attack](#redos-attack)).
+- `patternProperties` for large property names - use `propertyNames` to mitigate, but some regular expressions can have exponential evaluation time as well.
+- `uniqueItems` for large non-scalar arrays - use `maxItems` to mitigate
+
+__Please note__: The suggestions above to prevent slow validation would only work if you do NOT use `allErrors: true` in production code (using it would continue validation after validation errors).
+
+You can validate your JSON schemas against [this meta-schema](https://github.com/ajv-validator/ajv/blob/master/lib/refs/json-schema-secure.json) to check that these recommendations are followed:
+
+```javascript
+const isSchemaSecure = ajv.compile(require('ajv/lib/refs/json-schema-secure.json'));
+
+const schema1 = {format: 'email'};
+isSchemaSecure(schema1); // false
+
+const schema2 = {format: 'email', maxLength: MAX_LENGTH};
+isSchemaSecure(schema2); // true
+```
+
+__Please note__: following all these recommendation is not a guarantee that validation of untrusted data is safe - it can still lead to some undesirable results.
+
+
+##### Content Security Policies (CSP)
+See [Ajv and Content Security Policies (CSP)](#ajv-and-content-security-policies-csp)
+
+
+## ReDoS attack
+
+Certain regular expressions can lead to the exponential evaluation time even with relatively short strings.
+
+Please assess the regular expressions you use in the schemas on their vulnerability to this attack - see [safe-regex](https://github.com/substack/safe-regex), for example.
+
+__Please note__: some formats that Ajv implements use [regular expressions](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js) that can be vulnerable to ReDoS attack, so if you use Ajv to validate data from untrusted sources __it is strongly recommended__ to consider the following:
+
+- making assessment of "format" implementations in Ajv.
+- using `format: 'fast'` option that simplifies some of the regular expressions (although it does not guarantee that they are safe).
+- replacing format implementations provided by Ajv with your own implementations of "format" keyword that either uses different regular expressions or another approach to format validation. Please see [addFormat](#api-addformat) method.
+- disabling format validation by ignoring "format" keyword with option `format: false`
+
+Whatever mitigation you choose, please assume all formats provided by Ajv as potentially unsafe and make your own assessment of their suitability for your validation scenarios.
+
+
+## Filtering data
+
+With [option `removeAdditional`](#options) (added by [andyscott](https://github.com/andyscott)) you can filter data during the validation.
+
+This option modifies original data.
+
+Example:
+
+```javascript
+var ajv = new Ajv({ removeAdditional: true });
+var schema = {
+ "additionalProperties": false,
+ "properties": {
+ "foo": { "type": "number" },
+ "bar": {
+ "additionalProperties": { "type": "number" },
+ "properties": {
+ "baz": { "type": "string" }
+ }
+ }
+ }
+}
+
+var data = {
+ "foo": 0,
+ "additional1": 1, // will be removed; `additionalProperties` == false
+ "bar": {
+ "baz": "abc",
+ "additional2": 2 // will NOT be removed; `additionalProperties` != false
+ },
+}
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // { "foo": 0, "bar": { "baz": "abc", "additional2": 2 }
+```
+
+If `removeAdditional` option in the example above were `"all"` then both `additional1` and `additional2` properties would have been removed.
+
+If the option were `"failing"` then property `additional1` would have been removed regardless of its value and property `additional2` would have been removed only if its value were failing the schema in the inner `additionalProperties` (so in the example above it would have stayed because it passes the schema, but any non-number would have been removed).
+
+__Please note__: If you use `removeAdditional` option with `additionalProperties` keyword inside `anyOf`/`oneOf` keywords your validation can fail with this schema, for example:
+
+```json
+{
+ "type": "object",
+ "oneOf": [
+ {
+ "properties": {
+ "foo": { "type": "string" }
+ },
+ "required": [ "foo" ],
+ "additionalProperties": false
+ },
+ {
+ "properties": {
+ "bar": { "type": "integer" }
+ },
+ "required": [ "bar" ],
+ "additionalProperties": false
+ }
+ ]
+}
+```
+
+The intention of the schema above is to allow objects with either the string property "foo" or the integer property "bar", but not with both and not with any other properties.
+
+With the option `removeAdditional: true` the validation will pass for the object `{ "foo": "abc"}` but will fail for the object `{"bar": 1}`. It happens because while the first subschema in `oneOf` is validated, the property `bar` is removed because it is an additional property according to the standard (because it is not included in `properties` keyword in the same schema).
+
+While this behaviour is unexpected (issues [#129](https://github.com/ajv-validator/ajv/issues/129), [#134](https://github.com/ajv-validator/ajv/issues/134)), it is correct. To have the expected behaviour (both objects are allowed and additional properties are removed) the schema has to be refactored in this way:
+
+```json
+{
+ "type": "object",
+ "properties": {
+ "foo": { "type": "string" },
+ "bar": { "type": "integer" }
+ },
+ "additionalProperties": false,
+ "oneOf": [
+ { "required": [ "foo" ] },
+ { "required": [ "bar" ] }
+ ]
+}
+```
+
+The schema above is also more efficient - it will compile into a faster function.
+
+
+## Assigning defaults
+
+With [option `useDefaults`](#options) Ajv will assign values from `default` keyword in the schemas of `properties` and `items` (when it is the array of schemas) to the missing properties and items.
+
+With the option value `"empty"` properties and items equal to `null` or `""` (empty string) will be considered missing and assigned defaults.
+
+This option modifies original data.
+
+__Please note__: the default value is inserted in the generated validation code as a literal, so the value inserted in the data will be the deep clone of the default in the schema.
+
+
+Example 1 (`default` in `properties`):
+
+```javascript
+var ajv = new Ajv({ useDefaults: true });
+var schema = {
+ "type": "object",
+ "properties": {
+ "foo": { "type": "number" },
+ "bar": { "type": "string", "default": "baz" }
+ },
+ "required": [ "foo", "bar" ]
+};
+
+var data = { "foo": 1 };
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // { "foo": 1, "bar": "baz" }
+```
+
+Example 2 (`default` in `items`):
+
+```javascript
+var schema = {
+ "type": "array",
+ "items": [
+ { "type": "number" },
+ { "type": "string", "default": "foo" }
+ ]
+}
+
+var data = [ 1 ];
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // [ 1, "foo" ]
+```
+
+`default` keywords in other cases are ignored:
+
+- not in `properties` or `items` subschemas
+- in schemas inside `anyOf`, `oneOf` and `not` (see [#42](https://github.com/ajv-validator/ajv/issues/42))
+- in `if` subschema of `switch` keyword
+- in schemas generated by custom macro keywords
+
+The [`strictDefaults` option](#options) customizes Ajv's behavior for the defaults that Ajv ignores (`true` raises an error, and `"log"` outputs a warning).
+
+
+## Coercing data types
+
+When you are validating user inputs all your data properties are usually strings. The option `coerceTypes` allows you to have your data types coerced to the types specified in your schema `type` keywords, both to pass the validation and to use the correctly typed data afterwards.
+
+This option modifies original data.
+
+__Please note__: if you pass a scalar value to the validating function its type will be coerced and it will pass the validation, but the value of the variable you pass won't be updated because scalars are passed by value.
+
+
+Example 1:
+
+```javascript
+var ajv = new Ajv({ coerceTypes: true });
+var schema = {
+ "type": "object",
+ "properties": {
+ "foo": { "type": "number" },
+ "bar": { "type": "boolean" }
+ },
+ "required": [ "foo", "bar" ]
+};
+
+var data = { "foo": "1", "bar": "false" };
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // { "foo": 1, "bar": false }
+```
+
+Example 2 (array coercions):
+
+```javascript
+var ajv = new Ajv({ coerceTypes: 'array' });
+var schema = {
+ "properties": {
+ "foo": { "type": "array", "items": { "type": "number" } },
+ "bar": { "type": "boolean" }
+ }
+};
+
+var data = { "foo": "1", "bar": ["false"] };
+
+var validate = ajv.compile(schema);
+
+console.log(validate(data)); // true
+console.log(data); // { "foo": [1], "bar": false }
+```
+
+The coercion rules, as you can see from the example, are different from JavaScript both to validate user input as expected and to have the coercion reversible (to correctly validate cases where different types are defined in subschemas of "anyOf" and other compound keywords).
+
+See [Coercion rules](https://github.com/ajv-validator/ajv/blob/master/COERCION.md) for details.
+
+
+## API
+
+##### new Ajv(Object options) -> Object
+
+Create Ajv instance.
+
+
+##### .compile(Object schema) -> Function<Object data>
+
+Generate validating function and cache the compiled schema for future use.
+
+Validating function returns a boolean value. This function has properties `errors` and `schema`. Errors encountered during the last validation are assigned to `errors` property (it is assigned `null` if there was no errors). `schema` property contains the reference to the original schema.
+
+The schema passed to this method will be validated against meta-schema unless `validateSchema` option is false. If schema is invalid, an error will be thrown. See [options](#options).
+
+
+##### .compileAsync(Object schema [, Boolean meta] [, Function callback]) -> Promise
+
+Asynchronous version of `compile` method that loads missing remote schemas using asynchronous function in `options.loadSchema`. This function returns a Promise that resolves to a validation function. An optional callback passed to `compileAsync` will be called with 2 parameters: error (or null) and validating function. The returned promise will reject (and the callback will be called with an error) when:
+
+- missing schema can't be loaded (`loadSchema` returns a Promise that rejects).
+- a schema containing a missing reference is loaded, but the reference cannot be resolved.
+- schema (or some loaded/referenced schema) is invalid.
+
+The function compiles schema and loads the first missing schema (or meta-schema) until all missing schemas are loaded.
+
+You can asynchronously compile meta-schema by passing `true` as the second parameter.
+
+See example in [Asynchronous compilation](#asynchronous-schema-compilation).
+
+
+##### .validate(Object schema|String key|String ref, data) -> Boolean
+
+Validate data using passed schema (it will be compiled and cached).
+
+Instead of the schema you can use the key that was previously passed to `addSchema`, the schema id if it was present in the schema or any previously resolved reference.
+
+Validation errors will be available in the `errors` property of Ajv instance (`null` if there were no errors).
+
+__Please note__: every time this method is called the errors are overwritten so you need to copy them to another variable if you want to use them later.
+
+If the schema is asynchronous (has `$async` keyword on the top level) this method returns a Promise. See [Asynchronous validation](#asynchronous-validation).
+
+
+##### .addSchema(Array<Object>|Object schema [, String key]) -> Ajv
+
+Add schema(s) to validator instance. This method does not compile schemas (but it still validates them). Because of that dependencies can be added in any order and circular dependencies are supported. It also prevents unnecessary compilation of schemas that are containers for other schemas but not used as a whole.
+
+Array of schemas can be passed (schemas should have ids), the second parameter will be ignored.
+
+Key can be passed that can be used to reference the schema and will be used as the schema id if there is no id inside the schema. If the key is not passed, the schema id will be used as the key.
+
+
+Once the schema is added, it (and all the references inside it) can be referenced in other schemas and used to validate data.
+
+Although `addSchema` does not compile schemas, explicit compilation is not required - the schema will be compiled when it is used first time.
+
+By default the schema is validated against meta-schema before it is added, and if the schema does not pass validation the exception is thrown. This behaviour is controlled by `validateSchema` option.
+
+__Please note__: Ajv uses the [method chaining syntax](https://en.wikipedia.org/wiki/Method_chaining) for all methods with the prefix `add*` and `remove*`.
+This allows you to do nice things like the following.
+
+```javascript
+var validate = new Ajv().addSchema(schema).addFormat(name, regex).getSchema(uri);
+```
+
+##### .addMetaSchema(Array<Object>|Object schema [, String key]) -> Ajv
+
+Adds meta schema(s) that can be used to validate other schemas. That function should be used instead of `addSchema` because there may be instance options that would compile a meta schema incorrectly (at the moment it is `removeAdditional` option).
+
+There is no need to explicitly add draft-07 meta schema (http://json-schema.org/draft-07/schema) - it is added by default, unless option `meta` is set to `false`. You only need to use it if you have a changed meta-schema that you want to use to validate your schemas. See `validateSchema`.
+
+
+##### .validateSchema(Object schema) -> Boolean
+
+Validates schema. This method should be used to validate schemas rather than `validate` due to the inconsistency of `uri` format in JSON Schema standard.
+
+By default this method is called automatically when the schema is added, so you rarely need to use it directly.
+
+If schema doesn't have `$schema` property, it is validated against draft 6 meta-schema (option `meta` should not be false).
+
+If schema has `$schema` property, then the schema with this id (that should be previously added) is used to validate passed schema.
+
+Errors will be available at `ajv.errors`.
+
+
+##### .getSchema(String key) -> Function<Object data>
+
+Retrieve compiled schema previously added with `addSchema` by the key passed to `addSchema` or by its full reference (id). The returned validating function has `schema` property with the reference to the original schema.
+
+
+##### .removeSchema([Object schema|String key|String ref|RegExp pattern]) -> Ajv
+
+Remove added/cached schema. Even if schema is referenced by other schemas it can be safely removed as dependent schemas have local references.
+
+Schema can be removed using:
+- key passed to `addSchema`
+- it's full reference (id)
+- RegExp that should match schema id or key (meta-schemas won't be removed)
+- actual schema object that will be stable-stringified to remove schema from cache
+
+If no parameter is passed all schemas but meta-schemas will be removed and the cache will be cleared.
+
+
+##### .addFormat(String name, String|RegExp|Function|Object format) -> Ajv
+
+Add custom format to validate strings or numbers. It can also be used to replace pre-defined formats for Ajv instance.
+
+Strings are converted to RegExp.
+
+Function should return validation result as `true` or `false`.
+
+If object is passed it should have properties `validate`, `compare` and `async`:
+
+- _validate_: a string, RegExp or a function as described above.
+- _compare_: an optional comparison function that accepts two strings and compares them according to the format meaning. This function is used with keywords `formatMaximum`/`formatMinimum` (defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package). It should return `1` if the first value is bigger than the second value, `-1` if it is smaller and `0` if it is equal.
+- _async_: an optional `true` value if `validate` is an asynchronous function; in this case it should return a promise that resolves with a value `true` or `false`.
+- _type_: an optional type of data that the format applies to. It can be `"string"` (default) or `"number"` (see https://github.com/ajv-validator/ajv/issues/291#issuecomment-259923858). If the type of data is different, the validation will pass.
+
+Custom formats can be also added via `formats` option.
+
+
+##### .addKeyword(String keyword, Object definition) -> Ajv
+
+Add custom validation keyword to Ajv instance.
+
+Keyword should be different from all standard JSON Schema keywords and different from previously defined keywords. There is no way to redefine keywords or to remove keyword definition from the instance.
+
+Keyword must start with a letter, `_` or `$`, and may continue with letters, numbers, `_`, `$`, or `-`.
+It is recommended to use an application-specific prefix for keywords to avoid current and future name collisions.
+
+Example Keywords:
+- `"xyz-example"`: valid, and uses prefix for the xyz project to avoid name collisions.
+- `"example"`: valid, but not recommended as it could collide with future versions of JSON Schema etc.
+- `"3-example"`: invalid as numbers are not allowed to be the first character in a keyword
+
+Keyword definition is an object with the following properties:
+
+- _type_: optional string or array of strings with data type(s) that the keyword applies to. If not present, the keyword will apply to all types.
+- _validate_: validating function
+- _compile_: compiling function
+- _macro_: macro function
+- _inline_: compiling function that returns code (as string)
+- _schema_: an optional `false` value used with "validate" keyword to not pass schema
+- _metaSchema_: an optional meta-schema for keyword schema
+- _dependencies_: an optional list of properties that must be present in the parent schema - it will be checked during schema compilation
+- _modifying_: `true` MUST be passed if keyword modifies data
+- _statements_: `true` can be passed in case inline keyword generates statements (as opposed to expression)
+- _valid_: pass `true`/`false` to pre-define validation result, the result returned from validation function will be ignored. This option cannot be used with macro keywords.
+- _$data_: an optional `true` value to support [$data reference](#data-reference) as the value of custom keyword. The reference will be resolved at validation time. If the keyword has meta-schema it would be extended to allow $data and it will be used to validate the resolved value. Supporting $data reference requires that keyword has validating function (as the only option or in addition to compile, macro or inline function).
+- _async_: an optional `true` value if the validation function is asynchronous (whether it is compiled or passed in _validate_ property); in this case it should return a promise that resolves with a value `true` or `false`. This option is ignored in case of "macro" and "inline" keywords.
+- _errors_: an optional boolean or string `"full"` indicating whether keyword returns errors. If this property is not set Ajv will determine if the errors were set in case of failed validation.
+
+_compile_, _macro_ and _inline_ are mutually exclusive, only one should be used at a time. _validate_ can be used separately or in addition to them to support $data reference.
+
+__Please note__: If the keyword is validating data type that is different from the type(s) in its definition, the validation function will not be called (and expanded macro will not be used), so there is no need to check for data type inside validation function or inside schema returned by macro function (unless you want to enforce a specific type and for some reason do not want to use a separate `type` keyword for that). In the same way as standard keywords work, if the keyword does not apply to the data type being validated, the validation of this keyword will succeed.
+
+See [Defining custom keywords](#defining-custom-keywords) for more details.
+
+
+##### .getKeyword(String keyword) -> Object|Boolean
+
+Returns custom keyword definition, `true` for pre-defined keywords and `false` if the keyword is unknown.
+
+
+##### .removeKeyword(String keyword) -> Ajv
+
+Removes custom or pre-defined keyword so you can redefine them.
+
+While this method can be used to extend pre-defined keywords, it can also be used to completely change their meaning - it may lead to unexpected results.
+
+__Please note__: schemas compiled before the keyword is removed will continue to work without changes. To recompile schemas use `removeSchema` method and compile them again.
+
+
+##### .errorsText([Array<Object> errors [, Object options]]) -> String
+
+Returns the text with all errors in a String.
+
+Options can have properties `separator` (string used to separate errors, ", " by default) and `dataVar` (the variable name that dataPaths are prefixed with, "data" by default).
+
+
+## Options
+
+Defaults:
+
+```javascript
+{
+ // validation and reporting options:
+ $data: false,
+ allErrors: false,
+ verbose: false,
+ $comment: false, // NEW in Ajv version 6.0
+ jsonPointers: false,
+ uniqueItems: true,
+ unicode: true,
+ nullable: false,
+ format: 'fast',
+ formats: {},
+ unknownFormats: true,
+ schemas: {},
+ logger: undefined,
+ // referenced schema options:
+ schemaId: '$id',
+ missingRefs: true,
+ extendRefs: 'ignore', // recommended 'fail'
+ loadSchema: undefined, // function(uri: string): Promise {}
+ // options to modify validated data:
+ removeAdditional: false,
+ useDefaults: false,
+ coerceTypes: false,
+ // strict mode options
+ strictDefaults: false,
+ strictKeywords: false,
+ strictNumbers: false,
+ // asynchronous validation options:
+ transpile: undefined, // requires ajv-async package
+ // advanced options:
+ meta: true,
+ validateSchema: true,
+ addUsedSchema: true,
+ inlineRefs: true,
+ passContext: false,
+ loopRequired: Infinity,
+ ownProperties: false,
+ multipleOfPrecision: false,
+ errorDataPath: 'object', // deprecated
+ messages: true,
+ sourceCode: false,
+ processCode: undefined, // function (str: string, schema: object): string {}
+ cache: new Cache,
+ serialize: undefined
+}
+```
+
+##### Validation and reporting options
+
+- _$data_: support [$data references](#data-reference). Draft 6 meta-schema that is added by default will be extended to allow them. If you want to use another meta-schema you need to use $dataMetaSchema method to add support for $data reference. See [API](#api).
+- _allErrors_: check all rules collecting all errors. Default is to return after the first error.
+- _verbose_: include the reference to the part of the schema (`schema` and `parentSchema`) and validated data in errors (false by default).
+- _$comment_ (NEW in Ajv version 6.0): log or pass the value of `$comment` keyword to a function. Option values:
+ - `false` (default): ignore $comment keyword.
+ - `true`: log the keyword value to console.
+ - function: pass the keyword value, its schema path and root schema to the specified function
+- _jsonPointers_: set `dataPath` property of errors using [JSON Pointers](https://tools.ietf.org/html/rfc6901) instead of JavaScript property access notation.
+- _uniqueItems_: validate `uniqueItems` keyword (true by default).
+- _unicode_: calculate correct length of strings with unicode pairs (true by default). Pass `false` to use `.length` of strings that is faster, but gives "incorrect" lengths of strings with unicode pairs - each unicode pair is counted as two characters.
+- _nullable_: support keyword "nullable" from [Open API 3 specification](https://swagger.io/docs/specification/data-models/data-types/).
+- _format_: formats validation mode. Option values:
+ - `"fast"` (default) - simplified and fast validation (see [Formats](#formats) for details of which formats are available and affected by this option).
+ - `"full"` - more restrictive and slow validation. E.g., 25:00:00 and 2015/14/33 will be invalid time and date in 'full' mode but it will be valid in 'fast' mode.
+ - `false` - ignore all format keywords.
+- _formats_: an object with custom formats. Keys and values will be passed to `addFormat` method.
+- _keywords_: an object with custom keywords. Keys and values will be passed to `addKeyword` method.
+- _unknownFormats_: handling of unknown formats. Option values:
+ - `true` (default) - if an unknown format is encountered the exception is thrown during schema compilation. If `format` keyword value is [$data reference](#data-reference) and it is unknown the validation will fail.
+ - `[String]` - an array of unknown format names that will be ignored. This option can be used to allow usage of third party schemas with format(s) for which you don't have definitions, but still fail if another unknown format is used. If `format` keyword value is [$data reference](#data-reference) and it is not in this array the validation will fail.
+ - `"ignore"` - to log warning during schema compilation and always pass validation (the default behaviour in versions before 5.0.0). This option is not recommended, as it allows to mistype format name and it won't be validated without any error message. This behaviour is required by JSON Schema specification.
+- _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object.
+- _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. See [Error logging](#error-logging). Option values:
+ - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown.
+ - `false` - logging is disabled.
+
+
+##### Referenced schema options
+
+- _schemaId_: this option defines which keywords are used as schema URI. Option value:
+ - `"$id"` (default) - only use `$id` keyword as schema URI (as specified in JSON Schema draft-06/07), ignore `id` keyword (if it is present a warning will be logged).
+ - `"id"` - only use `id` keyword as schema URI (as specified in JSON Schema draft-04), ignore `$id` keyword (if it is present a warning will be logged).
+ - `"auto"` - use both `$id` and `id` keywords as schema URI. If both are present (in the same schema object) and different the exception will be thrown during schema compilation.
+- _missingRefs_: handling of missing referenced schemas. Option values:
+ - `true` (default) - if the reference cannot be resolved during compilation the exception is thrown. The thrown error has properties `missingRef` (with hash fragment) and `missingSchema` (without it). Both properties are resolved relative to the current base id (usually schema id, unless it was substituted).
+ - `"ignore"` - to log error during compilation and always pass validation.
+ - `"fail"` - to log error and successfully compile schema but fail validation if this rule is checked.
+- _extendRefs_: validation of other keywords when `$ref` is present in the schema. Option values:
+ - `"ignore"` (default) - when `$ref` is used other keywords are ignored (as per [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03#section-3) standard). A warning will be logged during the schema compilation.
+ - `"fail"` (recommended) - if other validation keywords are used together with `$ref` the exception will be thrown when the schema is compiled. This option is recommended to make sure schema has no keywords that are ignored, which can be confusing.
+ - `true` - validate all keywords in the schemas with `$ref` (the default behaviour in versions before 5.0.0).
+- _loadSchema_: asynchronous function that will be used to load remote schemas when `compileAsync` [method](#api-compileAsync) is used and some reference is missing (option `missingRefs` should NOT be 'fail' or 'ignore'). This function should accept remote schema uri as a parameter and return a Promise that resolves to a schema. See example in [Asynchronous compilation](#asynchronous-schema-compilation).
+
+
+##### Options to modify validated data
+
+- _removeAdditional_: remove additional properties - see example in [Filtering data](#filtering-data). This option is not used if schema is added with `addMetaSchema` method. Option values:
+ - `false` (default) - not to remove additional properties
+ - `"all"` - all additional properties are removed, regardless of `additionalProperties` keyword in schema (and no validation is made for them).
+ - `true` - only additional properties with `additionalProperties` keyword equal to `false` are removed.
+ - `"failing"` - additional properties that fail schema validation will be removed (where `additionalProperties` keyword is `false` or schema).
+- _useDefaults_: replace missing or undefined properties and items with the values from corresponding `default` keywords. Default behaviour is to ignore `default` keywords. This option is not used if schema is added with `addMetaSchema` method. See examples in [Assigning defaults](#assigning-defaults). Option values:
+ - `false` (default) - do not use defaults
+ - `true` - insert defaults by value (object literal is used).
+ - `"empty"` - in addition to missing or undefined, use defaults for properties and items that are equal to `null` or `""` (an empty string).
+ - `"shared"` (deprecated) - insert defaults by reference. If the default is an object, it will be shared by all instances of validated data. If you modify the inserted default in the validated data, it will be modified in the schema as well.
+- _coerceTypes_: change data type of data to match `type` keyword. See the example in [Coercing data types](#coercing-data-types) and [coercion rules](https://github.com/ajv-validator/ajv/blob/master/COERCION.md). Option values:
+ - `false` (default) - no type coercion.
+ - `true` - coerce scalar data types.
+ - `"array"` - in addition to coercions between scalar types, coerce scalar data to an array with one element and vice versa (as required by the schema).
+
+
+##### Strict mode options
+
+- _strictDefaults_: report ignored `default` keywords in schemas. Option values:
+ - `false` (default) - ignored defaults are not reported
+ - `true` - if an ignored default is present, throw an error
+ - `"log"` - if an ignored default is present, log warning
+- _strictKeywords_: report unknown keywords in schemas. Option values:
+ - `false` (default) - unknown keywords are not reported
+ - `true` - if an unknown keyword is present, throw an error
+ - `"log"` - if an unknown keyword is present, log warning
+- _strictNumbers_: validate numbers strictly, failing validation for NaN and Infinity. Option values:
+ - `false` (default) - NaN or Infinity will pass validation for numeric types
+ - `true` - NaN or Infinity will not pass validation for numeric types
+
+##### Asynchronous validation options
+
+- _transpile_: Requires [ajv-async](https://github.com/ajv-validator/ajv-async) package. It determines whether Ajv transpiles compiled asynchronous validation function. Option values:
+ - `undefined` (default) - transpile with [nodent](https://github.com/MatAtBread/nodent) if async functions are not supported.
+ - `true` - always transpile with nodent.
+ - `false` - do not transpile; if async functions are not supported an exception will be thrown.
+
+
+##### Advanced options
+
+- _meta_: add [meta-schema](http://json-schema.org/documentation.html) so it can be used by other schemas (true by default). If an object is passed, it will be used as the default meta-schema for schemas that have no `$schema` keyword. This default meta-schema MUST have `$schema` keyword.
+- _validateSchema_: validate added/compiled schemas against meta-schema (true by default). `$schema` property in the schema can be http://json-schema.org/draft-07/schema or absent (draft-07 meta-schema will be used) or can be a reference to the schema previously added with `addMetaSchema` method. Option values:
+ - `true` (default) - if the validation fails, throw the exception.
+ - `"log"` - if the validation fails, log error.
+ - `false` - skip schema validation.
+- _addUsedSchema_: by default methods `compile` and `validate` add schemas to the instance if they have `$id` (or `id`) property that doesn't start with "#". If `$id` is present and it is not unique the exception will be thrown. Set this option to `false` to skip adding schemas to the instance and the `$id` uniqueness check when these methods are used. This option does not affect `addSchema` method.
+- _inlineRefs_: Affects compilation of referenced schemas. Option values:
+ - `true` (default) - the referenced schemas that don't have refs in them are inlined, regardless of their size - that substantially improves performance at the cost of the bigger size of compiled schema functions.
+ - `false` - to not inline referenced schemas (they will be compiled as separate functions).
+ - integer number - to limit the maximum number of keywords of the schema that will be inlined.
+- _passContext_: pass validation context to custom keyword functions. If this option is `true` and you pass some context to the compiled validation function with `validate.call(context, data)`, the `context` will be available as `this` in your custom keywords. By default `this` is Ajv instance.
+- _loopRequired_: by default `required` keyword is compiled into a single expression (or a sequence of statements in `allErrors` mode). In case of a very large number of properties in this keyword it may result in a very big validation function. Pass integer to set the number of properties above which `required` keyword will be validated in a loop - smaller validation function size but also worse performance.
+- _ownProperties_: by default Ajv iterates over all enumerable object properties; when this option is `true` only own enumerable object properties (i.e. found directly on the object rather than on its prototype) are iterated. Contributed by @mbroadst.
+- _multipleOfPrecision_: by default `multipleOf` keyword is validated by comparing the result of division with parseInt() of that result. It works for dividers that are bigger than 1. For small dividers such as 0.01 the result of the division is usually not integer (even when it should be integer, see issue [#84](https://github.com/ajv-validator/ajv/issues/84)). If you need to use fractional dividers set this option to some positive integer N to have `multipleOf` validated using this formula: `Math.abs(Math.round(division) - division) < 1e-N` (it is slower but allows for float arithmetics deviations).
+- _errorDataPath_ (deprecated): set `dataPath` to point to 'object' (default) or to 'property' when validating keywords `required`, `additionalProperties` and `dependencies`.
+- _messages_: Include human-readable messages in errors. `true` by default. `false` can be passed when custom messages are used (e.g. with [ajv-i18n](https://github.com/ajv-validator/ajv-i18n)).
+- _sourceCode_: add `sourceCode` property to validating function (for debugging; this code can be different from the result of toString call).
+- _processCode_: an optional function to process generated code before it is passed to Function constructor. It can be used to either beautify (the validating function is generated without line-breaks) or to transpile code. Starting from version 5.0.0 this option replaced options:
+ - `beautify` that formatted the generated function using [js-beautify](https://github.com/beautify-web/js-beautify). If you want to beautify the generated code pass a function calling `require('js-beautify').js_beautify` as `processCode: code => js_beautify(code)`.
+ - `transpile` that transpiled asynchronous validation function. You can still use `transpile` option with [ajv-async](https://github.com/ajv-validator/ajv-async) package. See [Asynchronous validation](#asynchronous-validation) for more information.
+- _cache_: an optional instance of cache to store compiled schemas using stable-stringified schema as a key. For example, set-associative cache [sacjs](https://github.com/epoberezkin/sacjs) can be used. If not passed then a simple hash is used which is good enough for the common use case (a limited number of statically defined schemas). Cache should have methods `put(key, value)`, `get(key)`, `del(key)` and `clear()`.
+- _serialize_: an optional function to serialize schema to cache key. Pass `false` to use schema itself as a key (e.g., if WeakMap used as a cache). By default [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used.
+
+
+## Validation errors
+
+In case of validation failure, Ajv assigns the array of errors to `errors` property of validation function (or to `errors` property of Ajv instance when `validate` or `validateSchema` methods were called). In case of [asynchronous validation](#asynchronous-validation), the returned promise is rejected with exception `Ajv.ValidationError` that has `errors` property.
+
+
+### Error objects
+
+Each error is an object with the following properties:
+
+- _keyword_: validation keyword.
+- _dataPath_: the path to the part of the data that was validated. By default `dataPath` uses JavaScript property access notation (e.g., `".prop[1].subProp"`). When the option `jsonPointers` is true (see [Options](#options)) `dataPath` will be set using JSON pointer standard (e.g., `"/prop/1/subProp"`).
+- _schemaPath_: the path (JSON-pointer as a URI fragment) to the schema of the keyword that failed validation.
+- _params_: the object with the additional information about error that can be used to create custom error messages (e.g., using [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) package). See below for parameters set by all keywords.
+- _message_: the standard error message (can be excluded with option `messages` set to false).
+- _schema_: the schema of the keyword (added with `verbose` option).
+- _parentSchema_: the schema containing the keyword (added with `verbose` option)
+- _data_: the data validated by the keyword (added with `verbose` option).
+
+__Please note__: `propertyNames` keyword schema validation errors have an additional property `propertyName`, `dataPath` points to the object. After schema validation for each property name, if it is invalid an additional error is added with the property `keyword` equal to `"propertyNames"`.
+
+
+### Error parameters
+
+Properties of `params` object in errors depend on the keyword that failed validation.
+
+- `maxItems`, `minItems`, `maxLength`, `minLength`, `maxProperties`, `minProperties` - property `limit` (number, the schema of the keyword).
+- `additionalItems` - property `limit` (the maximum number of allowed items in case when `items` keyword is an array of schemas and `additionalItems` is false).
+- `additionalProperties` - property `additionalProperty` (the property not used in `properties` and `patternProperties` keywords).
+- `dependencies` - properties:
+ - `property` (dependent property),
+ - `missingProperty` (required missing dependency - only the first one is reported currently)
+ - `deps` (required dependencies, comma separated list as a string),
+ - `depsCount` (the number of required dependencies).
+- `format` - property `format` (the schema of the keyword).
+- `maximum`, `minimum` - properties:
+ - `limit` (number, the schema of the keyword),
+ - `exclusive` (boolean, the schema of `exclusiveMaximum` or `exclusiveMinimum`),
+ - `comparison` (string, comparison operation to compare the data to the limit, with the data on the left and the limit on the right; can be "<", "<=", ">", ">=")
+- `multipleOf` - property `multipleOf` (the schema of the keyword)
+- `pattern` - property `pattern` (the schema of the keyword)
+- `required` - property `missingProperty` (required property that is missing).
+- `propertyNames` - property `propertyName` (an invalid property name).
+- `patternRequired` (in ajv-keywords) - property `missingPattern` (required pattern that did not match any property).
+- `type` - property `type` (required type(s), a string, can be a comma-separated list)
+- `uniqueItems` - properties `i` and `j` (indices of duplicate items).
+- `const` - property `allowedValue` pointing to the value (the schema of the keyword).
+- `enum` - property `allowedValues` pointing to the array of values (the schema of the keyword).
+- `$ref` - property `ref` with the referenced schema URI.
+- `oneOf` - property `passingSchemas` (array of indices of passing schemas, null if no schema passes).
+- custom keywords (in case keyword definition doesn't create errors) - property `keyword` (the keyword name).
+
+
+### Error logging
+
+Using the `logger` option when initiallizing Ajv will allow you to define custom logging. Here you can build upon the exisiting logging. The use of other logging packages is supported as long as the package or its associated wrapper exposes the required methods. If any of the required methods are missing an exception will be thrown.
+- **Required Methods**: `log`, `warn`, `error`
+
+```javascript
+var otherLogger = new OtherLogger();
+var ajv = new Ajv({
+ logger: {
+ log: console.log.bind(console),
+ warn: function warn() {
+ otherLogger.logWarn.apply(otherLogger, arguments);
+ },
+ error: function error() {
+ otherLogger.logError.apply(otherLogger, arguments);
+ console.error.apply(console, arguments);
+ }
+ }
+});
+```
+
+
+## Plugins
+
+Ajv can be extended with plugins that add custom keywords, formats or functions to process generated code. When such plugin is published as npm package it is recommended that it follows these conventions:
+
+- it exports a function
+- this function accepts ajv instance as the first parameter and returns the same instance to allow chaining
+- this function can accept an optional configuration as the second parameter
+
+If you have published a useful plugin please submit a PR to add it to the next section.
+
+
+## Related packages
+
+- [ajv-async](https://github.com/ajv-validator/ajv-async) - plugin to configure async validation mode
+- [ajv-bsontype](https://github.com/BoLaMN/ajv-bsontype) - plugin to validate mongodb's bsonType formats
+- [ajv-cli](https://github.com/jessedc/ajv-cli) - command line interface
+- [ajv-errors](https://github.com/ajv-validator/ajv-errors) - plugin for custom error messages
+- [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) - internationalised error messages
+- [ajv-istanbul](https://github.com/ajv-validator/ajv-istanbul) - plugin to instrument generated validation code to measure test coverage of your schemas
+- [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) - plugin with custom validation keywords (select, typeof, etc.)
+- [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) - plugin with keywords $merge and $patch
+- [ajv-pack](https://github.com/ajv-validator/ajv-pack) - produces a compact module exporting validation functions
+- [ajv-formats-draft2019](https://github.com/luzlab/ajv-formats-draft2019) - format validators for draft2019 that aren't already included in ajv (ie. `idn-hostname`, `idn-email`, `iri`, `iri-reference` and `duration`).
+
+## Some packages using Ajv
+
+- [webpack](https://github.com/webpack/webpack) - a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser
+- [jsonscript-js](https://github.com/JSONScript/jsonscript-js) - the interpreter for [JSONScript](http://www.jsonscript.org) - scripted processing of existing endpoints and services
+- [osprey-method-handler](https://github.com/mulesoft-labs/osprey-method-handler) - Express middleware for validating requests and responses based on a RAML method object, used in [osprey](https://github.com/mulesoft/osprey) - validating API proxy generated from a RAML definition
+- [har-validator](https://github.com/ahmadnassri/har-validator) - HTTP Archive (HAR) validator
+- [jsoneditor](https://github.com/josdejong/jsoneditor) - a web-based tool to view, edit, format, and validate JSON http://jsoneditoronline.org
+- [JSON Schema Lint](https://github.com/nickcmaynard/jsonschemalint) - a web tool to validate JSON/YAML document against a single JSON Schema http://jsonschemalint.com
+- [objection](https://github.com/vincit/objection.js) - SQL-friendly ORM for Node.js
+- [table](https://github.com/gajus/table) - formats data into a string table
+- [ripple-lib](https://github.com/ripple/ripple-lib) - a JavaScript API for interacting with [Ripple](https://ripple.com) in Node.js and the browser
+- [restbase](https://github.com/wikimedia/restbase) - distributed storage with REST API & dispatcher for backend services built to provide a low-latency & high-throughput API for Wikipedia / Wikimedia content
+- [hippie-swagger](https://github.com/CacheControl/hippie-swagger) - [Hippie](https://github.com/vesln/hippie) wrapper that provides end to end API testing with swagger validation
+- [react-form-controlled](https://github.com/seeden/react-form-controlled) - React controlled form components with validation
+- [rabbitmq-schema](https://github.com/tjmehta/rabbitmq-schema) - a schema definition module for RabbitMQ graphs and messages
+- [@query/schema](https://www.npmjs.com/package/@query/schema) - stream filtering with a URI-safe query syntax parsing to JSON Schema
+- [chai-ajv-json-schema](https://github.com/peon374/chai-ajv-json-schema) - chai plugin to us JSON Schema with expect in mocha tests
+- [grunt-jsonschema-ajv](https://github.com/SignpostMarv/grunt-jsonschema-ajv) - Grunt plugin for validating files against JSON Schema
+- [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) - extract text from bundle into a file
+- [electron-builder](https://github.com/electron-userland/electron-builder) - a solution to package and build a ready for distribution Electron app
+- [addons-linter](https://github.com/mozilla/addons-linter) - Mozilla Add-ons Linter
+- [gh-pages-generator](https://github.com/epoberezkin/gh-pages-generator) - multi-page site generator converting markdown files to GitHub pages
+- [ESLint](https://github.com/eslint/eslint) - the pluggable linting utility for JavaScript and JSX
+
+
+## Tests
+
+```
+npm install
+git submodule update --init
+npm test
+```
+
+## Contributing
+
+All validation functions are generated using doT templates in [dot](https://github.com/ajv-validator/ajv/tree/master/lib/dot) folder. Templates are precompiled so doT is not a run-time dependency.
+
+`npm run build` - compiles templates to [dotjs](https://github.com/ajv-validator/ajv/tree/master/lib/dotjs) folder.
+
+`npm run watch` - automatically compiles templates when files in dot folder change
+
+Please see [Contributing guidelines](https://github.com/ajv-validator/ajv/blob/master/CONTRIBUTING.md)
+
+
+## Changes history
+
+See https://github.com/ajv-validator/ajv/releases
+
+__Please note__: [Changes in version 7.0.0-beta](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0-beta.0)
+
+[Version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0).
+
+## Code of conduct
+
+Please review and follow the [Code of conduct](https://github.com/ajv-validator/ajv/blob/master/CODE_OF_CONDUCT.md).
+
+Please report any unacceptable behaviour to ajv.validator@gmail.com - it will be reviewed by the project team.
+
+
## Open-source software support
Ajv is a part of [Tidelift subscription](https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=readme) - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers.
+
## License
-[MIT](./LICENSE)
+[MIT](https://github.com/ajv-validator/ajv/blob/master/LICENSE)
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/2019.d.ts b/front_end/third_party/mcp-sdk/ajv/dist/2019.d.ts
deleted file mode 100644
index e835e2b27aa..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/2019.d.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import type { AnySchemaObject } from "./types";
-import AjvCore, { Options } from "./core";
-export declare class Ajv2019 extends AjvCore {
- constructor(opts?: Options);
- _addVocabularies(): void;
- _addDefaultMetaSchema(): void;
- defaultMeta(): string | AnySchemaObject | undefined;
-}
-export default Ajv2019;
-export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, ErrorObject, ErrorNoParams, } from "./types";
-export { Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions } from "./core";
-export { SchemaCxt, SchemaObjCxt } from "./compile";
-export { KeywordCxt } from "./compile/validate";
-export { DefinedError } from "./vocabularies/errors";
-export { JSONType } from "./compile/rules";
-export { JSONSchemaType } from "./types/json-schema";
-export { _, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions } from "./compile/codegen";
-export { default as ValidationError } from "./runtime/validation_error";
-export { default as MissingRefError } from "./compile/ref_error";
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/2019.js b/front_end/third_party/mcp-sdk/ajv/dist/2019.js
deleted file mode 100644
index bad415cc2cc..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/2019.js
+++ /dev/null
@@ -1,61 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.MissingRefError = exports.ValidationError = exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = exports.Ajv2019 = void 0;
-const core_1 = require("./core");
-const draft7_1 = require("./vocabularies/draft7");
-const dynamic_1 = require("./vocabularies/dynamic");
-const next_1 = require("./vocabularies/next");
-const unevaluated_1 = require("./vocabularies/unevaluated");
-const discriminator_1 = require("./vocabularies/discriminator");
-const json_schema_2019_09_1 = require("./refs/json-schema-2019-09");
-const META_SCHEMA_ID = "https://json-schema.org/draft/2019-09/schema";
-class Ajv2019 extends core_1.default {
- constructor(opts = {}) {
- super({
- ...opts,
- dynamicRef: true,
- next: true,
- unevaluated: true,
- });
- }
- _addVocabularies() {
- super._addVocabularies();
- this.addVocabulary(dynamic_1.default);
- draft7_1.default.forEach((v) => this.addVocabulary(v));
- this.addVocabulary(next_1.default);
- this.addVocabulary(unevaluated_1.default);
- if (this.opts.discriminator)
- this.addKeyword(discriminator_1.default);
- }
- _addDefaultMetaSchema() {
- super._addDefaultMetaSchema();
- const { $data, meta } = this.opts;
- if (!meta)
- return;
- json_schema_2019_09_1.default.call(this, $data);
- this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
- }
- defaultMeta() {
- return (this.opts.defaultMeta =
- super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined));
- }
-}
-exports.Ajv2019 = Ajv2019;
-module.exports = exports = Ajv2019;
-module.exports.Ajv2019 = Ajv2019;
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.default = Ajv2019;
-var validate_1 = require("./compile/validate");
-Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function () { return validate_1.KeywordCxt; } });
-var codegen_1 = require("./compile/codegen");
-Object.defineProperty(exports, "_", { enumerable: true, get: function () { return codegen_1._; } });
-Object.defineProperty(exports, "str", { enumerable: true, get: function () { return codegen_1.str; } });
-Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
-Object.defineProperty(exports, "nil", { enumerable: true, get: function () { return codegen_1.nil; } });
-Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return codegen_1.Name; } });
-Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function () { return codegen_1.CodeGen; } });
-var validation_error_1 = require("./runtime/validation_error");
-Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validation_error_1.default; } });
-var ref_error_1 = require("./compile/ref_error");
-Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function () { return ref_error_1.default; } });
-//# sourceMappingURL=2019.js.map
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/2019.js.map b/front_end/third_party/mcp-sdk/ajv/dist/2019.js.map
deleted file mode 100644
index 7e55d957747..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/2019.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"2019.js","sourceRoot":"","sources":["../lib/2019.ts"],"names":[],"mappings":";;;AACA,iCAAuC;AAEvC,kDAAsD;AACtD,oDAAsD;AACtD,8CAAgD;AAChD,4DAA8D;AAC9D,gEAAwD;AACxD,oEAA0D;AAE1D,MAAM,cAAc,GAAG,8CAA8C,CAAA;AAErE,MAAa,OAAQ,SAAQ,cAAO;IAClC,YAAY,OAAgB,EAAE;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,IAAI;SAClB,CAAC,CAAA;IACJ,CAAC;IAED,gBAAgB;QACd,KAAK,CAAC,gBAAgB,EAAE,CAAA;QACxB,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAA;QACrC,gBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;QACxD,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;QAClC,IAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAA;QACzC,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa;YAAE,IAAI,CAAC,UAAU,CAAC,uBAAa,CAAC,CAAA;IAC7D,CAAC;IAED,qBAAqB;QACnB,KAAK,CAAC,qBAAqB,EAAE,CAAA;QAC7B,MAAM,EAAC,KAAK,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,IAAI,CAAA;QAC/B,IAAI,CAAC,IAAI;YAAE,OAAM;QACjB,6BAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACnC,IAAI,CAAC,IAAI,CAAC,+BAA+B,CAAC,GAAG,cAAc,CAAA;IAC7D,CAAC;IAED,WAAW;QACT,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW;YAC3B,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;IACzF,CAAC;CACF;AA/BD,0BA+BC;AAED,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA;AAClC,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAA;AAChC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;AAE3D,kBAAe,OAAO,CAAA;AAyBtB,+CAA6C;AAArC,sGAAA,UAAU,OAAA;AAIlB,6CAA6F;AAArF,4FAAA,CAAC,OAAA;AAAE,8FAAA,GAAG,OAAA;AAAE,oGAAA,SAAS,OAAA;AAAE,8FAAA,GAAG,OAAA;AAAE,+FAAA,IAAI,OAAA;AAAQ,kGAAA,OAAO,OAAA;AACnD,+DAAqE;AAA7D,mHAAA,OAAO,OAAmB;AAClC,iDAA8D;AAAtD,4GAAA,OAAO,OAAmB"}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/2020.d.ts b/front_end/third_party/mcp-sdk/ajv/dist/2020.d.ts
deleted file mode 100644
index 2e56c8fcfc1..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/2020.d.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import type { AnySchemaObject } from "./types";
-import AjvCore, { Options } from "./core";
-export declare class Ajv2020 extends AjvCore {
- constructor(opts?: Options);
- _addVocabularies(): void;
- _addDefaultMetaSchema(): void;
- defaultMeta(): string | AnySchemaObject | undefined;
-}
-export default Ajv2020;
-export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, ErrorObject, ErrorNoParams, } from "./types";
-export { Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions } from "./core";
-export { SchemaCxt, SchemaObjCxt } from "./compile";
-export { KeywordCxt } from "./compile/validate";
-export { DefinedError } from "./vocabularies/errors";
-export { JSONType } from "./compile/rules";
-export { JSONSchemaType } from "./types/json-schema";
-export { _, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions } from "./compile/codegen";
-export { default as ValidationError } from "./runtime/validation_error";
-export { default as MissingRefError } from "./compile/ref_error";
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/2020.js b/front_end/third_party/mcp-sdk/ajv/dist/2020.js
deleted file mode 100644
index b3fe71cb834..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/2020.js
+++ /dev/null
@@ -1,55 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.MissingRefError = exports.ValidationError = exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = exports.Ajv2020 = void 0;
-const core_1 = require("./core");
-const draft2020_1 = require("./vocabularies/draft2020");
-const discriminator_1 = require("./vocabularies/discriminator");
-const json_schema_2020_12_1 = require("./refs/json-schema-2020-12");
-const META_SCHEMA_ID = "https://json-schema.org/draft/2020-12/schema";
-class Ajv2020 extends core_1.default {
- constructor(opts = {}) {
- super({
- ...opts,
- dynamicRef: true,
- next: true,
- unevaluated: true,
- });
- }
- _addVocabularies() {
- super._addVocabularies();
- draft2020_1.default.forEach((v) => this.addVocabulary(v));
- if (this.opts.discriminator)
- this.addKeyword(discriminator_1.default);
- }
- _addDefaultMetaSchema() {
- super._addDefaultMetaSchema();
- const { $data, meta } = this.opts;
- if (!meta)
- return;
- json_schema_2020_12_1.default.call(this, $data);
- this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
- }
- defaultMeta() {
- return (this.opts.defaultMeta =
- super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined));
- }
-}
-exports.Ajv2020 = Ajv2020;
-module.exports = exports = Ajv2020;
-module.exports.Ajv2020 = Ajv2020;
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.default = Ajv2020;
-var validate_1 = require("./compile/validate");
-Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function () { return validate_1.KeywordCxt; } });
-var codegen_1 = require("./compile/codegen");
-Object.defineProperty(exports, "_", { enumerable: true, get: function () { return codegen_1._; } });
-Object.defineProperty(exports, "str", { enumerable: true, get: function () { return codegen_1.str; } });
-Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
-Object.defineProperty(exports, "nil", { enumerable: true, get: function () { return codegen_1.nil; } });
-Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return codegen_1.Name; } });
-Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function () { return codegen_1.CodeGen; } });
-var validation_error_1 = require("./runtime/validation_error");
-Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validation_error_1.default; } });
-var ref_error_1 = require("./compile/ref_error");
-Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function () { return ref_error_1.default; } });
-//# sourceMappingURL=2020.js.map
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/2020.js.map b/front_end/third_party/mcp-sdk/ajv/dist/2020.js.map
deleted file mode 100644
index 2f4fda81e2d..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/2020.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"2020.js","sourceRoot":"","sources":["../lib/2020.ts"],"names":[],"mappings":";;;AACA,iCAAuC;AAEvC,wDAA4D;AAC5D,gEAAwD;AACxD,oEAA0D;AAE1D,MAAM,cAAc,GAAG,8CAA8C,CAAA;AAErE,MAAa,OAAQ,SAAQ,cAAO;IAClC,YAAY,OAAgB,EAAE;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,IAAI;SAClB,CAAC,CAAA;IACJ,CAAC;IAED,gBAAgB;QACd,KAAK,CAAC,gBAAgB,EAAE,CAAA;QACxB,mBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3D,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa;YAAE,IAAI,CAAC,UAAU,CAAC,uBAAa,CAAC,CAAA;IAC7D,CAAC;IAED,qBAAqB;QACnB,KAAK,CAAC,qBAAqB,EAAE,CAAA;QAC7B,MAAM,EAAC,KAAK,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,IAAI,CAAA;QAC/B,IAAI,CAAC,IAAI;YAAE,OAAM;QACjB,6BAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACnC,IAAI,CAAC,IAAI,CAAC,+BAA+B,CAAC,GAAG,cAAc,CAAA;IAC7D,CAAC;IAED,WAAW;QACT,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW;YAC3B,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;IACzF,CAAC;CACF;AA5BD,0BA4BC;AAED,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA;AAClC,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAA;AAChC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;AAE3D,kBAAe,OAAO,CAAA;AAyBtB,+CAA6C;AAArC,sGAAA,UAAU,OAAA;AAIlB,6CAA6F;AAArF,4FAAA,CAAC,OAAA;AAAE,8FAAA,GAAG,OAAA;AAAE,oGAAA,SAAS,OAAA;AAAE,8FAAA,GAAG,OAAA;AAAE,+FAAA,IAAI,OAAA;AAAQ,kGAAA,OAAO,OAAA;AACnD,+DAAqE;AAA7D,mHAAA,OAAO,OAAmB;AAClC,iDAA8D;AAAtD,4GAAA,OAAO,OAAmB"}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/ajv-esm.js b/front_end/third_party/mcp-sdk/ajv/dist/ajv-esm.js
new file mode 100644
index 00000000000..fc6d349ff67
--- /dev/null
+++ b/front_end/third_party/mcp-sdk/ajv/dist/ajv-esm.js
@@ -0,0 +1,9 @@
+// ES module wrapper for ajv.bundle.js
+import * as ajvModule from './ajv.bundle.js';
+
+// Try multiple ways to get AJV - from direct import, global, or window
+const Ajv = ajvModule.default || ajvModule.Ajv || globalThis.Ajv || window?.Ajv;
+if (!Ajv) {
+ throw new Error('AJV failed to load from bundle. ajvModule=' + typeof ajvModule + ', globalThis.Ajv=' + typeof globalThis.Ajv + ', window.Ajv=' + typeof window?.Ajv);
+}
+export default Ajv;
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/ajv.bundle.js b/front_end/third_party/mcp-sdk/ajv/dist/ajv.bundle.js
new file mode 100644
index 00000000000..e4d9d156ff7
--- /dev/null
+++ b/front_end/third_party/mcp-sdk/ajv/dist/ajv.bundle.js
@@ -0,0 +1,7189 @@
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Ajv = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
+// For the source: https://gist.github.com/dperini/729294
+// For test cases: https://mathiasbynens.be/demo/url-regex
+// @todo Delete current URL in favour of the commented out URL rule when this issue is fixed https://github.com/eslint/eslint/issues/7983.
+// var URL = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
+var URL = /^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i;
+var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
+var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
+var JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
+var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
+
+
+module.exports = formats;
+
+function formats(mode) {
+ mode = mode == 'full' ? 'full' : 'fast';
+ return util.copy(formats[mode]);
+}
+
+
+formats.fast = {
+ // date: http://tools.ietf.org/html/rfc3339#section-5.6
+ date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
+ // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
+ time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,
+ 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,
+ // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
+ uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,
+ 'uri-reference': /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,
+ 'uri-template': URITEMPLATE,
+ url: URL,
+ // email (sources from jsen validator):
+ // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
+ // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
+ email: /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
+ hostname: HOSTNAME,
+ // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
+ ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
+ // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
+ ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
+ regex: regex,
+ // uuid: http://tools.ietf.org/html/rfc4122
+ uuid: UUID,
+ // JSON-pointer: https://tools.ietf.org/html/rfc6901
+ // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
+ 'json-pointer': JSON_POINTER,
+ 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
+ // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
+ 'relative-json-pointer': RELATIVE_JSON_POINTER
+};
+
+
+formats.full = {
+ date: date,
+ time: time,
+ 'date-time': date_time,
+ uri: uri,
+ 'uri-reference': URIREF,
+ 'uri-template': URITEMPLATE,
+ url: URL,
+ email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
+ hostname: HOSTNAME,
+ ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
+ ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
+ regex: regex,
+ uuid: UUID,
+ 'json-pointer': JSON_POINTER,
+ 'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
+ 'relative-json-pointer': RELATIVE_JSON_POINTER
+};
+
+
+function isLeapYear(year) {
+ // https://tools.ietf.org/html/rfc3339#appendix-C
+ return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
+}
+
+
+function date(str) {
+ // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
+ var matches = str.match(DATE);
+ if (!matches) return false;
+
+ var year = +matches[1];
+ var month = +matches[2];
+ var day = +matches[3];
+
+ return month >= 1 && month <= 12 && day >= 1 &&
+ day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]);
+}
+
+
+function time(str, full) {
+ var matches = str.match(TIME);
+ if (!matches) return false;
+
+ var hour = matches[1];
+ var minute = matches[2];
+ var second = matches[3];
+ var timeZone = matches[5];
+ return ((hour <= 23 && minute <= 59 && second <= 59) ||
+ (hour == 23 && minute == 59 && second == 60)) &&
+ (!full || timeZone);
+}
+
+
+var DATE_TIME_SEPARATOR = /t|\s/i;
+function date_time(str) {
+ // http://tools.ietf.org/html/rfc3339#section-5.6
+ var dateTime = str.split(DATE_TIME_SEPARATOR);
+ return dateTime.length == 2 && date(dateTime[0]) && time(dateTime[1], true);
+}
+
+
+var NOT_URI_FRAGMENT = /\/|:/;
+function uri(str) {
+ // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
+ return NOT_URI_FRAGMENT.test(str) && URI.test(str);
+}
+
+
+var Z_ANCHOR = /[^\\]\\Z/;
+function regex(str) {
+ if (Z_ANCHOR.test(str)) return false;
+ try {
+ new RegExp(str);
+ return true;
+ } catch(e) {
+ return false;
+ }
+}
+
+},{"./util":10}],5:[function(require,module,exports){
+'use strict';
+
+var resolve = require('./resolve')
+ , util = require('./util')
+ , errorClasses = require('./error_classes')
+ , stableStringify = require('fast-json-stable-stringify');
+
+var validateGenerator = require('../dotjs/validate');
+
+/**
+ * Functions below are used inside compiled validations function
+ */
+
+var ucs2length = util.ucs2length;
+var equal = require('fast-deep-equal');
+
+// this error is thrown by async schemas to return validation errors via exception
+var ValidationError = errorClasses.Validation;
+
+module.exports = compile;
+
+
+/**
+ * Compiles schema to validation function
+ * @this Ajv
+ * @param {Object} schema schema object
+ * @param {Object} root object with information about the root schema for this schema
+ * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
+ * @param {String} baseId base ID for IDs in the schema
+ * @return {Function} validation function
+ */
+function compile(schema, root, localRefs, baseId) {
+ /* jshint validthis: true, evil: true */
+ /* eslint no-shadow: 0 */
+ var self = this
+ , opts = this._opts
+ , refVal = [ undefined ]
+ , refs = {}
+ , patterns = []
+ , patternsHash = {}
+ , defaults = []
+ , defaultsHash = {}
+ , customRules = [];
+
+ root = root || { schema: schema, refVal: refVal, refs: refs };
+
+ var c = checkCompiling.call(this, schema, root, baseId);
+ var compilation = this._compilations[c.index];
+ if (c.compiling) return (compilation.callValidate = callValidate);
+
+ var formats = this._formats;
+ var RULES = this.RULES;
+
+ try {
+ var v = localCompile(schema, root, localRefs, baseId);
+ compilation.validate = v;
+ var cv = compilation.callValidate;
+ if (cv) {
+ cv.schema = v.schema;
+ cv.errors = null;
+ cv.refs = v.refs;
+ cv.refVal = v.refVal;
+ cv.root = v.root;
+ cv.$async = v.$async;
+ if (opts.sourceCode) cv.source = v.source;
+ }
+ return v;
+ } finally {
+ endCompiling.call(this, schema, root, baseId);
+ }
+
+ /* @this {*} - custom context, see passContext option */
+ function callValidate() {
+ /* jshint validthis: true */
+ var validate = compilation.validate;
+ var result = validate.apply(this, arguments);
+ callValidate.errors = validate.errors;
+ return result;
+ }
+
+ function localCompile(_schema, _root, localRefs, baseId) {
+ var isRoot = !_root || (_root && _root.schema == _schema);
+ if (_root.schema != root.schema)
+ return compile.call(self, _schema, _root, localRefs, baseId);
+
+ var $async = _schema.$async === true;
+
+ var sourceCode = validateGenerator({
+ isTop: true,
+ schema: _schema,
+ isRoot: isRoot,
+ baseId: baseId,
+ root: _root,
+ schemaPath: '',
+ errSchemaPath: '#',
+ errorPath: '""',
+ MissingRefError: errorClasses.MissingRef,
+ RULES: RULES,
+ validate: validateGenerator,
+ util: util,
+ resolve: resolve,
+ resolveRef: resolveRef,
+ usePattern: usePattern,
+ useDefault: useDefault,
+ useCustomRule: useCustomRule,
+ opts: opts,
+ formats: formats,
+ logger: self.logger,
+ self: self
+ });
+
+ sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
+ + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
+ + sourceCode;
+
+ if (opts.processCode) sourceCode = opts.processCode(sourceCode, _schema);
+ // console.log('\n\n\n *** \n', JSON.stringify(sourceCode));
+ var validate;
+ try {
+ var makeValidate = new Function(
+ 'self',
+ 'RULES',
+ 'formats',
+ 'root',
+ 'refVal',
+ 'defaults',
+ 'customRules',
+ 'equal',
+ 'ucs2length',
+ 'ValidationError',
+ sourceCode
+ );
+
+ validate = makeValidate(
+ self,
+ RULES,
+ formats,
+ root,
+ refVal,
+ defaults,
+ customRules,
+ equal,
+ ucs2length,
+ ValidationError
+ );
+
+ refVal[0] = validate;
+ } catch(e) {
+ self.logger.error('Error compiling schema, function code:', sourceCode);
+ throw e;
+ }
+
+ validate.schema = _schema;
+ validate.errors = null;
+ validate.refs = refs;
+ validate.refVal = refVal;
+ validate.root = isRoot ? validate : _root;
+ if ($async) validate.$async = true;
+ if (opts.sourceCode === true) {
+ validate.source = {
+ code: sourceCode,
+ patterns: patterns,
+ defaults: defaults
+ };
+ }
+
+ return validate;
+ }
+
+ function resolveRef(baseId, ref, isRoot) {
+ ref = resolve.url(baseId, ref);
+ var refIndex = refs[ref];
+ var _refVal, refCode;
+ if (refIndex !== undefined) {
+ _refVal = refVal[refIndex];
+ refCode = 'refVal[' + refIndex + ']';
+ return resolvedRef(_refVal, refCode);
+ }
+ if (!isRoot && root.refs) {
+ var rootRefId = root.refs[ref];
+ if (rootRefId !== undefined) {
+ _refVal = root.refVal[rootRefId];
+ refCode = addLocalRef(ref, _refVal);
+ return resolvedRef(_refVal, refCode);
+ }
+ }
+
+ refCode = addLocalRef(ref);
+ var v = resolve.call(self, localCompile, root, ref);
+ if (v === undefined) {
+ var localSchema = localRefs && localRefs[ref];
+ if (localSchema) {
+ v = resolve.inlineRef(localSchema, opts.inlineRefs)
+ ? localSchema
+ : compile.call(self, localSchema, root, localRefs, baseId);
+ }
+ }
+
+ if (v === undefined) {
+ removeLocalRef(ref);
+ } else {
+ replaceLocalRef(ref, v);
+ return resolvedRef(v, refCode);
+ }
+ }
+
+ function addLocalRef(ref, v) {
+ var refId = refVal.length;
+ refVal[refId] = v;
+ refs[ref] = refId;
+ return 'refVal' + refId;
+ }
+
+ function removeLocalRef(ref) {
+ delete refs[ref];
+ }
+
+ function replaceLocalRef(ref, v) {
+ var refId = refs[ref];
+ refVal[refId] = v;
+ }
+
+ function resolvedRef(refVal, code) {
+ return typeof refVal == 'object' || typeof refVal == 'boolean'
+ ? { code: code, schema: refVal, inline: true }
+ : { code: code, $async: refVal && !!refVal.$async };
+ }
+
+ function usePattern(regexStr) {
+ var index = patternsHash[regexStr];
+ if (index === undefined) {
+ index = patternsHash[regexStr] = patterns.length;
+ patterns[index] = regexStr;
+ }
+ return 'pattern' + index;
+ }
+
+ function useDefault(value) {
+ switch (typeof value) {
+ case 'boolean':
+ case 'number':
+ return '' + value;
+ case 'string':
+ return util.toQuotedString(value);
+ case 'object':
+ if (value === null) return 'null';
+ var valueStr = stableStringify(value);
+ var index = defaultsHash[valueStr];
+ if (index === undefined) {
+ index = defaultsHash[valueStr] = defaults.length;
+ defaults[index] = value;
+ }
+ return 'default' + index;
+ }
+ }
+
+ function useCustomRule(rule, schema, parentSchema, it) {
+ if (self._opts.validateSchema !== false) {
+ var deps = rule.definition.dependencies;
+ if (deps && !deps.every(function(keyword) {
+ return Object.prototype.hasOwnProperty.call(parentSchema, keyword);
+ }))
+ throw new Error('parent schema must have all required keywords: ' + deps.join(','));
+
+ var validateSchema = rule.definition.validateSchema;
+ if (validateSchema) {
+ var valid = validateSchema(schema);
+ if (!valid) {
+ var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors);
+ if (self._opts.validateSchema == 'log') self.logger.error(message);
+ else throw new Error(message);
+ }
+ }
+ }
+
+ var compile = rule.definition.compile
+ , inline = rule.definition.inline
+ , macro = rule.definition.macro;
+
+ var validate;
+ if (compile) {
+ validate = compile.call(self, schema, parentSchema, it);
+ } else if (macro) {
+ validate = macro.call(self, schema, parentSchema, it);
+ if (opts.validateSchema !== false) self.validateSchema(validate, true);
+ } else if (inline) {
+ validate = inline.call(self, it, rule.keyword, schema, parentSchema);
+ } else {
+ validate = rule.definition.validate;
+ if (!validate) return;
+ }
+
+ if (validate === undefined)
+ throw new Error('custom keyword "' + rule.keyword + '"failed to compile');
+
+ var index = customRules.length;
+ customRules[index] = validate;
+
+ return {
+ code: 'customRule' + index,
+ validate: validate
+ };
+ }
+}
+
+
+/**
+ * Checks if the schema is currently compiled
+ * @this Ajv
+ * @param {Object} schema schema to compile
+ * @param {Object} root root object
+ * @param {String} baseId base schema ID
+ * @return {Object} object with properties "index" (compilation index) and "compiling" (boolean)
+ */
+function checkCompiling(schema, root, baseId) {
+ /* jshint validthis: true */
+ var index = compIndex.call(this, schema, root, baseId);
+ if (index >= 0) return { index: index, compiling: true };
+ index = this._compilations.length;
+ this._compilations[index] = {
+ schema: schema,
+ root: root,
+ baseId: baseId
+ };
+ return { index: index, compiling: false };
+}
+
+
+/**
+ * Removes the schema from the currently compiled list
+ * @this Ajv
+ * @param {Object} schema schema to compile
+ * @param {Object} root root object
+ * @param {String} baseId base schema ID
+ */
+function endCompiling(schema, root, baseId) {
+ /* jshint validthis: true */
+ var i = compIndex.call(this, schema, root, baseId);
+ if (i >= 0) this._compilations.splice(i, 1);
+}
+
+
+/**
+ * Index of schema compilation in the currently compiled list
+ * @this Ajv
+ * @param {Object} schema schema to compile
+ * @param {Object} root root object
+ * @param {String} baseId base schema ID
+ * @return {Integer} compilation index
+ */
+function compIndex(schema, root, baseId) {
+ /* jshint validthis: true */
+ for (var i=0; i= 0xD800 && value <= 0xDBFF && pos < len) {
+ // high surrogate, and there is a next character
+ value = str.charCodeAt(pos);
+ if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
+ }
+ }
+ return length;
+};
+
+},{}],10:[function(require,module,exports){
+'use strict';
+
+
+module.exports = {
+ copy: copy,
+ checkDataType: checkDataType,
+ checkDataTypes: checkDataTypes,
+ coerceToTypes: coerceToTypes,
+ toHash: toHash,
+ getProperty: getProperty,
+ escapeQuotes: escapeQuotes,
+ equal: require('fast-deep-equal'),
+ ucs2length: require('./ucs2length'),
+ varOccurences: varOccurences,
+ varReplace: varReplace,
+ schemaHasRules: schemaHasRules,
+ schemaHasRulesExcept: schemaHasRulesExcept,
+ schemaUnknownRules: schemaUnknownRules,
+ toQuotedString: toQuotedString,
+ getPathExpr: getPathExpr,
+ getPath: getPath,
+ getData: getData,
+ unescapeFragment: unescapeFragment,
+ unescapeJsonPointer: unescapeJsonPointer,
+ escapeFragment: escapeFragment,
+ escapeJsonPointer: escapeJsonPointer
+};
+
+
+function copy(o, to) {
+ to = to || {};
+ for (var key in o) to[key] = o[key];
+ return to;
+}
+
+
+function checkDataType(dataType, data, strictNumbers, negate) {
+ var EQUAL = negate ? ' !== ' : ' === '
+ , AND = negate ? ' || ' : ' && '
+ , OK = negate ? '!' : ''
+ , NOT = negate ? '' : '!';
+ switch (dataType) {
+ case 'null': return data + EQUAL + 'null';
+ case 'array': return OK + 'Array.isArray(' + data + ')';
+ case 'object': return '(' + OK + data + AND +
+ 'typeof ' + data + EQUAL + '"object"' + AND +
+ NOT + 'Array.isArray(' + data + '))';
+ case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
+ NOT + '(' + data + ' % 1)' +
+ AND + data + EQUAL + data +
+ (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
+ case 'number': return '(typeof ' + data + EQUAL + '"' + dataType + '"' +
+ (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
+ default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
+ }
+}
+
+
+function checkDataTypes(dataTypes, data, strictNumbers) {
+ switch (dataTypes.length) {
+ case 1: return checkDataType(dataTypes[0], data, strictNumbers, true);
+ default:
+ var code = '';
+ var types = toHash(dataTypes);
+ if (types.array && types.object) {
+ code = types.null ? '(': '(!' + data + ' || ';
+ code += 'typeof ' + data + ' !== "object")';
+ delete types.null;
+ delete types.array;
+ delete types.object;
+ }
+ if (types.number) delete types.integer;
+ for (var t in types)
+ code += (code ? ' && ' : '' ) + checkDataType(t, data, strictNumbers, true);
+
+ return code;
+ }
+}
+
+
+var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
+function coerceToTypes(optionCoerceTypes, dataTypes) {
+ if (Array.isArray(dataTypes)) {
+ var types = [];
+ for (var i=0; i= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
+ return paths[lvl - up];
+ }
+
+ if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
+ data = 'data' + ((lvl - up) || '');
+ if (!jsonPointer) return data;
+ }
+
+ var expr = data;
+ var segments = jsonPointer.split('/');
+ for (var i=0; i',
+ $notOp = $isMax ? '>' : '<',
+ $errorKeyword = undefined;
+ if (!($isData || typeof $schema == 'number' || $schema === undefined)) {
+ throw new Error($keyword + ' must be number');
+ }
+ if (!($isDataExcl || $schemaExcl === undefined || typeof $schemaExcl == 'number' || typeof $schemaExcl == 'boolean')) {
+ throw new Error($exclusiveKeyword + ' must be number or boolean');
+ }
+ if ($isDataExcl) {
+ var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
+ $exclusive = 'exclusive' + $lvl,
+ $exclType = 'exclType' + $lvl,
+ $exclIsNumber = 'exclIsNumber' + $lvl,
+ $opExpr = 'op' + $lvl,
+ $opStr = '\' + ' + $opExpr + ' + \'';
+ out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
+ $schemaValueExcl = 'schemaExcl' + $lvl;
+ out += ' var ' + ($exclusive) + '; var ' + ($exclType) + ' = typeof ' + ($schemaValueExcl) + '; if (' + ($exclType) + ' != \'boolean\' && ' + ($exclType) + ' != \'undefined\' && ' + ($exclType) + ' != \'number\') { ';
+ var $errorKeyword = $exclusiveKeyword;
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } else if ( ';
+ if ($isData) {
+ out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
+ }
+ out += ' ' + ($exclType) + ' == \'number\' ? ( (' + ($exclusive) + ' = ' + ($schemaValue) + ' === undefined || ' + ($schemaValueExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ') ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValueExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) : ( (' + ($exclusive) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = ' + ($exclusive) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\'; ';
+ if ($schema === undefined) {
+ $errorKeyword = $exclusiveKeyword;
+ $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
+ $schemaValue = $schemaValueExcl;
+ $isData = $isDataExcl;
+ }
+ } else {
+ var $exclIsNumber = typeof $schemaExcl == 'number',
+ $opStr = $op;
+ if ($exclIsNumber && $isData) {
+ var $opExpr = '\'' + $opStr + '\'';
+ out += ' if ( ';
+ if ($isData) {
+ out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
+ }
+ out += ' ( ' + ($schemaValue) + ' === undefined || ' + ($schemaExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ' ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { ';
+ } else {
+ if ($exclIsNumber && $schema === undefined) {
+ $exclusive = true;
+ $errorKeyword = $exclusiveKeyword;
+ $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
+ $schemaValue = $schemaExcl;
+ $notOp += '=';
+ } else {
+ if ($exclIsNumber) $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
+ if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
+ $exclusive = true;
+ $errorKeyword = $exclusiveKeyword;
+ $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
+ $notOp += '=';
+ } else {
+ $exclusive = false;
+ $opStr += '=';
+ }
+ }
+ var $opExpr = '\'' + $opStr + '\'';
+ out += ' if ( ';
+ if ($isData) {
+ out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
+ }
+ out += ' ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') { ';
+ }
+ }
+ $errorKeyword = $errorKeyword || $keyword;
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be ' + ($opStr) + ' ';
+ if ($isData) {
+ out += '\' + ' + ($schemaValue);
+ } else {
+ out += '' + ($schemaValue) + '\'';
+ }
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: ';
+ if ($isData) {
+ out += 'validate.schema' + ($schemaPath);
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],14:[function(require,module,exports){
+'use strict';
+module.exports = function generate__limitItems(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $errorKeyword;
+ var $data = 'data' + ($dataLvl || '');
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ if (!($isData || typeof $schema == 'number')) {
+ throw new Error($keyword + ' must be number');
+ }
+ var $op = $keyword == 'maxItems' ? '>' : '<';
+ out += 'if ( ';
+ if ($isData) {
+ out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
+ }
+ out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
+ var $errorKeyword = $keyword;
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should NOT have ';
+ if ($keyword == 'maxItems') {
+ out += 'more';
+ } else {
+ out += 'fewer';
+ }
+ out += ' than ';
+ if ($isData) {
+ out += '\' + ' + ($schemaValue) + ' + \'';
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' items\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: ';
+ if ($isData) {
+ out += 'validate.schema' + ($schemaPath);
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += '} ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],15:[function(require,module,exports){
+'use strict';
+module.exports = function generate__limitLength(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $errorKeyword;
+ var $data = 'data' + ($dataLvl || '');
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ if (!($isData || typeof $schema == 'number')) {
+ throw new Error($keyword + ' must be number');
+ }
+ var $op = $keyword == 'maxLength' ? '>' : '<';
+ out += 'if ( ';
+ if ($isData) {
+ out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
+ }
+ if (it.opts.unicode === false) {
+ out += ' ' + ($data) + '.length ';
+ } else {
+ out += ' ucs2length(' + ($data) + ') ';
+ }
+ out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
+ var $errorKeyword = $keyword;
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should NOT be ';
+ if ($keyword == 'maxLength') {
+ out += 'longer';
+ } else {
+ out += 'shorter';
+ }
+ out += ' than ';
+ if ($isData) {
+ out += '\' + ' + ($schemaValue) + ' + \'';
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' characters\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: ';
+ if ($isData) {
+ out += 'validate.schema' + ($schemaPath);
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += '} ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],16:[function(require,module,exports){
+'use strict';
+module.exports = function generate__limitProperties(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $errorKeyword;
+ var $data = 'data' + ($dataLvl || '');
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ if (!($isData || typeof $schema == 'number')) {
+ throw new Error($keyword + ' must be number');
+ }
+ var $op = $keyword == 'maxProperties' ? '>' : '<';
+ out += 'if ( ';
+ if ($isData) {
+ out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
+ }
+ out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
+ var $errorKeyword = $keyword;
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should NOT have ';
+ if ($keyword == 'maxProperties') {
+ out += 'more';
+ } else {
+ out += 'fewer';
+ }
+ out += ' than ';
+ if ($isData) {
+ out += '\' + ' + ($schemaValue) + ' + \'';
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' properties\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: ';
+ if ($isData) {
+ out += 'validate.schema' + ($schemaPath);
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += '} ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],17:[function(require,module,exports){
+'use strict';
+module.exports = function generate_allOf(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $it = it.util.copy(it);
+ var $closingBraces = '';
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ var $currentBaseId = $it.baseId,
+ $allSchemasEmpty = true;
+ var arr1 = $schema;
+ if (arr1) {
+ var $sch, $i = -1,
+ l1 = arr1.length - 1;
+ while ($i < l1) {
+ $sch = arr1[$i += 1];
+ if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
+ $allSchemasEmpty = false;
+ $it.schema = $sch;
+ $it.schemaPath = $schemaPath + '[' + $i + ']';
+ $it.errSchemaPath = $errSchemaPath + '/' + $i;
+ out += ' ' + (it.validate($it)) + ' ';
+ $it.baseId = $currentBaseId;
+ if ($breakOnError) {
+ out += ' if (' + ($nextValid) + ') { ';
+ $closingBraces += '}';
+ }
+ }
+ }
+ }
+ if ($breakOnError) {
+ if ($allSchemasEmpty) {
+ out += ' if (true) { ';
+ } else {
+ out += ' ' + ($closingBraces.slice(0, -1)) + ' ';
+ }
+ }
+ return out;
+}
+
+},{}],18:[function(require,module,exports){
+'use strict';
+module.exports = function generate_anyOf(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $errs = 'errs__' + $lvl;
+ var $it = it.util.copy(it);
+ var $closingBraces = '';
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ var $noEmptySchema = $schema.every(function($sch) {
+ return (it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all));
+ });
+ if ($noEmptySchema) {
+ var $currentBaseId = $it.baseId;
+ out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
+ var $wasComposite = it.compositeRule;
+ it.compositeRule = $it.compositeRule = true;
+ var arr1 = $schema;
+ if (arr1) {
+ var $sch, $i = -1,
+ l1 = arr1.length - 1;
+ while ($i < l1) {
+ $sch = arr1[$i += 1];
+ $it.schema = $sch;
+ $it.schemaPath = $schemaPath + '[' + $i + ']';
+ $it.errSchemaPath = $errSchemaPath + '/' + $i;
+ out += ' ' + (it.validate($it)) + ' ';
+ $it.baseId = $currentBaseId;
+ out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { ';
+ $closingBraces += '}';
+ }
+ }
+ it.compositeRule = $it.compositeRule = $wasComposite;
+ out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should match some schema in anyOf\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError(vErrors); ';
+ } else {
+ out += ' validate.errors = vErrors; return false; ';
+ }
+ }
+ out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
+ if (it.opts.allErrors) {
+ out += ' } ';
+ }
+ } else {
+ if ($breakOnError) {
+ out += ' if (true) { ';
+ }
+ }
+ return out;
+}
+
+},{}],19:[function(require,module,exports){
+'use strict';
+module.exports = function generate_comment(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $schema = it.schema[$keyword];
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $comment = it.util.toQuotedString($schema);
+ if (it.opts.$comment === true) {
+ out += ' console.log(' + ($comment) + ');';
+ } else if (typeof it.opts.$comment == 'function') {
+ out += ' self._opts.$comment(' + ($comment) + ', ' + (it.util.toQuotedString($errSchemaPath)) + ', validate.root.schema);';
+ }
+ return out;
+}
+
+},{}],20:[function(require,module,exports){
+'use strict';
+module.exports = function generate_const(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ if (!$isData) {
+ out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
+ }
+ out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValue: schema' + ($lvl) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be equal to constant\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' }';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],21:[function(require,module,exports){
+'use strict';
+module.exports = function generate_contains(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $errs = 'errs__' + $lvl;
+ var $it = it.util.copy(it);
+ var $closingBraces = '';
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ var $idx = 'i' + $lvl,
+ $dataNxt = $it.dataLevel = it.dataLevel + 1,
+ $nextData = 'data' + $dataNxt,
+ $currentBaseId = it.baseId,
+ $nonEmptySchema = (it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all));
+ out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
+ if ($nonEmptySchema) {
+ var $wasComposite = it.compositeRule;
+ it.compositeRule = $it.compositeRule = true;
+ $it.schema = $schema;
+ $it.schemaPath = $schemaPath;
+ $it.errSchemaPath = $errSchemaPath;
+ out += ' var ' + ($nextValid) + ' = false; for (var ' + ($idx) + ' = 0; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
+ $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
+ var $passData = $data + '[' + $idx + ']';
+ $it.dataPathArr[$dataNxt] = $idx;
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
+ } else {
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
+ }
+ out += ' if (' + ($nextValid) + ') break; } ';
+ it.compositeRule = $it.compositeRule = $wasComposite;
+ out += ' ' + ($closingBraces) + ' if (!' + ($nextValid) + ') {';
+ } else {
+ out += ' if (' + ($data) + '.length == 0) {';
+ }
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('contains') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should contain a valid item\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } else { ';
+ if ($nonEmptySchema) {
+ out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
+ }
+ if (it.opts.allErrors) {
+ out += ' } ';
+ }
+ return out;
+}
+
+},{}],22:[function(require,module,exports){
+'use strict';
+module.exports = function generate_custom(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $errorKeyword;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $errs = 'errs__' + $lvl;
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ var $rule = this,
+ $definition = 'definition' + $lvl,
+ $rDef = $rule.definition,
+ $closingBraces = '';
+ var $compile, $inline, $macro, $ruleValidate, $validateCode;
+ if ($isData && $rDef.$data) {
+ $validateCode = 'keywordValidate' + $lvl;
+ var $validateSchema = $rDef.validateSchema;
+ out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;';
+ } else {
+ $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
+ if (!$ruleValidate) return;
+ $schemaValue = 'validate.schema' + $schemaPath;
+ $validateCode = $ruleValidate.code;
+ $compile = $rDef.compile;
+ $inline = $rDef.inline;
+ $macro = $rDef.macro;
+ }
+ var $ruleErrs = $validateCode + '.errors',
+ $i = 'i' + $lvl,
+ $ruleErr = 'ruleErr' + $lvl,
+ $asyncKeyword = $rDef.async;
+ if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
+ if (!($inline || $macro)) {
+ out += '' + ($ruleErrs) + ' = null;';
+ }
+ out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
+ if ($isData && $rDef.$data) {
+ $closingBraces += '}';
+ out += ' if (' + ($schemaValue) + ' === undefined) { ' + ($valid) + ' = true; } else { ';
+ if ($validateSchema) {
+ $closingBraces += '}';
+ out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') { ';
+ }
+ }
+ if ($inline) {
+ if ($rDef.statements) {
+ out += ' ' + ($ruleValidate.validate) + ' ';
+ } else {
+ out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; ';
+ }
+ } else if ($macro) {
+ var $it = it.util.copy(it);
+ var $closingBraces = '';
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ $it.schema = $ruleValidate.validate;
+ $it.schemaPath = '';
+ var $wasComposite = it.compositeRule;
+ it.compositeRule = $it.compositeRule = true;
+ var $code = it.validate($it).replace(/validate\.schema/g, $validateCode);
+ it.compositeRule = $it.compositeRule = $wasComposite;
+ out += ' ' + ($code);
+ } else {
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = '';
+ out += ' ' + ($validateCode) + '.call( ';
+ if (it.opts.passContext) {
+ out += 'this';
+ } else {
+ out += 'self';
+ }
+ if ($compile || $rDef.schema === false) {
+ out += ' , ' + ($data) + ' ';
+ } else {
+ out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
+ }
+ out += ' , (dataPath || \'\')';
+ if (it.errorPath != '""') {
+ out += ' + ' + (it.errorPath);
+ }
+ var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
+ $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
+ out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) ';
+ var def_callRuleValidate = out;
+ out = $$outStack.pop();
+ if ($rDef.errors === false) {
+ out += ' ' + ($valid) + ' = ';
+ if ($asyncKeyword) {
+ out += 'await ';
+ }
+ out += '' + (def_callRuleValidate) + '; ';
+ } else {
+ if ($asyncKeyword) {
+ $ruleErrs = 'customErrors' + $lvl;
+ out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = await ' + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
+ } else {
+ out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; ';
+ }
+ }
+ }
+ if ($rDef.modifying) {
+ out += ' if (' + ($parentData) + ') ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];';
+ }
+ out += '' + ($closingBraces);
+ if ($rDef.valid) {
+ if ($breakOnError) {
+ out += ' if (true) { ';
+ }
+ } else {
+ out += ' if ( ';
+ if ($rDef.valid === undefined) {
+ out += ' !';
+ if ($macro) {
+ out += '' + ($nextValid);
+ } else {
+ out += '' + ($valid);
+ }
+ } else {
+ out += ' ' + (!$rDef.valid) + ' ';
+ }
+ out += ') { ';
+ $errorKeyword = $rule.keyword;
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = '';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ var def_customError = out;
+ out = $$outStack.pop();
+ if ($inline) {
+ if ($rDef.errors) {
+ if ($rDef.errors != 'full') {
+ out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + ' 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
+ out += ' ' + ($nextValid) + ' = true; if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
+ if ($ownProperties) {
+ out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
+ }
+ out += ') { ';
+ $it.schema = $sch;
+ $it.schemaPath = $schemaPath + it.util.getProperty($property);
+ $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
+ out += ' ' + (it.validate($it)) + ' ';
+ $it.baseId = $currentBaseId;
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' if (' + ($nextValid) + ') { ';
+ $closingBraces += '}';
+ }
+ }
+ }
+ if ($breakOnError) {
+ out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
+ }
+ return out;
+}
+
+},{}],24:[function(require,module,exports){
+'use strict';
+module.exports = function generate_enum(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ var $i = 'i' + $lvl,
+ $vSchema = 'schema' + $lvl;
+ if (!$isData) {
+ out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + ';';
+ }
+ out += 'var ' + ($valid) + ';';
+ if ($isData) {
+ out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
+ }
+ out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<' + ($vSchema) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
+ if ($isData) {
+ out += ' } ';
+ }
+ out += ' if (!' + ($valid) + ') { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValues: schema' + ($lvl) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be equal to one of the allowed values\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' }';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],25:[function(require,module,exports){
+'use strict';
+module.exports = function generate_format(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ if (it.opts.format === false) {
+ if ($breakOnError) {
+ out += ' if (true) { ';
+ }
+ return out;
+ }
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ var $unknownFormats = it.opts.unknownFormats,
+ $allowUnknown = Array.isArray($unknownFormats);
+ if ($isData) {
+ var $format = 'format' + $lvl,
+ $isObject = 'isObject' + $lvl,
+ $formatType = 'formatType' + $lvl;
+ out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var ' + ($isObject) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; var ' + ($formatType) + ' = ' + ($isObject) + ' && ' + ($format) + '.type || \'string\'; if (' + ($isObject) + ') { ';
+ if (it.async) {
+ out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; ';
+ }
+ out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
+ if ($isData) {
+ out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
+ }
+ out += ' (';
+ if ($unknownFormats != 'ignore') {
+ out += ' (' + ($schemaValue) + ' && !' + ($format) + ' ';
+ if ($allowUnknown) {
+ out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 ';
+ }
+ out += ') || ';
+ }
+ out += ' (' + ($format) + ' && ' + ($formatType) + ' == \'' + ($ruleType) + '\' && !(typeof ' + ($format) + ' == \'function\' ? ';
+ if (it.async) {
+ out += ' (async' + ($lvl) + ' ? await ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
+ } else {
+ out += ' ' + ($format) + '(' + ($data) + ') ';
+ }
+ out += ' : ' + ($format) + '.test(' + ($data) + '))))) {';
+ } else {
+ var $format = it.formats[$schema];
+ if (!$format) {
+ if ($unknownFormats == 'ignore') {
+ it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
+ if ($breakOnError) {
+ out += ' if (true) { ';
+ }
+ return out;
+ } else if ($allowUnknown && $unknownFormats.indexOf($schema) >= 0) {
+ if ($breakOnError) {
+ out += ' if (true) { ';
+ }
+ return out;
+ } else {
+ throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"');
+ }
+ }
+ var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
+ var $formatType = $isObject && $format.type || 'string';
+ if ($isObject) {
+ var $async = $format.async === true;
+ $format = $format.validate;
+ }
+ if ($formatType != $ruleType) {
+ if ($breakOnError) {
+ out += ' if (true) { ';
+ }
+ return out;
+ }
+ if ($async) {
+ if (!it.async) throw new Error('async format in sync schema');
+ var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
+ out += ' if (!(await ' + ($formatRef) + '(' + ($data) + '))) { ';
+ } else {
+ out += ' if (! ';
+ var $formatRef = 'formats' + it.util.getProperty($schema);
+ if ($isObject) $formatRef += '.validate';
+ if (typeof $format == 'function') {
+ out += ' ' + ($formatRef) + '(' + ($data) + ') ';
+ } else {
+ out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
+ }
+ out += ') { ';
+ }
+ }
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format: ';
+ if ($isData) {
+ out += '' + ($schemaValue);
+ } else {
+ out += '' + (it.util.toQuotedString($schema));
+ }
+ out += ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should match format "';
+ if ($isData) {
+ out += '\' + ' + ($schemaValue) + ' + \'';
+ } else {
+ out += '' + (it.util.escapeQuotes($schema));
+ }
+ out += '"\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: ';
+ if ($isData) {
+ out += 'validate.schema' + ($schemaPath);
+ } else {
+ out += '' + (it.util.toQuotedString($schema));
+ }
+ out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],26:[function(require,module,exports){
+'use strict';
+module.exports = function generate_if(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $errs = 'errs__' + $lvl;
+ var $it = it.util.copy(it);
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ var $thenSch = it.schema['then'],
+ $elseSch = it.schema['else'],
+ $thenPresent = $thenSch !== undefined && (it.opts.strictKeywords ? (typeof $thenSch == 'object' && Object.keys($thenSch).length > 0) || $thenSch === false : it.util.schemaHasRules($thenSch, it.RULES.all)),
+ $elsePresent = $elseSch !== undefined && (it.opts.strictKeywords ? (typeof $elseSch == 'object' && Object.keys($elseSch).length > 0) || $elseSch === false : it.util.schemaHasRules($elseSch, it.RULES.all)),
+ $currentBaseId = $it.baseId;
+ if ($thenPresent || $elsePresent) {
+ var $ifClause;
+ $it.createErrors = false;
+ $it.schema = $schema;
+ $it.schemaPath = $schemaPath;
+ $it.errSchemaPath = $errSchemaPath;
+ out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = true; ';
+ var $wasComposite = it.compositeRule;
+ it.compositeRule = $it.compositeRule = true;
+ out += ' ' + (it.validate($it)) + ' ';
+ $it.baseId = $currentBaseId;
+ $it.createErrors = true;
+ out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
+ it.compositeRule = $it.compositeRule = $wasComposite;
+ if ($thenPresent) {
+ out += ' if (' + ($nextValid) + ') { ';
+ $it.schema = it.schema['then'];
+ $it.schemaPath = it.schemaPath + '.then';
+ $it.errSchemaPath = it.errSchemaPath + '/then';
+ out += ' ' + (it.validate($it)) + ' ';
+ $it.baseId = $currentBaseId;
+ out += ' ' + ($valid) + ' = ' + ($nextValid) + '; ';
+ if ($thenPresent && $elsePresent) {
+ $ifClause = 'ifClause' + $lvl;
+ out += ' var ' + ($ifClause) + ' = \'then\'; ';
+ } else {
+ $ifClause = '\'then\'';
+ }
+ out += ' } ';
+ if ($elsePresent) {
+ out += ' else { ';
+ }
+ } else {
+ out += ' if (!' + ($nextValid) + ') { ';
+ }
+ if ($elsePresent) {
+ $it.schema = it.schema['else'];
+ $it.schemaPath = it.schemaPath + '.else';
+ $it.errSchemaPath = it.errSchemaPath + '/else';
+ out += ' ' + (it.validate($it)) + ' ';
+ $it.baseId = $currentBaseId;
+ out += ' ' + ($valid) + ' = ' + ($nextValid) + '; ';
+ if ($thenPresent && $elsePresent) {
+ $ifClause = 'ifClause' + $lvl;
+ out += ' var ' + ($ifClause) + ' = \'else\'; ';
+ } else {
+ $ifClause = '\'else\'';
+ }
+ out += ' } ';
+ }
+ out += ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('if') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { failingKeyword: ' + ($ifClause) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should match "\' + ' + ($ifClause) + ' + \'" schema\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError(vErrors); ';
+ } else {
+ out += ' validate.errors = vErrors; return false; ';
+ }
+ }
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ } else {
+ if ($breakOnError) {
+ out += ' if (true) { ';
+ }
+ }
+ return out;
+}
+
+},{}],27:[function(require,module,exports){
+'use strict';
+
+//all requires must be explicit because browserify won't work with dynamic requires
+module.exports = {
+ '$ref': require('./ref'),
+ allOf: require('./allOf'),
+ anyOf: require('./anyOf'),
+ '$comment': require('./comment'),
+ const: require('./const'),
+ contains: require('./contains'),
+ dependencies: require('./dependencies'),
+ 'enum': require('./enum'),
+ format: require('./format'),
+ 'if': require('./if'),
+ items: require('./items'),
+ maximum: require('./_limit'),
+ minimum: require('./_limit'),
+ maxItems: require('./_limitItems'),
+ minItems: require('./_limitItems'),
+ maxLength: require('./_limitLength'),
+ minLength: require('./_limitLength'),
+ maxProperties: require('./_limitProperties'),
+ minProperties: require('./_limitProperties'),
+ multipleOf: require('./multipleOf'),
+ not: require('./not'),
+ oneOf: require('./oneOf'),
+ pattern: require('./pattern'),
+ properties: require('./properties'),
+ propertyNames: require('./propertyNames'),
+ required: require('./required'),
+ uniqueItems: require('./uniqueItems'),
+ validate: require('./validate')
+};
+
+},{"./_limit":13,"./_limitItems":14,"./_limitLength":15,"./_limitProperties":16,"./allOf":17,"./anyOf":18,"./comment":19,"./const":20,"./contains":21,"./dependencies":23,"./enum":24,"./format":25,"./if":26,"./items":28,"./multipleOf":29,"./not":30,"./oneOf":31,"./pattern":32,"./properties":33,"./propertyNames":34,"./ref":35,"./required":36,"./uniqueItems":37,"./validate":38}],28:[function(require,module,exports){
+'use strict';
+module.exports = function generate_items(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $errs = 'errs__' + $lvl;
+ var $it = it.util.copy(it);
+ var $closingBraces = '';
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ var $idx = 'i' + $lvl,
+ $dataNxt = $it.dataLevel = it.dataLevel + 1,
+ $nextData = 'data' + $dataNxt,
+ $currentBaseId = it.baseId;
+ out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
+ if (Array.isArray($schema)) {
+ var $additionalItems = it.schema.additionalItems;
+ if ($additionalItems === false) {
+ out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; ';
+ var $currErrSchemaPath = $errSchemaPath;
+ $errSchemaPath = it.errSchemaPath + '/additionalItems';
+ out += ' if (!' + ($valid) + ') { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schema.length) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } ';
+ $errSchemaPath = $currErrSchemaPath;
+ if ($breakOnError) {
+ $closingBraces += '}';
+ out += ' else { ';
+ }
+ }
+ var arr1 = $schema;
+ if (arr1) {
+ var $sch, $i = -1,
+ l1 = arr1.length - 1;
+ while ($i < l1) {
+ $sch = arr1[$i += 1];
+ if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
+ out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
+ var $passData = $data + '[' + $i + ']';
+ $it.schema = $sch;
+ $it.schemaPath = $schemaPath + '[' + $i + ']';
+ $it.errSchemaPath = $errSchemaPath + '/' + $i;
+ $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
+ $it.dataPathArr[$dataNxt] = $i;
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
+ } else {
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
+ }
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' if (' + ($nextValid) + ') { ';
+ $closingBraces += '}';
+ }
+ }
+ }
+ }
+ if (typeof $additionalItems == 'object' && (it.opts.strictKeywords ? (typeof $additionalItems == 'object' && Object.keys($additionalItems).length > 0) || $additionalItems === false : it.util.schemaHasRules($additionalItems, it.RULES.all))) {
+ $it.schema = $additionalItems;
+ $it.schemaPath = it.schemaPath + '.additionalItems';
+ $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
+ out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var ' + ($idx) + ' = ' + ($schema.length) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
+ $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
+ var $passData = $data + '[' + $idx + ']';
+ $it.dataPathArr[$dataNxt] = $idx;
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
+ } else {
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
+ }
+ if ($breakOnError) {
+ out += ' if (!' + ($nextValid) + ') break; ';
+ }
+ out += ' } } ';
+ if ($breakOnError) {
+ out += ' if (' + ($nextValid) + ') { ';
+ $closingBraces += '}';
+ }
+ }
+ } else if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
+ $it.schema = $schema;
+ $it.schemaPath = $schemaPath;
+ $it.errSchemaPath = $errSchemaPath;
+ out += ' for (var ' + ($idx) + ' = ' + (0) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
+ $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
+ var $passData = $data + '[' + $idx + ']';
+ $it.dataPathArr[$dataNxt] = $idx;
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
+ } else {
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
+ }
+ if ($breakOnError) {
+ out += ' if (!' + ($nextValid) + ') break; ';
+ }
+ out += ' }';
+ }
+ if ($breakOnError) {
+ out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
+ }
+ return out;
+}
+
+},{}],29:[function(require,module,exports){
+'use strict';
+module.exports = function generate_multipleOf(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ if (!($isData || typeof $schema == 'number')) {
+ throw new Error($keyword + ' must be number');
+ }
+ out += 'var division' + ($lvl) + ';if (';
+ if ($isData) {
+ out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
+ }
+ out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
+ if (it.opts.multipleOfPrecision) {
+ out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
+ } else {
+ out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
+ }
+ out += ' ) ';
+ if ($isData) {
+ out += ' ) ';
+ }
+ out += ' ) { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { multipleOf: ' + ($schemaValue) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be multiple of ';
+ if ($isData) {
+ out += '\' + ' + ($schemaValue);
+ } else {
+ out += '' + ($schemaValue) + '\'';
+ }
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: ';
+ if ($isData) {
+ out += 'validate.schema' + ($schemaPath);
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += '} ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],30:[function(require,module,exports){
+'use strict';
+module.exports = function generate_not(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $errs = 'errs__' + $lvl;
+ var $it = it.util.copy(it);
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
+ $it.schema = $schema;
+ $it.schemaPath = $schemaPath;
+ $it.errSchemaPath = $errSchemaPath;
+ out += ' var ' + ($errs) + ' = errors; ';
+ var $wasComposite = it.compositeRule;
+ it.compositeRule = $it.compositeRule = true;
+ $it.createErrors = false;
+ var $allErrorsOption;
+ if ($it.opts.allErrors) {
+ $allErrorsOption = $it.opts.allErrors;
+ $it.opts.allErrors = false;
+ }
+ out += ' ' + (it.validate($it)) + ' ';
+ $it.createErrors = true;
+ if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
+ it.compositeRule = $it.compositeRule = $wasComposite;
+ out += ' if (' + ($nextValid) + ') { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should NOT be valid\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
+ if (it.opts.allErrors) {
+ out += ' } ';
+ }
+ } else {
+ out += ' var err = '; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should NOT be valid\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ if ($breakOnError) {
+ out += ' if (false) { ';
+ }
+ }
+ return out;
+}
+
+},{}],31:[function(require,module,exports){
+'use strict';
+module.exports = function generate_oneOf(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $errs = 'errs__' + $lvl;
+ var $it = it.util.copy(it);
+ var $closingBraces = '';
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ var $currentBaseId = $it.baseId,
+ $prevValid = 'prevValid' + $lvl,
+ $passingSchemas = 'passingSchemas' + $lvl;
+ out += 'var ' + ($errs) + ' = errors , ' + ($prevValid) + ' = false , ' + ($valid) + ' = false , ' + ($passingSchemas) + ' = null; ';
+ var $wasComposite = it.compositeRule;
+ it.compositeRule = $it.compositeRule = true;
+ var arr1 = $schema;
+ if (arr1) {
+ var $sch, $i = -1,
+ l1 = arr1.length - 1;
+ while ($i < l1) {
+ $sch = arr1[$i += 1];
+ if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
+ $it.schema = $sch;
+ $it.schemaPath = $schemaPath + '[' + $i + ']';
+ $it.errSchemaPath = $errSchemaPath + '/' + $i;
+ out += ' ' + (it.validate($it)) + ' ';
+ $it.baseId = $currentBaseId;
+ } else {
+ out += ' var ' + ($nextValid) + ' = true; ';
+ }
+ if ($i) {
+ out += ' if (' + ($nextValid) + ' && ' + ($prevValid) + ') { ' + ($valid) + ' = false; ' + ($passingSchemas) + ' = [' + ($passingSchemas) + ', ' + ($i) + ']; } else { ';
+ $closingBraces += '}';
+ }
+ out += ' if (' + ($nextValid) + ') { ' + ($valid) + ' = ' + ($prevValid) + ' = true; ' + ($passingSchemas) + ' = ' + ($i) + '; }';
+ }
+ }
+ it.compositeRule = $it.compositeRule = $wasComposite;
+ out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { passingSchemas: ' + ($passingSchemas) + ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should match exactly one schema in oneOf\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError(vErrors); ';
+ } else {
+ out += ' validate.errors = vErrors; return false; ';
+ }
+ }
+ out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
+ if (it.opts.allErrors) {
+ out += ' } ';
+ }
+ return out;
+}
+
+},{}],32:[function(require,module,exports){
+'use strict';
+module.exports = function generate_pattern(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
+ out += 'if ( ';
+ if ($isData) {
+ out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
+ }
+ out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { pattern: ';
+ if ($isData) {
+ out += '' + ($schemaValue);
+ } else {
+ out += '' + (it.util.toQuotedString($schema));
+ }
+ out += ' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should match pattern "';
+ if ($isData) {
+ out += '\' + ' + ($schemaValue) + ' + \'';
+ } else {
+ out += '' + (it.util.escapeQuotes($schema));
+ }
+ out += '"\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: ';
+ if ($isData) {
+ out += 'validate.schema' + ($schemaPath);
+ } else {
+ out += '' + (it.util.toQuotedString($schema));
+ }
+ out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += '} ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ return out;
+}
+
+},{}],33:[function(require,module,exports){
+'use strict';
+module.exports = function generate_properties(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $errs = 'errs__' + $lvl;
+ var $it = it.util.copy(it);
+ var $closingBraces = '';
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ var $key = 'key' + $lvl,
+ $idx = 'idx' + $lvl,
+ $dataNxt = $it.dataLevel = it.dataLevel + 1,
+ $nextData = 'data' + $dataNxt,
+ $dataProperties = 'dataProperties' + $lvl;
+ var $schemaKeys = Object.keys($schema || {}).filter(notProto),
+ $pProperties = it.schema.patternProperties || {},
+ $pPropertyKeys = Object.keys($pProperties).filter(notProto),
+ $aProperties = it.schema.additionalProperties,
+ $someProperties = $schemaKeys.length || $pPropertyKeys.length,
+ $noAdditional = $aProperties === false,
+ $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
+ $removeAdditional = it.opts.removeAdditional,
+ $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional,
+ $ownProperties = it.opts.ownProperties,
+ $currentBaseId = it.baseId;
+ var $required = it.schema.required;
+ if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) {
+ var $requiredHash = it.util.toHash($required);
+ }
+
+ function notProto(p) {
+ return p !== '__proto__';
+ }
+ out += 'var ' + ($errs) + ' = errors;var ' + ($nextValid) + ' = true;';
+ if ($ownProperties) {
+ out += ' var ' + ($dataProperties) + ' = undefined;';
+ }
+ if ($checkAdditional) {
+ if ($ownProperties) {
+ out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
+ } else {
+ out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
+ }
+ if ($someProperties) {
+ out += ' var isAdditional' + ($lvl) + ' = !(false ';
+ if ($schemaKeys.length) {
+ if ($schemaKeys.length > 8) {
+ out += ' || validate.schema' + ($schemaPath) + '.hasOwnProperty(' + ($key) + ') ';
+ } else {
+ var arr1 = $schemaKeys;
+ if (arr1) {
+ var $propertyKey, i1 = -1,
+ l1 = arr1.length - 1;
+ while (i1 < l1) {
+ $propertyKey = arr1[i1 += 1];
+ out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
+ }
+ }
+ }
+ }
+ if ($pPropertyKeys.length) {
+ var arr2 = $pPropertyKeys;
+ if (arr2) {
+ var $pProperty, $i = -1,
+ l2 = arr2.length - 1;
+ while ($i < l2) {
+ $pProperty = arr2[$i += 1];
+ out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') ';
+ }
+ }
+ }
+ out += ' ); if (isAdditional' + ($lvl) + ') { ';
+ }
+ if ($removeAdditional == 'all') {
+ out += ' delete ' + ($data) + '[' + ($key) + ']; ';
+ } else {
+ var $currentErrorPath = it.errorPath;
+ var $additionalProperty = '\' + ' + $key + ' + \'';
+ if (it.opts._errorDataPathProperty) {
+ it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
+ }
+ if ($noAdditional) {
+ if ($removeAdditional) {
+ out += ' delete ' + ($data) + '[' + ($key) + ']; ';
+ } else {
+ out += ' ' + ($nextValid) + ' = false; ';
+ var $currErrSchemaPath = $errSchemaPath;
+ $errSchemaPath = it.errSchemaPath + '/additionalProperties';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { additionalProperty: \'' + ($additionalProperty) + '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'';
+ if (it.opts._errorDataPathProperty) {
+ out += 'is an invalid additional property';
+ } else {
+ out += 'should NOT have additional properties';
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ $errSchemaPath = $currErrSchemaPath;
+ if ($breakOnError) {
+ out += ' break; ';
+ }
+ }
+ } else if ($additionalIsSchema) {
+ if ($removeAdditional == 'failing') {
+ out += ' var ' + ($errs) + ' = errors; ';
+ var $wasComposite = it.compositeRule;
+ it.compositeRule = $it.compositeRule = true;
+ $it.schema = $aProperties;
+ $it.schemaPath = it.schemaPath + '.additionalProperties';
+ $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
+ $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
+ var $passData = $data + '[' + $key + ']';
+ $it.dataPathArr[$dataNxt] = $key;
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
+ } else {
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
+ }
+ out += ' if (!' + ($nextValid) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[' + ($key) + ']; } ';
+ it.compositeRule = $it.compositeRule = $wasComposite;
+ } else {
+ $it.schema = $aProperties;
+ $it.schemaPath = it.schemaPath + '.additionalProperties';
+ $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
+ $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
+ var $passData = $data + '[' + $key + ']';
+ $it.dataPathArr[$dataNxt] = $key;
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
+ } else {
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
+ }
+ if ($breakOnError) {
+ out += ' if (!' + ($nextValid) + ') break; ';
+ }
+ }
+ }
+ it.errorPath = $currentErrorPath;
+ }
+ if ($someProperties) {
+ out += ' } ';
+ }
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' if (' + ($nextValid) + ') { ';
+ $closingBraces += '}';
+ }
+ }
+ var $useDefaults = it.opts.useDefaults && !it.compositeRule;
+ if ($schemaKeys.length) {
+ var arr3 = $schemaKeys;
+ if (arr3) {
+ var $propertyKey, i3 = -1,
+ l3 = arr3.length - 1;
+ while (i3 < l3) {
+ $propertyKey = arr3[i3 += 1];
+ var $sch = $schema[$propertyKey];
+ if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
+ var $prop = it.util.getProperty($propertyKey),
+ $passData = $data + $prop,
+ $hasDefault = $useDefaults && $sch.default !== undefined;
+ $it.schema = $sch;
+ $it.schemaPath = $schemaPath + $prop;
+ $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
+ $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
+ $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ $code = it.util.varReplace($code, $nextData, $passData);
+ var $useData = $passData;
+ } else {
+ var $useData = $nextData;
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
+ }
+ if ($hasDefault) {
+ out += ' ' + ($code) + ' ';
+ } else {
+ if ($requiredHash && $requiredHash[$propertyKey]) {
+ out += ' if ( ' + ($useData) + ' === undefined ';
+ if ($ownProperties) {
+ out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
+ }
+ out += ') { ' + ($nextValid) + ' = false; ';
+ var $currentErrorPath = it.errorPath,
+ $currErrSchemaPath = $errSchemaPath,
+ $missingProperty = it.util.escapeQuotes($propertyKey);
+ if (it.opts._errorDataPathProperty) {
+ it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
+ }
+ $errSchemaPath = it.errSchemaPath + '/required';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'';
+ if (it.opts._errorDataPathProperty) {
+ out += 'is a required property';
+ } else {
+ out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ $errSchemaPath = $currErrSchemaPath;
+ it.errorPath = $currentErrorPath;
+ out += ' } else { ';
+ } else {
+ if ($breakOnError) {
+ out += ' if ( ' + ($useData) + ' === undefined ';
+ if ($ownProperties) {
+ out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
+ }
+ out += ') { ' + ($nextValid) + ' = true; } else { ';
+ } else {
+ out += ' if (' + ($useData) + ' !== undefined ';
+ if ($ownProperties) {
+ out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
+ }
+ out += ' ) { ';
+ }
+ }
+ out += ' ' + ($code) + ' } ';
+ }
+ }
+ if ($breakOnError) {
+ out += ' if (' + ($nextValid) + ') { ';
+ $closingBraces += '}';
+ }
+ }
+ }
+ }
+ if ($pPropertyKeys.length) {
+ var arr4 = $pPropertyKeys;
+ if (arr4) {
+ var $pProperty, i4 = -1,
+ l4 = arr4.length - 1;
+ while (i4 < l4) {
+ $pProperty = arr4[i4 += 1];
+ var $sch = $pProperties[$pProperty];
+ if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
+ $it.schema = $sch;
+ $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
+ $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty);
+ if ($ownProperties) {
+ out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
+ } else {
+ out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
+ }
+ out += ' if (' + (it.usePattern($pProperty)) + '.test(' + ($key) + ')) { ';
+ $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
+ var $passData = $data + '[' + $key + ']';
+ $it.dataPathArr[$dataNxt] = $key;
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
+ } else {
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
+ }
+ if ($breakOnError) {
+ out += ' if (!' + ($nextValid) + ') break; ';
+ }
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' else ' + ($nextValid) + ' = true; ';
+ }
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' if (' + ($nextValid) + ') { ';
+ $closingBraces += '}';
+ }
+ }
+ }
+ }
+ }
+ if ($breakOnError) {
+ out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
+ }
+ return out;
+}
+
+},{}],34:[function(require,module,exports){
+'use strict';
+module.exports = function generate_propertyNames(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $errs = 'errs__' + $lvl;
+ var $it = it.util.copy(it);
+ var $closingBraces = '';
+ $it.level++;
+ var $nextValid = 'valid' + $it.level;
+ out += 'var ' + ($errs) + ' = errors;';
+ if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
+ $it.schema = $schema;
+ $it.schemaPath = $schemaPath;
+ $it.errSchemaPath = $errSchemaPath;
+ var $key = 'key' + $lvl,
+ $idx = 'idx' + $lvl,
+ $i = 'i' + $lvl,
+ $invalidName = '\' + ' + $key + ' + \'',
+ $dataNxt = $it.dataLevel = it.dataLevel + 1,
+ $nextData = 'data' + $dataNxt,
+ $dataProperties = 'dataProperties' + $lvl,
+ $ownProperties = it.opts.ownProperties,
+ $currentBaseId = it.baseId;
+ if ($ownProperties) {
+ out += ' var ' + ($dataProperties) + ' = undefined; ';
+ }
+ if ($ownProperties) {
+ out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
+ } else {
+ out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
+ }
+ out += ' var startErrs' + ($lvl) + ' = errors; ';
+ var $passData = $key;
+ var $wasComposite = it.compositeRule;
+ it.compositeRule = $it.compositeRule = true;
+ var $code = it.validate($it);
+ $it.baseId = $currentBaseId;
+ if (it.util.varOccurences($code, $nextData) < 2) {
+ out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
+ } else {
+ out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
+ }
+ it.compositeRule = $it.compositeRule = $wasComposite;
+ out += ' if (!' + ($nextValid) + ') { for (var ' + ($i) + '=startErrs' + ($lvl) + '; ' + ($i) + ' 0) || $propertySch === false : it.util.schemaHasRules($propertySch, it.RULES.all)))) {
+ $required[$required.length] = $property;
+ }
+ }
+ }
+ } else {
+ var $required = $schema;
+ }
+ }
+ if ($isData || $required.length) {
+ var $currentErrorPath = it.errorPath,
+ $loopRequired = $isData || $required.length >= it.opts.loopRequired,
+ $ownProperties = it.opts.ownProperties;
+ if ($breakOnError) {
+ out += ' var missing' + ($lvl) + '; ';
+ if ($loopRequired) {
+ if (!$isData) {
+ out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
+ }
+ var $i = 'i' + $lvl,
+ $propertyPath = 'schema' + $lvl + '[' + $i + ']',
+ $missingProperty = '\' + ' + $propertyPath + ' + \'';
+ if (it.opts._errorDataPathProperty) {
+ it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
+ }
+ out += ' var ' + ($valid) + ' = true; ';
+ if ($isData) {
+ out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
+ }
+ out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] !== undefined ';
+ if ($ownProperties) {
+ out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
+ }
+ out += '; if (!' + ($valid) + ') break; } ';
+ if ($isData) {
+ out += ' } ';
+ }
+ out += ' if (!' + ($valid) + ') { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'';
+ if (it.opts._errorDataPathProperty) {
+ out += 'is a required property';
+ } else {
+ out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } else { ';
+ } else {
+ out += ' if ( ';
+ var arr2 = $required;
+ if (arr2) {
+ var $propertyKey, $i = -1,
+ l2 = arr2.length - 1;
+ while ($i < l2) {
+ $propertyKey = arr2[$i += 1];
+ if ($i) {
+ out += ' || ';
+ }
+ var $prop = it.util.getProperty($propertyKey),
+ $useData = $data + $prop;
+ out += ' ( ( ' + ($useData) + ' === undefined ';
+ if ($ownProperties) {
+ out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
+ }
+ out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
+ }
+ }
+ out += ') { ';
+ var $propertyPath = 'missing' + $lvl,
+ $missingProperty = '\' + ' + $propertyPath + ' + \'';
+ if (it.opts._errorDataPathProperty) {
+ it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
+ }
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'';
+ if (it.opts._errorDataPathProperty) {
+ out += 'is a required property';
+ } else {
+ out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } else { ';
+ }
+ } else {
+ if ($loopRequired) {
+ if (!$isData) {
+ out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
+ }
+ var $i = 'i' + $lvl,
+ $propertyPath = 'schema' + $lvl + '[' + $i + ']',
+ $missingProperty = '\' + ' + $propertyPath + ' + \'';
+ if (it.opts._errorDataPathProperty) {
+ it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
+ }
+ if ($isData) {
+ out += ' if (' + ($vSchema) + ' && !Array.isArray(' + ($vSchema) + ')) { var err = '; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'';
+ if (it.opts._errorDataPathProperty) {
+ out += 'is a required property';
+ } else {
+ out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (' + ($vSchema) + ' !== undefined) { ';
+ }
+ out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { if (' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] === undefined ';
+ if ($ownProperties) {
+ out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
+ }
+ out += ') { var err = '; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'';
+ if (it.opts._errorDataPathProperty) {
+ out += 'is a required property';
+ } else {
+ out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
+ if ($isData) {
+ out += ' } ';
+ }
+ } else {
+ var arr3 = $required;
+ if (arr3) {
+ var $propertyKey, i3 = -1,
+ l3 = arr3.length - 1;
+ while (i3 < l3) {
+ $propertyKey = arr3[i3 += 1];
+ var $prop = it.util.getProperty($propertyKey),
+ $missingProperty = it.util.escapeQuotes($propertyKey),
+ $useData = $data + $prop;
+ if (it.opts._errorDataPathProperty) {
+ it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
+ }
+ out += ' if ( ' + ($useData) + ' === undefined ';
+ if ($ownProperties) {
+ out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
+ }
+ out += ') { var err = '; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'';
+ if (it.opts._errorDataPathProperty) {
+ out += 'is a required property';
+ } else {
+ out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
+ }
+ }
+ }
+ }
+ it.errorPath = $currentErrorPath;
+ } else if ($breakOnError) {
+ out += ' if (true) {';
+ }
+ return out;
+}
+
+},{}],37:[function(require,module,exports){
+'use strict';
+module.exports = function generate_uniqueItems(it, $keyword, $ruleType) {
+ var out = ' ';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ var $isData = it.opts.$data && $schema && $schema.$data,
+ $schemaValue;
+ if ($isData) {
+ out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
+ $schemaValue = 'schema' + $lvl;
+ } else {
+ $schemaValue = $schema;
+ }
+ if (($schema || $isData) && it.opts.uniqueItems !== false) {
+ if ($isData) {
+ out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
+ }
+ out += ' var i = ' + ($data) + '.length , ' + ($valid) + ' = true , j; if (i > 1) { ';
+ var $itemType = it.schema.items && it.schema.items.type,
+ $typeIsArray = Array.isArray($itemType);
+ if (!$itemType || $itemType == 'object' || $itemType == 'array' || ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0))) {
+ out += ' outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } ';
+ } else {
+ out += ' var itemIndices = {}, item; for (;i--;) { var item = ' + ($data) + '[i]; ';
+ var $method = 'checkDataType' + ($typeIsArray ? 's' : '');
+ out += ' if (' + (it.util[$method]($itemType, 'item', it.opts.strictNumbers, true)) + ') continue; ';
+ if ($typeIsArray) {
+ out += ' if (typeof item == \'string\') item = \'"\' + item; ';
+ }
+ out += ' if (typeof itemIndices[item] == \'number\') { ' + ($valid) + ' = false; j = itemIndices[item]; break; } itemIndices[item] = i; } ';
+ }
+ out += ' } ';
+ if ($isData) {
+ out += ' } ';
+ }
+ out += ' if (!' + ($valid) + ') { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ('uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { i: i, j: j } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: ';
+ if ($isData) {
+ out += 'validate.schema' + ($schemaPath);
+ } else {
+ out += '' + ($schema);
+ }
+ out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } ';
+ if ($breakOnError) {
+ out += ' else { ';
+ }
+ } else {
+ if ($breakOnError) {
+ out += ' if (true) { ';
+ }
+ }
+ return out;
+}
+
+},{}],38:[function(require,module,exports){
+'use strict';
+module.exports = function generate_validate(it, $keyword, $ruleType) {
+ var out = '';
+ var $async = it.schema.$async === true,
+ $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'),
+ $id = it.self._getId(it.schema);
+ if (it.opts.strictKeywords) {
+ var $unknownKwd = it.util.schemaUnknownRules(it.schema, it.RULES.keywords);
+ if ($unknownKwd) {
+ var $keywordsMsg = 'unknown keyword: ' + $unknownKwd;
+ if (it.opts.strictKeywords === 'log') it.logger.warn($keywordsMsg);
+ else throw new Error($keywordsMsg);
+ }
+ }
+ if (it.isTop) {
+ out += ' var validate = ';
+ if ($async) {
+ it.async = true;
+ out += 'async ';
+ }
+ out += 'function(data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; ';
+ if ($id && (it.opts.sourceCode || it.opts.processCode)) {
+ out += ' ' + ('/\*# sourceURL=' + $id + ' */') + ' ';
+ }
+ }
+ if (typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref)) {
+ var $keyword = 'false schema';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $errorKeyword;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ if (it.schema === false) {
+ if (it.isTop) {
+ $breakOnError = true;
+ } else {
+ out += ' var ' + ($valid) + ' = false; ';
+ }
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || 'false schema') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'boolean schema is false\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ } else {
+ if (it.isTop) {
+ if ($async) {
+ out += ' return data; ';
+ } else {
+ out += ' validate.errors = null; return true; ';
+ }
+ } else {
+ out += ' var ' + ($valid) + ' = true; ';
+ }
+ }
+ if (it.isTop) {
+ out += ' }; return validate; ';
+ }
+ return out;
+ }
+ if (it.isTop) {
+ var $top = it.isTop,
+ $lvl = it.level = 0,
+ $dataLvl = it.dataLevel = 0,
+ $data = 'data';
+ it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema));
+ it.baseId = it.baseId || it.rootId;
+ delete it.isTop;
+ it.dataPathArr = [""];
+ if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) {
+ var $defaultMsg = 'default is ignored in the schema root';
+ if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
+ else throw new Error($defaultMsg);
+ }
+ out += ' var vErrors = null; ';
+ out += ' var errors = 0; ';
+ out += ' if (rootData === undefined) rootData = data; ';
+ } else {
+ var $lvl = it.level,
+ $dataLvl = it.dataLevel,
+ $data = 'data' + ($dataLvl || '');
+ if ($id) it.baseId = it.resolve.url(it.baseId, $id);
+ if ($async && !it.async) throw new Error('async schema in sync schema');
+ out += ' var errs_' + ($lvl) + ' = errors;';
+ }
+ var $valid = 'valid' + $lvl,
+ $breakOnError = !it.opts.allErrors,
+ $closingBraces1 = '',
+ $closingBraces2 = '';
+ var $errorKeyword;
+ var $typeSchema = it.schema.type,
+ $typeIsArray = Array.isArray($typeSchema);
+ if ($typeSchema && it.opts.nullable && it.schema.nullable === true) {
+ if ($typeIsArray) {
+ if ($typeSchema.indexOf('null') == -1) $typeSchema = $typeSchema.concat('null');
+ } else if ($typeSchema != 'null') {
+ $typeSchema = [$typeSchema, 'null'];
+ $typeIsArray = true;
+ }
+ }
+ if ($typeIsArray && $typeSchema.length == 1) {
+ $typeSchema = $typeSchema[0];
+ $typeIsArray = false;
+ }
+ if (it.schema.$ref && $refKeywords) {
+ if (it.opts.extendRefs == 'fail') {
+ throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)');
+ } else if (it.opts.extendRefs !== true) {
+ $refKeywords = false;
+ it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
+ }
+ }
+ if (it.schema.$comment && it.opts.$comment) {
+ out += ' ' + (it.RULES.all.$comment.code(it, '$comment'));
+ }
+ if ($typeSchema) {
+ if (it.opts.coerceTypes) {
+ var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema);
+ }
+ var $rulesGroup = it.RULES.types[$typeSchema];
+ if ($coerceToTypes || $typeIsArray || $rulesGroup === true || ($rulesGroup && !$shouldUseGroup($rulesGroup))) {
+ var $schemaPath = it.schemaPath + '.type',
+ $errSchemaPath = it.errSchemaPath + '/type';
+ var $schemaPath = it.schemaPath + '.type',
+ $errSchemaPath = it.errSchemaPath + '/type',
+ $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
+ out += ' if (' + (it.util[$method]($typeSchema, $data, it.opts.strictNumbers, true)) + ') { ';
+ if ($coerceToTypes) {
+ var $dataType = 'dataType' + $lvl,
+ $coerced = 'coerced' + $lvl;
+ out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; var ' + ($coerced) + ' = undefined; ';
+ if (it.opts.coerceTypes == 'array') {
+ out += ' if (' + ($dataType) + ' == \'object\' && Array.isArray(' + ($data) + ') && ' + ($data) + '.length == 1) { ' + ($data) + ' = ' + ($data) + '[0]; ' + ($dataType) + ' = typeof ' + ($data) + '; if (' + (it.util.checkDataType(it.schema.type, $data, it.opts.strictNumbers)) + ') ' + ($coerced) + ' = ' + ($data) + '; } ';
+ }
+ out += ' if (' + ($coerced) + ' !== undefined) ; ';
+ var arr1 = $coerceToTypes;
+ if (arr1) {
+ var $type, $i = -1,
+ l1 = arr1.length - 1;
+ while ($i < l1) {
+ $type = arr1[$i += 1];
+ if ($type == 'string') {
+ out += ' else if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
+ } else if ($type == 'number' || $type == 'integer') {
+ out += ' else if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
+ if ($type == 'integer') {
+ out += ' && !(' + ($data) + ' % 1)';
+ }
+ out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
+ } else if ($type == 'boolean') {
+ out += ' else if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
+ } else if ($type == 'null') {
+ out += ' else if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
+ } else if (it.opts.coerceTypes == 'array' && $type == 'array') {
+ out += ' else if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; ';
+ }
+ }
+ }
+ out += ' else { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
+ }
+ out += '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be ';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } if (' + ($coerced) + ' !== undefined) { ';
+ var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
+ $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
+ out += ' ' + ($data) + ' = ' + ($coerced) + '; ';
+ if (!$dataLvl) {
+ out += 'if (' + ($parentData) + ' !== undefined)';
+ }
+ out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } ';
+ } else {
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
+ }
+ out += '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be ';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ }
+ out += ' } ';
+ }
+ }
+ if (it.schema.$ref && !$refKeywords) {
+ out += ' ' + (it.RULES.all.$ref.code(it, '$ref')) + ' ';
+ if ($breakOnError) {
+ out += ' } if (errors === ';
+ if ($top) {
+ out += '0';
+ } else {
+ out += 'errs_' + ($lvl);
+ }
+ out += ') { ';
+ $closingBraces2 += '}';
+ }
+ } else {
+ var arr2 = it.RULES;
+ if (arr2) {
+ var $rulesGroup, i2 = -1,
+ l2 = arr2.length - 1;
+ while (i2 < l2) {
+ $rulesGroup = arr2[i2 += 1];
+ if ($shouldUseGroup($rulesGroup)) {
+ if ($rulesGroup.type) {
+ out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data, it.opts.strictNumbers)) + ') { ';
+ }
+ if (it.opts.useDefaults) {
+ if ($rulesGroup.type == 'object' && it.schema.properties) {
+ var $schema = it.schema.properties,
+ $schemaKeys = Object.keys($schema);
+ var arr3 = $schemaKeys;
+ if (arr3) {
+ var $propertyKey, i3 = -1,
+ l3 = arr3.length - 1;
+ while (i3 < l3) {
+ $propertyKey = arr3[i3 += 1];
+ var $sch = $schema[$propertyKey];
+ if ($sch.default !== undefined) {
+ var $passData = $data + it.util.getProperty($propertyKey);
+ if (it.compositeRule) {
+ if (it.opts.strictDefaults) {
+ var $defaultMsg = 'default is ignored for: ' + $passData;
+ if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
+ else throw new Error($defaultMsg);
+ }
+ } else {
+ out += ' if (' + ($passData) + ' === undefined ';
+ if (it.opts.useDefaults == 'empty') {
+ out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
+ }
+ out += ' ) ' + ($passData) + ' = ';
+ if (it.opts.useDefaults == 'shared') {
+ out += ' ' + (it.useDefault($sch.default)) + ' ';
+ } else {
+ out += ' ' + (JSON.stringify($sch.default)) + ' ';
+ }
+ out += '; ';
+ }
+ }
+ }
+ }
+ } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
+ var arr4 = it.schema.items;
+ if (arr4) {
+ var $sch, $i = -1,
+ l4 = arr4.length - 1;
+ while ($i < l4) {
+ $sch = arr4[$i += 1];
+ if ($sch.default !== undefined) {
+ var $passData = $data + '[' + $i + ']';
+ if (it.compositeRule) {
+ if (it.opts.strictDefaults) {
+ var $defaultMsg = 'default is ignored for: ' + $passData;
+ if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
+ else throw new Error($defaultMsg);
+ }
+ } else {
+ out += ' if (' + ($passData) + ' === undefined ';
+ if (it.opts.useDefaults == 'empty') {
+ out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
+ }
+ out += ' ) ' + ($passData) + ' = ';
+ if (it.opts.useDefaults == 'shared') {
+ out += ' ' + (it.useDefault($sch.default)) + ' ';
+ } else {
+ out += ' ' + (JSON.stringify($sch.default)) + ' ';
+ }
+ out += '; ';
+ }
+ }
+ }
+ }
+ }
+ }
+ var arr5 = $rulesGroup.rules;
+ if (arr5) {
+ var $rule, i5 = -1,
+ l5 = arr5.length - 1;
+ while (i5 < l5) {
+ $rule = arr5[i5 += 1];
+ if ($shouldUseRule($rule)) {
+ var $code = $rule.code(it, $rule.keyword, $rulesGroup.type);
+ if ($code) {
+ out += ' ' + ($code) + ' ';
+ if ($breakOnError) {
+ $closingBraces1 += '}';
+ }
+ }
+ }
+ }
+ }
+ if ($breakOnError) {
+ out += ' ' + ($closingBraces1) + ' ';
+ $closingBraces1 = '';
+ }
+ if ($rulesGroup.type) {
+ out += ' } ';
+ if ($typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes) {
+ out += ' else { ';
+ var $schemaPath = it.schemaPath + '.type',
+ $errSchemaPath = it.errSchemaPath + '/type';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
+ }
+ out += '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be ';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) {
+ /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ out += ' } ';
+ }
+ }
+ if ($breakOnError) {
+ out += ' if (errors === ';
+ if ($top) {
+ out += '0';
+ } else {
+ out += 'errs_' + ($lvl);
+ }
+ out += ') { ';
+ $closingBraces2 += '}';
+ }
+ }
+ }
+ }
+ }
+ if ($breakOnError) {
+ out += ' ' + ($closingBraces2) + ' ';
+ }
+ if ($top) {
+ if ($async) {
+ out += ' if (errors === 0) return data; ';
+ out += ' else throw new ValidationError(vErrors); ';
+ } else {
+ out += ' validate.errors = vErrors; ';
+ out += ' return errors === 0; ';
+ }
+ out += ' }; return validate;';
+ } else {
+ out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
+ }
+
+ function $shouldUseGroup($rulesGroup) {
+ var rules = $rulesGroup.rules;
+ for (var i = 0; i < rules.length; i++)
+ if ($shouldUseRule(rules[i])) return true;
+ }
+
+ function $shouldUseRule($rule) {
+ return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImplementsSomeKeyword($rule));
+ }
+
+ function $ruleImplementsSomeKeyword($rule) {
+ var impl = $rule.implements;
+ for (var i = 0; i < impl.length; i++)
+ if (it.schema[impl[i]] !== undefined) return true;
+ }
+ return out;
+}
+
+},{}],39:[function(require,module,exports){
+'use strict';
+
+var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
+var customRuleCode = require('./dotjs/custom');
+var definitionSchema = require('./definition_schema');
+
+module.exports = {
+ add: addKeyword,
+ get: getKeyword,
+ remove: removeKeyword,
+ validate: validateKeyword
+};
+
+
+/**
+ * Define custom keyword
+ * @this Ajv
+ * @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords).
+ * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
+ * @return {Ajv} this for method chaining
+ */
+function addKeyword(keyword, definition) {
+ /* jshint validthis: true */
+ /* eslint no-shadow: 0 */
+ var RULES = this.RULES;
+ if (RULES.keywords[keyword])
+ throw new Error('Keyword ' + keyword + ' is already defined');
+
+ if (!IDENTIFIER.test(keyword))
+ throw new Error('Keyword ' + keyword + ' is not a valid identifier');
+
+ if (definition) {
+ this.validateKeyword(definition, true);
+
+ var dataType = definition.type;
+ if (Array.isArray(dataType)) {
+ for (var i=0; i 1) {
+ sets[0] = sets[0].slice(0, -1);
+ var xl = sets.length - 1;
+ for (var x = 1; x < xl; ++x) {
+ sets[x] = sets[x].slice(1, -1);
+ }
+ sets[xl] = sets[xl].slice(1);
+ return sets.join('');
+ } else {
+ return sets[0];
+ }
+}
+function subexp(str) {
+ return "(?:" + str + ")";
+}
+function typeOf(o) {
+ return o === undefined ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase();
+}
+function toUpperCase(str) {
+ return str.toUpperCase();
+}
+function toArray(obj) {
+ return obj !== undefined && obj !== null ? obj instanceof Array ? obj : typeof obj.length !== "number" || obj.split || obj.setInterval || obj.call ? [obj] : Array.prototype.slice.call(obj) : [];
+}
+function assign(target, source) {
+ var obj = target;
+ if (source) {
+ for (var key in source) {
+ obj[key] = source[key];
+ }
+ }
+ return obj;
+}
+
+function buildExps(isIRI) {
+ var ALPHA$$ = "[A-Za-z]",
+ CR$ = "[\\x0D]",
+ DIGIT$$ = "[0-9]",
+ DQUOTE$$ = "[\\x22]",
+ HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"),
+ //case-insensitive
+ LF$$ = "[\\x0A]",
+ SP$$ = "[\\x20]",
+ PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)),
+ //expanded
+ GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]",
+ SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
+ RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$),
+ UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]",
+ //subset, excludes bidi control characters
+ IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]",
+ //subset
+ UNRESERVED$$ = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$),
+ SCHEME$ = subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*"),
+ USERINFO$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]")) + "*"),
+ DEC_OCTET$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("[1-9]" + DIGIT$$) + "|" + DIGIT$$),
+ DEC_OCTET_RELAXED$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("0?[1-9]" + DIGIT$$) + "|0?0?" + DIGIT$$),
+ //relaxed parsing rules
+ IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$),
+ H16$ = subexp(HEXDIG$$ + "{1,4}"),
+ LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$),
+ IPV6ADDRESS1$ = subexp(subexp(H16$ + "\\:") + "{6}" + LS32$),
+ // 6( h16 ":" ) ls32
+ IPV6ADDRESS2$ = subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$),
+ // "::" 5( h16 ":" ) ls32
+ IPV6ADDRESS3$ = subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$),
+ //[ h16 ] "::" 4( h16 ":" ) ls32
+ IPV6ADDRESS4$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$),
+ //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
+ IPV6ADDRESS5$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$),
+ //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
+ IPV6ADDRESS6$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$),
+ //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
+ IPV6ADDRESS7$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$),
+ //[ *4( h16 ":" ) h16 ] "::" ls32
+ IPV6ADDRESS8$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$),
+ //[ *5( h16 ":" ) h16 ] "::" h16
+ IPV6ADDRESS9$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:"),
+ //[ *6( h16 ":" ) h16 ] "::"
+ IPV6ADDRESS$ = subexp([IPV6ADDRESS1$, IPV6ADDRESS2$, IPV6ADDRESS3$, IPV6ADDRESS4$, IPV6ADDRESS5$, IPV6ADDRESS6$, IPV6ADDRESS7$, IPV6ADDRESS8$, IPV6ADDRESS9$].join("|")),
+ ZONEID$ = subexp(subexp(UNRESERVED$$ + "|" + PCT_ENCODED$) + "+"),
+ //RFC 6874
+ IPV6ADDRZ$ = subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$),
+ //RFC 6874
+ IPV6ADDRZ_RELAXED$ = subexp(IPV6ADDRESS$ + subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + ZONEID$),
+ //RFC 6874, with relaxed parsing rules
+ IPVFUTURE$ = subexp("[vV]" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"),
+ IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRZ_RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"),
+ //RFC 6874
+ REG_NAME$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$)) + "*"),
+ HOST$ = subexp(IP_LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG_NAME$ + ")" + "|" + REG_NAME$),
+ PORT$ = subexp(DIGIT$$ + "*"),
+ AUTHORITY$ = subexp(subexp(USERINFO$ + "@") + "?" + HOST$ + subexp("\\:" + PORT$) + "?"),
+ PCHAR$ = subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@]")),
+ SEGMENT$ = subexp(PCHAR$ + "*"),
+ SEGMENT_NZ$ = subexp(PCHAR$ + "+"),
+ SEGMENT_NZ_NC$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\@]")) + "+"),
+ PATH_ABEMPTY$ = subexp(subexp("\\/" + SEGMENT$) + "*"),
+ PATH_ABSOLUTE$ = subexp("\\/" + subexp(SEGMENT_NZ$ + PATH_ABEMPTY$) + "?"),
+ //simplified
+ PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$),
+ //simplified
+ PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$),
+ //simplified
+ PATH_EMPTY$ = "(?!" + PCHAR$ + ")",
+ PATH$ = subexp(PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
+ QUERY$ = subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*"),
+ FRAGMENT$ = subexp(subexp(PCHAR$ + "|[\\/\\?]") + "*"),
+ HIER_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
+ URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
+ RELATIVE_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$),
+ RELATIVE$ = subexp(RELATIVE_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
+ URI_REFERENCE$ = subexp(URI$ + "|" + RELATIVE$),
+ ABSOLUTE_URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?"),
+ GENERIC_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
+ RELATIVE_REF$ = "^(){0}" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
+ ABSOLUTE_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?$",
+ SAMEDOC_REF$ = "^" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
+ AUTHORITY_REF$ = "^" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?$";
+ return {
+ NOT_SCHEME: new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
+ NOT_USERINFO: new RegExp(merge("[^\\%\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
+ NOT_HOST: new RegExp(merge("[^\\%\\[\\]\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
+ NOT_PATH: new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
+ NOT_PATH_NOSCHEME: new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
+ NOT_QUERY: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
+ NOT_FRAGMENT: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
+ ESCAPE: new RegExp(merge("[^]", UNRESERVED$$, SUB_DELIMS$$), "g"),
+ UNRESERVED: new RegExp(UNRESERVED$$, "g"),
+ OTHER_CHARS: new RegExp(merge("[^\\%]", UNRESERVED$$, RESERVED$$), "g"),
+ PCT_ENCODED: new RegExp(PCT_ENCODED$, "g"),
+ IPV4ADDRESS: new RegExp("^(" + IPV4ADDRESS$ + ")$"),
+ IPV6ADDRESS: new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$") //RFC 6874, with relaxed parsing rules
+ };
+}
+var URI_PROTOCOL = buildExps(false);
+
+var IRI_PROTOCOL = buildExps(true);
+
+var slicedToArray = function () {
+ function sliceIterator(arr, i) {
+ var _arr = [];
+ var _n = true;
+ var _d = false;
+ var _e = undefined;
+
+ try {
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
+ _arr.push(_s.value);
+
+ if (i && _arr.length === i) break;
+ }
+ } catch (err) {
+ _d = true;
+ _e = err;
+ } finally {
+ try {
+ if (!_n && _i["return"]) _i["return"]();
+ } finally {
+ if (_d) throw _e;
+ }
+ }
+
+ return _arr;
+ }
+
+ return function (arr, i) {
+ if (Array.isArray(arr)) {
+ return arr;
+ } else if (Symbol.iterator in Object(arr)) {
+ return sliceIterator(arr, i);
+ } else {
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
+ }
+ };
+}();
+
+
+
+
+
+
+
+
+
+
+
+
+
+var toConsumableArray = function (arr) {
+ if (Array.isArray(arr)) {
+ for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
+
+ return arr2;
+ } else {
+ return Array.from(arr);
+ }
+};
+
+/** Highest positive signed 32-bit float value */
+
+var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
+
+/** Bootstring parameters */
+var base = 36;
+var tMin = 1;
+var tMax = 26;
+var skew = 38;
+var damp = 700;
+var initialBias = 72;
+var initialN = 128; // 0x80
+var delimiter = '-'; // '\x2D'
+
+/** Regular expressions */
+var regexPunycode = /^xn--/;
+var regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
+var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
+
+/** Error messages */
+var errors = {
+ 'overflow': 'Overflow: input needs wider integers to process',
+ 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
+ 'invalid-input': 'Invalid input'
+};
+
+/** Convenience shortcuts */
+var baseMinusTMin = base - tMin;
+var floor = Math.floor;
+var stringFromCharCode = String.fromCharCode;
+
+/*--------------------------------------------------------------------------*/
+
+/**
+ * A generic error utility function.
+ * @private
+ * @param {String} type The error type.
+ * @returns {Error} Throws a `RangeError` with the applicable error message.
+ */
+function error$1(type) {
+ throw new RangeError(errors[type]);
+}
+
+/**
+ * A generic `Array#map` utility function.
+ * @private
+ * @param {Array} array The array to iterate over.
+ * @param {Function} callback The function that gets called for every array
+ * item.
+ * @returns {Array} A new array of values returned by the callback function.
+ */
+function map(array, fn) {
+ var result = [];
+ var length = array.length;
+ while (length--) {
+ result[length] = fn(array[length]);
+ }
+ return result;
+}
+
+/**
+ * A simple `Array#map`-like wrapper to work with domain name strings or email
+ * addresses.
+ * @private
+ * @param {String} domain The domain name or email address.
+ * @param {Function} callback The function that gets called for every
+ * character.
+ * @returns {Array} A new string of characters returned by the callback
+ * function.
+ */
+function mapDomain(string, fn) {
+ var parts = string.split('@');
+ var result = '';
+ if (parts.length > 1) {
+ // In email addresses, only the domain name should be punycoded. Leave
+ // the local part (i.e. everything up to `@`) intact.
+ result = parts[0] + '@';
+ string = parts[1];
+ }
+ // Avoid `split(regex)` for IE8 compatibility. See #17.
+ string = string.replace(regexSeparators, '\x2E');
+ var labels = string.split('.');
+ var encoded = map(labels, fn).join('.');
+ return result + encoded;
+}
+
+/**
+ * Creates an array containing the numeric code points of each Unicode
+ * character in the string. While JavaScript uses UCS-2 internally,
+ * this function will convert a pair of surrogate halves (each of which
+ * UCS-2 exposes as separate characters) into a single code point,
+ * matching UTF-16.
+ * @see `punycode.ucs2.encode`
+ * @see
+ * @memberOf punycode.ucs2
+ * @name decode
+ * @param {String} string The Unicode input string (UCS-2).
+ * @returns {Array} The new array of code points.
+ */
+function ucs2decode(string) {
+ var output = [];
+ var counter = 0;
+ var length = string.length;
+ while (counter < length) {
+ var value = string.charCodeAt(counter++);
+ if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
+ // It's a high surrogate, and there is a next character.
+ var extra = string.charCodeAt(counter++);
+ if ((extra & 0xFC00) == 0xDC00) {
+ // Low surrogate.
+ output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
+ } else {
+ // It's an unmatched surrogate; only append this code unit, in case the
+ // next code unit is the high surrogate of a surrogate pair.
+ output.push(value);
+ counter--;
+ }
+ } else {
+ output.push(value);
+ }
+ }
+ return output;
+}
+
+/**
+ * Creates a string based on an array of numeric code points.
+ * @see `punycode.ucs2.decode`
+ * @memberOf punycode.ucs2
+ * @name encode
+ * @param {Array} codePoints The array of numeric code points.
+ * @returns {String} The new Unicode string (UCS-2).
+ */
+var ucs2encode = function ucs2encode(array) {
+ return String.fromCodePoint.apply(String, toConsumableArray(array));
+};
+
+/**
+ * Converts a basic code point into a digit/integer.
+ * @see `digitToBasic()`
+ * @private
+ * @param {Number} codePoint The basic numeric code point value.
+ * @returns {Number} The numeric value of a basic code point (for use in
+ * representing integers) in the range `0` to `base - 1`, or `base` if
+ * the code point does not represent a value.
+ */
+var basicToDigit = function basicToDigit(codePoint) {
+ if (codePoint - 0x30 < 0x0A) {
+ return codePoint - 0x16;
+ }
+ if (codePoint - 0x41 < 0x1A) {
+ return codePoint - 0x41;
+ }
+ if (codePoint - 0x61 < 0x1A) {
+ return codePoint - 0x61;
+ }
+ return base;
+};
+
+/**
+ * Converts a digit/integer into a basic code point.
+ * @see `basicToDigit()`
+ * @private
+ * @param {Number} digit The numeric value of a basic code point.
+ * @returns {Number} The basic code point whose value (when used for
+ * representing integers) is `digit`, which needs to be in the range
+ * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
+ * used; else, the lowercase form is used. The behavior is undefined
+ * if `flag` is non-zero and `digit` has no uppercase form.
+ */
+var digitToBasic = function digitToBasic(digit, flag) {
+ // 0..25 map to ASCII a..z or A..Z
+ // 26..35 map to ASCII 0..9
+ return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
+};
+
+/**
+ * Bias adaptation function as per section 3.4 of RFC 3492.
+ * https://tools.ietf.org/html/rfc3492#section-3.4
+ * @private
+ */
+var adapt = function adapt(delta, numPoints, firstTime) {
+ var k = 0;
+ delta = firstTime ? floor(delta / damp) : delta >> 1;
+ delta += floor(delta / numPoints);
+ for (; /* no initialization */delta > baseMinusTMin * tMax >> 1; k += base) {
+ delta = floor(delta / baseMinusTMin);
+ }
+ return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
+};
+
+/**
+ * Converts a Punycode string of ASCII-only symbols to a string of Unicode
+ * symbols.
+ * @memberOf punycode
+ * @param {String} input The Punycode string of ASCII-only symbols.
+ * @returns {String} The resulting string of Unicode symbols.
+ */
+var decode = function decode(input) {
+ // Don't use UCS-2.
+ var output = [];
+ var inputLength = input.length;
+ var i = 0;
+ var n = initialN;
+ var bias = initialBias;
+
+ // Handle the basic code points: let `basic` be the number of input code
+ // points before the last delimiter, or `0` if there is none, then copy
+ // the first basic code points to the output.
+
+ var basic = input.lastIndexOf(delimiter);
+ if (basic < 0) {
+ basic = 0;
+ }
+
+ for (var j = 0; j < basic; ++j) {
+ // if it's not a basic code point
+ if (input.charCodeAt(j) >= 0x80) {
+ error$1('not-basic');
+ }
+ output.push(input.charCodeAt(j));
+ }
+
+ // Main decoding loop: start just after the last delimiter if any basic code
+ // points were copied; start at the beginning otherwise.
+
+ for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) /* no final expression */{
+
+ // `index` is the index of the next character to be consumed.
+ // Decode a generalized variable-length integer into `delta`,
+ // which gets added to `i`. The overflow checking is easier
+ // if we increase `i` as we go, then subtract off its starting
+ // value at the end to obtain `delta`.
+ var oldi = i;
+ for (var w = 1, k = base;; /* no condition */k += base) {
+
+ if (index >= inputLength) {
+ error$1('invalid-input');
+ }
+
+ var digit = basicToDigit(input.charCodeAt(index++));
+
+ if (digit >= base || digit > floor((maxInt - i) / w)) {
+ error$1('overflow');
+ }
+
+ i += digit * w;
+ var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
+
+ if (digit < t) {
+ break;
+ }
+
+ var baseMinusT = base - t;
+ if (w > floor(maxInt / baseMinusT)) {
+ error$1('overflow');
+ }
+
+ w *= baseMinusT;
+ }
+
+ var out = output.length + 1;
+ bias = adapt(i - oldi, out, oldi == 0);
+
+ // `i` was supposed to wrap around from `out` to `0`,
+ // incrementing `n` each time, so we'll fix that now:
+ if (floor(i / out) > maxInt - n) {
+ error$1('overflow');
+ }
+
+ n += floor(i / out);
+ i %= out;
+
+ // Insert `n` at position `i` of the output.
+ output.splice(i++, 0, n);
+ }
+
+ return String.fromCodePoint.apply(String, output);
+};
+
+/**
+ * Converts a string of Unicode symbols (e.g. a domain name label) to a
+ * Punycode string of ASCII-only symbols.
+ * @memberOf punycode
+ * @param {String} input The string of Unicode symbols.
+ * @returns {String} The resulting Punycode string of ASCII-only symbols.
+ */
+var encode = function encode(input) {
+ var output = [];
+
+ // Convert the input in UCS-2 to an array of Unicode code points.
+ input = ucs2decode(input);
+
+ // Cache the length.
+ var inputLength = input.length;
+
+ // Initialize the state.
+ var n = initialN;
+ var delta = 0;
+ var bias = initialBias;
+
+ // Handle the basic code points.
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
+
+ try {
+ for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
+ var _currentValue2 = _step.value;
+
+ if (_currentValue2 < 0x80) {
+ output.push(stringFromCharCode(_currentValue2));
+ }
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
+ }
+ }
+
+ var basicLength = output.length;
+ var handledCPCount = basicLength;
+
+ // `handledCPCount` is the number of code points that have been handled;
+ // `basicLength` is the number of basic code points.
+
+ // Finish the basic string with a delimiter unless it's empty.
+ if (basicLength) {
+ output.push(delimiter);
+ }
+
+ // Main encoding loop:
+ while (handledCPCount < inputLength) {
+
+ // All non-basic code points < n have been handled already. Find the next
+ // larger one:
+ var m = maxInt;
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
+
+ try {
+ for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
+ var currentValue = _step2.value;
+
+ if (currentValue >= n && currentValue < m) {
+ m = currentValue;
+ }
+ }
+
+ // Increase `delta` enough to advance the decoder's state to ,
+ // but guard against overflow.
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
+ }
+ }
+
+ var handledCPCountPlusOne = handledCPCount + 1;
+ if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
+ error$1('overflow');
+ }
+
+ delta += (m - n) * handledCPCountPlusOne;
+ n = m;
+
+ var _iteratorNormalCompletion3 = true;
+ var _didIteratorError3 = false;
+ var _iteratorError3 = undefined;
+
+ try {
+ for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
+ var _currentValue = _step3.value;
+
+ if (_currentValue < n && ++delta > maxInt) {
+ error$1('overflow');
+ }
+ if (_currentValue == n) {
+ // Represent delta as a generalized variable-length integer.
+ var q = delta;
+ for (var k = base;; /* no condition */k += base) {
+ var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
+ if (q < t) {
+ break;
+ }
+ var qMinusT = q - t;
+ var baseMinusT = base - t;
+ output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
+ q = floor(qMinusT / baseMinusT);
+ }
+
+ output.push(stringFromCharCode(digitToBasic(q, 0)));
+ bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
+ delta = 0;
+ ++handledCPCount;
+ }
+ }
+ } catch (err) {
+ _didIteratorError3 = true;
+ _iteratorError3 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion3 && _iterator3.return) {
+ _iterator3.return();
+ }
+ } finally {
+ if (_didIteratorError3) {
+ throw _iteratorError3;
+ }
+ }
+ }
+
+ ++delta;
+ ++n;
+ }
+ return output.join('');
+};
+
+/**
+ * Converts a Punycode string representing a domain name or an email address
+ * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
+ * it doesn't matter if you call it on a string that has already been
+ * converted to Unicode.
+ * @memberOf punycode
+ * @param {String} input The Punycoded domain name or email address to
+ * convert to Unicode.
+ * @returns {String} The Unicode representation of the given Punycode
+ * string.
+ */
+var toUnicode = function toUnicode(input) {
+ return mapDomain(input, function (string) {
+ return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
+ });
+};
+
+/**
+ * Converts a Unicode string representing a domain name or an email address to
+ * Punycode. Only the non-ASCII parts of the domain name will be converted,
+ * i.e. it doesn't matter if you call it with a domain that's already in
+ * ASCII.
+ * @memberOf punycode
+ * @param {String} input The domain name or email address to convert, as a
+ * Unicode string.
+ * @returns {String} The Punycode representation of the given domain name or
+ * email address.
+ */
+var toASCII = function toASCII(input) {
+ return mapDomain(input, function (string) {
+ return regexNonASCII.test(string) ? 'xn--' + encode(string) : string;
+ });
+};
+
+/*--------------------------------------------------------------------------*/
+
+/** Define the public API */
+var punycode = {
+ /**
+ * A string representing the current Punycode.js version number.
+ * @memberOf punycode
+ * @type String
+ */
+ 'version': '2.1.0',
+ /**
+ * An object of methods to convert from JavaScript's internal character
+ * representation (UCS-2) to Unicode code points, and back.
+ * @see
+ * @memberOf punycode
+ * @type Object
+ */
+ 'ucs2': {
+ 'decode': ucs2decode,
+ 'encode': ucs2encode
+ },
+ 'decode': decode,
+ 'encode': encode,
+ 'toASCII': toASCII,
+ 'toUnicode': toUnicode
+};
+
+/**
+ * URI.js
+ *
+ * @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
+ * @author Gary Court
+ * @see http://github.com/garycourt/uri-js
+ */
+/**
+ * Copyright 2011 Gary Court. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of Gary Court.
+ */
+var SCHEMES = {};
+function pctEncChar(chr) {
+ var c = chr.charCodeAt(0);
+ var e = void 0;
+ if (c < 16) e = "%0" + c.toString(16).toUpperCase();else if (c < 128) e = "%" + c.toString(16).toUpperCase();else if (c < 2048) e = "%" + (c >> 6 | 192).toString(16).toUpperCase() + "%" + (c & 63 | 128).toString(16).toUpperCase();else e = "%" + (c >> 12 | 224).toString(16).toUpperCase() + "%" + (c >> 6 & 63 | 128).toString(16).toUpperCase() + "%" + (c & 63 | 128).toString(16).toUpperCase();
+ return e;
+}
+function pctDecChars(str) {
+ var newStr = "";
+ var i = 0;
+ var il = str.length;
+ while (i < il) {
+ var c = parseInt(str.substr(i + 1, 2), 16);
+ if (c < 128) {
+ newStr += String.fromCharCode(c);
+ i += 3;
+ } else if (c >= 194 && c < 224) {
+ if (il - i >= 6) {
+ var c2 = parseInt(str.substr(i + 4, 2), 16);
+ newStr += String.fromCharCode((c & 31) << 6 | c2 & 63);
+ } else {
+ newStr += str.substr(i, 6);
+ }
+ i += 6;
+ } else if (c >= 224) {
+ if (il - i >= 9) {
+ var _c = parseInt(str.substr(i + 4, 2), 16);
+ var c3 = parseInt(str.substr(i + 7, 2), 16);
+ newStr += String.fromCharCode((c & 15) << 12 | (_c & 63) << 6 | c3 & 63);
+ } else {
+ newStr += str.substr(i, 9);
+ }
+ i += 9;
+ } else {
+ newStr += str.substr(i, 3);
+ i += 3;
+ }
+ }
+ return newStr;
+}
+function _normalizeComponentEncoding(components, protocol) {
+ function decodeUnreserved(str) {
+ var decStr = pctDecChars(str);
+ return !decStr.match(protocol.UNRESERVED) ? str : decStr;
+ }
+ if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
+ if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
+ if (components.host !== undefined) components.host = String(components.host).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_HOST, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
+ if (components.path !== undefined) components.path = String(components.path).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(components.scheme ? protocol.NOT_PATH : protocol.NOT_PATH_NOSCHEME, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
+ if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
+ if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
+ return components;
+}
+
+function _stripLeadingZeros(str) {
+ return str.replace(/^0*(.*)/, "$1") || "0";
+}
+function _normalizeIPv4(host, protocol) {
+ var matches = host.match(protocol.IPV4ADDRESS) || [];
+
+ var _matches = slicedToArray(matches, 2),
+ address = _matches[1];
+
+ if (address) {
+ return address.split(".").map(_stripLeadingZeros).join(".");
+ } else {
+ return host;
+ }
+}
+function _normalizeIPv6(host, protocol) {
+ var matches = host.match(protocol.IPV6ADDRESS) || [];
+
+ var _matches2 = slicedToArray(matches, 3),
+ address = _matches2[1],
+ zone = _matches2[2];
+
+ if (address) {
+ var _address$toLowerCase$ = address.toLowerCase().split('::').reverse(),
+ _address$toLowerCase$2 = slicedToArray(_address$toLowerCase$, 2),
+ last = _address$toLowerCase$2[0],
+ first = _address$toLowerCase$2[1];
+
+ var firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
+ var lastFields = last.split(":").map(_stripLeadingZeros);
+ var isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
+ var fieldCount = isLastFieldIPv4Address ? 7 : 8;
+ var lastFieldsStart = lastFields.length - fieldCount;
+ var fields = Array(fieldCount);
+ for (var x = 0; x < fieldCount; ++x) {
+ fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || '';
+ }
+ if (isLastFieldIPv4Address) {
+ fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
+ }
+ var allZeroFields = fields.reduce(function (acc, field, index) {
+ if (!field || field === "0") {
+ var lastLongest = acc[acc.length - 1];
+ if (lastLongest && lastLongest.index + lastLongest.length === index) {
+ lastLongest.length++;
+ } else {
+ acc.push({ index: index, length: 1 });
+ }
+ }
+ return acc;
+ }, []);
+ var longestZeroFields = allZeroFields.sort(function (a, b) {
+ return b.length - a.length;
+ })[0];
+ var newHost = void 0;
+ if (longestZeroFields && longestZeroFields.length > 1) {
+ var newFirst = fields.slice(0, longestZeroFields.index);
+ var newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
+ newHost = newFirst.join(":") + "::" + newLast.join(":");
+ } else {
+ newHost = fields.join(":");
+ }
+ if (zone) {
+ newHost += "%" + zone;
+ }
+ return newHost;
+ } else {
+ return host;
+ }
+}
+var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
+var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === undefined;
+function parse(uriString) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+
+ var components = {};
+ var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
+ if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
+ var matches = uriString.match(URI_PARSE);
+ if (matches) {
+ if (NO_MATCH_IS_UNDEFINED) {
+ //store each component
+ components.scheme = matches[1];
+ components.userinfo = matches[3];
+ components.host = matches[4];
+ components.port = parseInt(matches[5], 10);
+ components.path = matches[6] || "";
+ components.query = matches[7];
+ components.fragment = matches[8];
+ //fix port number
+ if (isNaN(components.port)) {
+ components.port = matches[5];
+ }
+ } else {
+ //IE FIX for improper RegExp matching
+ //store each component
+ components.scheme = matches[1] || undefined;
+ components.userinfo = uriString.indexOf("@") !== -1 ? matches[3] : undefined;
+ components.host = uriString.indexOf("//") !== -1 ? matches[4] : undefined;
+ components.port = parseInt(matches[5], 10);
+ components.path = matches[6] || "";
+ components.query = uriString.indexOf("?") !== -1 ? matches[7] : undefined;
+ components.fragment = uriString.indexOf("#") !== -1 ? matches[8] : undefined;
+ //fix port number
+ if (isNaN(components.port)) {
+ components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined;
+ }
+ }
+ if (components.host) {
+ //normalize IP hosts
+ components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
+ }
+ //determine reference type
+ if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
+ components.reference = "same-document";
+ } else if (components.scheme === undefined) {
+ components.reference = "relative";
+ } else if (components.fragment === undefined) {
+ components.reference = "absolute";
+ } else {
+ components.reference = "uri";
+ }
+ //check for reference errors
+ if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
+ components.error = components.error || "URI is not a " + options.reference + " reference.";
+ }
+ //find scheme handler
+ var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
+ //check if scheme can't handle IRIs
+ if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
+ //if host component is a domain name
+ if (components.host && (options.domainHost || schemeHandler && schemeHandler.domainHost)) {
+ //convert Unicode IDN -> ASCII IDN
+ try {
+ components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
+ } catch (e) {
+ components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
+ }
+ }
+ //convert IRI -> URI
+ _normalizeComponentEncoding(components, URI_PROTOCOL);
+ } else {
+ //normalize encodings
+ _normalizeComponentEncoding(components, protocol);
+ }
+ //perform scheme specific parsing
+ if (schemeHandler && schemeHandler.parse) {
+ schemeHandler.parse(components, options);
+ }
+ } else {
+ components.error = components.error || "URI can not be parsed.";
+ }
+ return components;
+}
+
+function _recomposeAuthority(components, options) {
+ var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
+ var uriTokens = [];
+ if (components.userinfo !== undefined) {
+ uriTokens.push(components.userinfo);
+ uriTokens.push("@");
+ }
+ if (components.host !== undefined) {
+ //normalize IP hosts, add brackets and escape zone separator for IPv6
+ uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, function (_, $1, $2) {
+ return "[" + $1 + ($2 ? "%25" + $2 : "") + "]";
+ }));
+ }
+ if (typeof components.port === "number" || typeof components.port === "string") {
+ uriTokens.push(":");
+ uriTokens.push(String(components.port));
+ }
+ return uriTokens.length ? uriTokens.join("") : undefined;
+}
+
+var RDS1 = /^\.\.?\//;
+var RDS2 = /^\/\.(\/|$)/;
+var RDS3 = /^\/\.\.(\/|$)/;
+var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
+function removeDotSegments(input) {
+ var output = [];
+ while (input.length) {
+ if (input.match(RDS1)) {
+ input = input.replace(RDS1, "");
+ } else if (input.match(RDS2)) {
+ input = input.replace(RDS2, "/");
+ } else if (input.match(RDS3)) {
+ input = input.replace(RDS3, "/");
+ output.pop();
+ } else if (input === "." || input === "..") {
+ input = "";
+ } else {
+ var im = input.match(RDS5);
+ if (im) {
+ var s = im[0];
+ input = input.slice(s.length);
+ output.push(s);
+ } else {
+ throw new Error("Unexpected dot segment condition");
+ }
+ }
+ }
+ return output.join("");
+}
+
+function serialize(components) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+
+ var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL;
+ var uriTokens = [];
+ //find scheme handler
+ var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
+ //perform scheme specific serialization
+ if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
+ if (components.host) {
+ //if host component is an IPv6 address
+ if (protocol.IPV6ADDRESS.test(components.host)) {}
+ //TODO: normalize IPv6 address as per RFC 5952
+
+ //if host component is a domain name
+ else if (options.domainHost || schemeHandler && schemeHandler.domainHost) {
+ //convert IDN via punycode
+ try {
+ components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host);
+ } catch (e) {
+ components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
+ }
+ }
+ }
+ //normalize encoding
+ _normalizeComponentEncoding(components, protocol);
+ if (options.reference !== "suffix" && components.scheme) {
+ uriTokens.push(components.scheme);
+ uriTokens.push(":");
+ }
+ var authority = _recomposeAuthority(components, options);
+ if (authority !== undefined) {
+ if (options.reference !== "suffix") {
+ uriTokens.push("//");
+ }
+ uriTokens.push(authority);
+ if (components.path && components.path.charAt(0) !== "/") {
+ uriTokens.push("/");
+ }
+ }
+ if (components.path !== undefined) {
+ var s = components.path;
+ if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
+ s = removeDotSegments(s);
+ }
+ if (authority === undefined) {
+ s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
+ }
+ uriTokens.push(s);
+ }
+ if (components.query !== undefined) {
+ uriTokens.push("?");
+ uriTokens.push(components.query);
+ }
+ if (components.fragment !== undefined) {
+ uriTokens.push("#");
+ uriTokens.push(components.fragment);
+ }
+ return uriTokens.join(""); //merge tokens into a string
+}
+
+function resolveComponents(base, relative) {
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+ var skipNormalization = arguments[3];
+
+ var target = {};
+ if (!skipNormalization) {
+ base = parse(serialize(base, options), options); //normalize base components
+ relative = parse(serialize(relative, options), options); //normalize relative components
+ }
+ options = options || {};
+ if (!options.tolerant && relative.scheme) {
+ target.scheme = relative.scheme;
+ //target.authority = relative.authority;
+ target.userinfo = relative.userinfo;
+ target.host = relative.host;
+ target.port = relative.port;
+ target.path = removeDotSegments(relative.path || "");
+ target.query = relative.query;
+ } else {
+ if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
+ //target.authority = relative.authority;
+ target.userinfo = relative.userinfo;
+ target.host = relative.host;
+ target.port = relative.port;
+ target.path = removeDotSegments(relative.path || "");
+ target.query = relative.query;
+ } else {
+ if (!relative.path) {
+ target.path = base.path;
+ if (relative.query !== undefined) {
+ target.query = relative.query;
+ } else {
+ target.query = base.query;
+ }
+ } else {
+ if (relative.path.charAt(0) === "/") {
+ target.path = removeDotSegments(relative.path);
+ } else {
+ if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
+ target.path = "/" + relative.path;
+ } else if (!base.path) {
+ target.path = relative.path;
+ } else {
+ target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
+ }
+ target.path = removeDotSegments(target.path);
+ }
+ target.query = relative.query;
+ }
+ //target.authority = base.authority;
+ target.userinfo = base.userinfo;
+ target.host = base.host;
+ target.port = base.port;
+ }
+ target.scheme = base.scheme;
+ }
+ target.fragment = relative.fragment;
+ return target;
+}
+
+function resolve(baseURI, relativeURI, options) {
+ var schemelessOptions = assign({ scheme: 'null' }, options);
+ return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
+}
+
+function normalize(uri, options) {
+ if (typeof uri === "string") {
+ uri = serialize(parse(uri, options), options);
+ } else if (typeOf(uri) === "object") {
+ uri = parse(serialize(uri, options), options);
+ }
+ return uri;
+}
+
+function equal(uriA, uriB, options) {
+ if (typeof uriA === "string") {
+ uriA = serialize(parse(uriA, options), options);
+ } else if (typeOf(uriA) === "object") {
+ uriA = serialize(uriA, options);
+ }
+ if (typeof uriB === "string") {
+ uriB = serialize(parse(uriB, options), options);
+ } else if (typeOf(uriB) === "object") {
+ uriB = serialize(uriB, options);
+ }
+ return uriA === uriB;
+}
+
+function escapeComponent(str, options) {
+ return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar);
+}
+
+function unescapeComponent(str, options) {
+ return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars);
+}
+
+var handler = {
+ scheme: "http",
+ domainHost: true,
+ parse: function parse(components, options) {
+ //report missing host
+ if (!components.host) {
+ components.error = components.error || "HTTP URIs must have a host.";
+ }
+ return components;
+ },
+ serialize: function serialize(components, options) {
+ var secure = String(components.scheme).toLowerCase() === "https";
+ //normalize the default port
+ if (components.port === (secure ? 443 : 80) || components.port === "") {
+ components.port = undefined;
+ }
+ //normalize the empty path
+ if (!components.path) {
+ components.path = "/";
+ }
+ //NOTE: We do not parse query strings for HTTP URIs
+ //as WWW Form Url Encoded query strings are part of the HTML4+ spec,
+ //and not the HTTP spec.
+ return components;
+ }
+};
+
+var handler$1 = {
+ scheme: "https",
+ domainHost: handler.domainHost,
+ parse: handler.parse,
+ serialize: handler.serialize
+};
+
+function isSecure(wsComponents) {
+ return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
+}
+//RFC 6455
+var handler$2 = {
+ scheme: "ws",
+ domainHost: true,
+ parse: function parse(components, options) {
+ var wsComponents = components;
+ //indicate if the secure flag is set
+ wsComponents.secure = isSecure(wsComponents);
+ //construct resouce name
+ wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
+ wsComponents.path = undefined;
+ wsComponents.query = undefined;
+ return wsComponents;
+ },
+ serialize: function serialize(wsComponents, options) {
+ //normalize the default port
+ if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
+ wsComponents.port = undefined;
+ }
+ //ensure scheme matches secure flag
+ if (typeof wsComponents.secure === 'boolean') {
+ wsComponents.scheme = wsComponents.secure ? 'wss' : 'ws';
+ wsComponents.secure = undefined;
+ }
+ //reconstruct path from resource name
+ if (wsComponents.resourceName) {
+ var _wsComponents$resourc = wsComponents.resourceName.split('?'),
+ _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2),
+ path = _wsComponents$resourc2[0],
+ query = _wsComponents$resourc2[1];
+
+ wsComponents.path = path && path !== '/' ? path : undefined;
+ wsComponents.query = query;
+ wsComponents.resourceName = undefined;
+ }
+ //forbid fragment component
+ wsComponents.fragment = undefined;
+ return wsComponents;
+ }
+};
+
+var handler$3 = {
+ scheme: "wss",
+ domainHost: handler$2.domainHost,
+ parse: handler$2.parse,
+ serialize: handler$2.serialize
+};
+
+var O = {};
+var isIRI = true;
+//RFC 3986
+var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]";
+var HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
+var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
+//RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
+//const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
+//const WSP$$ = "[\\x20\\x09]";
+//const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
+//const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
+//const VCHAR$$ = "[\\x21-\\x7E]";
+//const WSP$$ = "[\\x20\\x09]";
+//const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
+//const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
+//const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
+//const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
+var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
+var QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
+var VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
+var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
+var UNRESERVED = new RegExp(UNRESERVED$$, "g");
+var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
+var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
+var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
+var NOT_HFVALUE = NOT_HFNAME;
+function decodeUnreserved(str) {
+ var decStr = pctDecChars(str);
+ return !decStr.match(UNRESERVED) ? str : decStr;
+}
+var handler$4 = {
+ scheme: "mailto",
+ parse: function parse$$1(components, options) {
+ var mailtoComponents = components;
+ var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : [];
+ mailtoComponents.path = undefined;
+ if (mailtoComponents.query) {
+ var unknownHeaders = false;
+ var headers = {};
+ var hfields = mailtoComponents.query.split("&");
+ for (var x = 0, xl = hfields.length; x < xl; ++x) {
+ var hfield = hfields[x].split("=");
+ switch (hfield[0]) {
+ case "to":
+ var toAddrs = hfield[1].split(",");
+ for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) {
+ to.push(toAddrs[_x]);
+ }
+ break;
+ case "subject":
+ mailtoComponents.subject = unescapeComponent(hfield[1], options);
+ break;
+ case "body":
+ mailtoComponents.body = unescapeComponent(hfield[1], options);
+ break;
+ default:
+ unknownHeaders = true;
+ headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
+ break;
+ }
+ }
+ if (unknownHeaders) mailtoComponents.headers = headers;
+ }
+ mailtoComponents.query = undefined;
+ for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) {
+ var addr = to[_x2].split("@");
+ addr[0] = unescapeComponent(addr[0]);
+ if (!options.unicodeSupport) {
+ //convert Unicode IDN -> ASCII IDN
+ try {
+ addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
+ } catch (e) {
+ mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
+ }
+ } else {
+ addr[1] = unescapeComponent(addr[1], options).toLowerCase();
+ }
+ to[_x2] = addr.join("@");
+ }
+ return mailtoComponents;
+ },
+ serialize: function serialize$$1(mailtoComponents, options) {
+ var components = mailtoComponents;
+ var to = toArray(mailtoComponents.to);
+ if (to) {
+ for (var x = 0, xl = to.length; x < xl; ++x) {
+ var toAddr = String(to[x]);
+ var atIdx = toAddr.lastIndexOf("@");
+ var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
+ var domain = toAddr.slice(atIdx + 1);
+ //convert IDN via punycode
+ try {
+ domain = !options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain);
+ } catch (e) {
+ components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
+ }
+ to[x] = localPart + "@" + domain;
+ }
+ components.path = to.join(",");
+ }
+ var headers = mailtoComponents.headers = mailtoComponents.headers || {};
+ if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject;
+ if (mailtoComponents.body) headers["body"] = mailtoComponents.body;
+ var fields = [];
+ for (var name in headers) {
+ if (headers[name] !== O[name]) {
+ fields.push(name.replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFNAME, pctEncChar) + "=" + headers[name].replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFVALUE, pctEncChar));
+ }
+ }
+ if (fields.length) {
+ components.query = fields.join("&");
+ }
+ return components;
+ }
+};
+
+var URN_PARSE = /^([^\:]+)\:(.*)/;
+//RFC 2141
+var handler$5 = {
+ scheme: "urn",
+ parse: function parse$$1(components, options) {
+ var matches = components.path && components.path.match(URN_PARSE);
+ var urnComponents = components;
+ if (matches) {
+ var scheme = options.scheme || urnComponents.scheme || "urn";
+ var nid = matches[1].toLowerCase();
+ var nss = matches[2];
+ var urnScheme = scheme + ":" + (options.nid || nid);
+ var schemeHandler = SCHEMES[urnScheme];
+ urnComponents.nid = nid;
+ urnComponents.nss = nss;
+ urnComponents.path = undefined;
+ if (schemeHandler) {
+ urnComponents = schemeHandler.parse(urnComponents, options);
+ }
+ } else {
+ urnComponents.error = urnComponents.error || "URN can not be parsed.";
+ }
+ return urnComponents;
+ },
+ serialize: function serialize$$1(urnComponents, options) {
+ var scheme = options.scheme || urnComponents.scheme || "urn";
+ var nid = urnComponents.nid;
+ var urnScheme = scheme + ":" + (options.nid || nid);
+ var schemeHandler = SCHEMES[urnScheme];
+ if (schemeHandler) {
+ urnComponents = schemeHandler.serialize(urnComponents, options);
+ }
+ var uriComponents = urnComponents;
+ var nss = urnComponents.nss;
+ uriComponents.path = (nid || options.nid) + ":" + nss;
+ return uriComponents;
+ }
+};
+
+var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
+//RFC 4122
+var handler$6 = {
+ scheme: "urn:uuid",
+ parse: function parse(urnComponents, options) {
+ var uuidComponents = urnComponents;
+ uuidComponents.uuid = uuidComponents.nss;
+ uuidComponents.nss = undefined;
+ if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
+ uuidComponents.error = uuidComponents.error || "UUID is not valid.";
+ }
+ return uuidComponents;
+ },
+ serialize: function serialize(uuidComponents, options) {
+ var urnComponents = uuidComponents;
+ //normalize UUID
+ urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
+ return urnComponents;
+ }
+};
+
+SCHEMES[handler.scheme] = handler;
+SCHEMES[handler$1.scheme] = handler$1;
+SCHEMES[handler$2.scheme] = handler$2;
+SCHEMES[handler$3.scheme] = handler$3;
+SCHEMES[handler$4.scheme] = handler$4;
+SCHEMES[handler$5.scheme] = handler$5;
+SCHEMES[handler$6.scheme] = handler$6;
+
+exports.SCHEMES = SCHEMES;
+exports.pctEncChar = pctEncChar;
+exports.pctDecChars = pctDecChars;
+exports.parse = parse;
+exports.removeDotSegments = removeDotSegments;
+exports.serialize = serialize;
+exports.resolveComponents = resolveComponents;
+exports.resolve = resolve;
+exports.normalize = normalize;
+exports.equal = equal;
+exports.escapeComponent = escapeComponent;
+exports.unescapeComponent = unescapeComponent;
+
+Object.defineProperty(exports, '__esModule', { value: true });
+
+})));
+
+
+},{}],"ajv":[function(require,module,exports){
+'use strict';
+
+var compileSchema = require('./compile')
+ , resolve = require('./compile/resolve')
+ , Cache = require('./cache')
+ , SchemaObject = require('./compile/schema_obj')
+ , stableStringify = require('fast-json-stable-stringify')
+ , formats = require('./compile/formats')
+ , rules = require('./compile/rules')
+ , $dataMetaSchema = require('./data')
+ , util = require('./compile/util');
+
+module.exports = Ajv;
+
+Ajv.prototype.validate = validate;
+Ajv.prototype.compile = compile;
+Ajv.prototype.addSchema = addSchema;
+Ajv.prototype.addMetaSchema = addMetaSchema;
+Ajv.prototype.validateSchema = validateSchema;
+Ajv.prototype.getSchema = getSchema;
+Ajv.prototype.removeSchema = removeSchema;
+Ajv.prototype.addFormat = addFormat;
+Ajv.prototype.errorsText = errorsText;
+
+Ajv.prototype._addSchema = _addSchema;
+Ajv.prototype._compile = _compile;
+
+Ajv.prototype.compileAsync = require('./compile/async');
+var customKeyword = require('./keyword');
+Ajv.prototype.addKeyword = customKeyword.add;
+Ajv.prototype.getKeyword = customKeyword.get;
+Ajv.prototype.removeKeyword = customKeyword.remove;
+Ajv.prototype.validateKeyword = customKeyword.validate;
+
+var errorClasses = require('./compile/error_classes');
+Ajv.ValidationError = errorClasses.Validation;
+Ajv.MissingRefError = errorClasses.MissingRef;
+Ajv.$dataMetaSchema = $dataMetaSchema;
+
+var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema';
+
+var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'strictDefaults' ];
+var META_SUPPORT_DATA = ['/properties'];
+
+/**
+ * Creates validator instance.
+ * Usage: `Ajv(opts)`
+ * @param {Object} opts optional options
+ * @return {Object} ajv instance
+ */
+function Ajv(opts) {
+ if (!(this instanceof Ajv)) return new Ajv(opts);
+ opts = this._opts = util.copy(opts) || {};
+ setLogger(this);
+ this._schemas = {};
+ this._refs = {};
+ this._fragments = {};
+ this._formats = formats(opts.format);
+
+ this._cache = opts.cache || new Cache;
+ this._loadingSchemas = {};
+ this._compilations = [];
+ this.RULES = rules();
+ this._getId = chooseGetId(opts);
+
+ opts.loopRequired = opts.loopRequired || Infinity;
+ if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
+ if (opts.serialize === undefined) opts.serialize = stableStringify;
+ this._metaOpts = getMetaSchemaOptions(this);
+
+ if (opts.formats) addInitialFormats(this);
+ if (opts.keywords) addInitialKeywords(this);
+ addDefaultMetaSchema(this);
+ if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
+ if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}});
+ addInitialSchemas(this);
+}
+
+
+
+/**
+ * Validate data using schema
+ * Schema will be compiled and cached (using serialized JSON as key. [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used to serialize.
+ * @this Ajv
+ * @param {String|Object} schemaKeyRef key, ref or schema object
+ * @param {Any} data to be validated
+ * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
+ */
+function validate(schemaKeyRef, data) {
+ var v;
+ if (typeof schemaKeyRef == 'string') {
+ v = this.getSchema(schemaKeyRef);
+ if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
+ } else {
+ var schemaObj = this._addSchema(schemaKeyRef);
+ v = schemaObj.validate || this._compile(schemaObj);
+ }
+
+ var valid = v(data);
+ if (v.$async !== true) this.errors = v.errors;
+ return valid;
+}
+
+
+/**
+ * Create validating function for passed schema.
+ * @this Ajv
+ * @param {Object} schema schema object
+ * @param {Boolean} _meta true if schema is a meta-schema. Used internally to compile meta schemas of custom keywords.
+ * @return {Function} validating function
+ */
+function compile(schema, _meta) {
+ var schemaObj = this._addSchema(schema, undefined, _meta);
+ return schemaObj.validate || this._compile(schemaObj);
+}
+
+
+/**
+ * Adds schema to the instance.
+ * @this Ajv
+ * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
+ * @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
+ * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
+ * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
+ * @return {Ajv} this for method chaining
+ */
+function addSchema(schema, key, _skipValidation, _meta) {
+ if (Array.isArray(schema)){
+ for (var i=0; i} errors optional array of validation errors, if not passed errors from the instance are used.
+ * @param {Object} options optional options with properties `separator` and `dataVar`.
+ * @return {String} human readable string with all errors descriptions
+ */
+function errorsText(errors, options) {
+ errors = errors || this.errors;
+ if (!errors) return 'No errors';
+ options = options || {};
+ var separator = options.separator === undefined ? ', ' : options.separator;
+ var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
+
+ var text = '';
+ for (var i=0; i this.addVocabulary(v));
- if (this.opts.discriminator)
- this.addKeyword(discriminator_1.default);
- }
- _addDefaultMetaSchema() {
- super._addDefaultMetaSchema();
- if (!this.opts.meta)
- return;
- const metaSchema = this.opts.$data
- ? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA)
- : draft7MetaSchema;
- this.addMetaSchema(metaSchema, META_SCHEMA_ID, false);
- this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
- }
- defaultMeta() {
- return (this.opts.defaultMeta =
- super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined));
- }
-}
-exports.Ajv = Ajv;
-module.exports = exports = Ajv;
-module.exports.Ajv = Ajv;
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.default = Ajv;
-var validate_1 = require("./compile/validate");
-Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function () { return validate_1.KeywordCxt; } });
-var codegen_1 = require("./compile/codegen");
-Object.defineProperty(exports, "_", { enumerable: true, get: function () { return codegen_1._; } });
-Object.defineProperty(exports, "str", { enumerable: true, get: function () { return codegen_1.str; } });
-Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
-Object.defineProperty(exports, "nil", { enumerable: true, get: function () { return codegen_1.nil; } });
-Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return codegen_1.Name; } });
-Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function () { return codegen_1.CodeGen; } });
-var validation_error_1 = require("./runtime/validation_error");
-Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validation_error_1.default; } });
-var ref_error_1 = require("./compile/ref_error");
-Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function () { return ref_error_1.default; } });
-//# sourceMappingURL=ajv.js.map
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/ajv.js b/front_end/third_party/mcp-sdk/ajv/dist/ajv.js
new file mode 120000
index 00000000000..1c8dd82b48a
--- /dev/null
+++ b/front_end/third_party/mcp-sdk/ajv/dist/ajv.js
@@ -0,0 +1 @@
+../lib/ajv.js
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/ajv.js.map b/front_end/third_party/mcp-sdk/ajv/dist/ajv.js.map
deleted file mode 100644
index 42c3edf1af4..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/ajv.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"ajv.js","sourceRoot":"","sources":["../lib/ajv.ts"],"names":[],"mappings":";;;AACA,iCAA4B;AAC5B,kDAAsD;AACtD,gEAAwD;AACxD,qEAAoE;AAEpE,MAAM,iBAAiB,GAAG,CAAC,aAAa,CAAC,CAAA;AAEzC,MAAM,cAAc,GAAG,wCAAwC,CAAA;AAE/D,MAAa,GAAI,SAAQ,cAAO;IAC9B,gBAAgB;QACd,KAAK,CAAC,gBAAgB,EAAE,CAAA;QACxB,gBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;QACxD,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa;YAAE,IAAI,CAAC,UAAU,CAAC,uBAAa,CAAC,CAAA;IAC7D,CAAC;IAED,qBAAqB;QACnB,KAAK,CAAC,qBAAqB,EAAE,CAAA;QAC7B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,OAAM;QAC3B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK;YAChC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;YAC3D,CAAC,CAAC,gBAAgB,CAAA;QACpB,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,cAAc,EAAE,KAAK,CAAC,CAAA;QACrD,IAAI,CAAC,IAAI,CAAC,+BAA+B,CAAC,GAAG,cAAc,CAAA;IAC7D,CAAC;IAED,WAAW;QACT,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW;YAC3B,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;IACzF,CAAC;CACF;AArBD,kBAqBC;AAED,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,GAAG,CAAA;AAC9B,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAA;AACxB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;AAE3D,kBAAe,GAAG,CAAA;AA0BlB,+CAA6C;AAArC,sGAAA,UAAU,OAAA;AAIlB,6CAA6F;AAArF,4FAAA,CAAC,OAAA;AAAE,8FAAA,GAAG,OAAA;AAAE,oGAAA,SAAS,OAAA;AAAE,8FAAA,GAAG,OAAA;AAAE,+FAAA,IAAI,OAAA;AAAQ,kGAAA,OAAO,OAAA;AACnD,+DAAqE;AAA7D,mHAAA,OAAO,OAAmB;AAClC,iDAA8D;AAAtD,4GAAA,OAAO,OAAmB"}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/ajv.min.js b/front_end/third_party/mcp-sdk/ajv/dist/ajv.min.js
new file mode 100644
index 00000000000..7a60eb8a2bd
--- /dev/null
+++ b/front_end/third_party/mcp-sdk/ajv/dist/ajv.min.js
@@ -0,0 +1,3 @@
+/* ajv 6.12.6: Another JSON Schema Validator */
+!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Ajv=e()}(function(){return function o(i,n,l){function c(r,e){if(!n[r]){if(!i[r]){var t="function"==typeof require&&require;if(!e&&t)return t(r,!0);if(u)return u(r,!0);var a=new Error("Cannot find module '"+r+"'");throw a.code="MODULE_NOT_FOUND",a}var s=n[r]={exports:{}};i[r][0].call(s.exports,function(e){return c(i[r][1][e]||e)},s,s.exports,o,i,n,l)}return n[r].exports}for(var u="function"==typeof require&&require,e=0;e%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,u=/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i,h=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,d=/^(?:\/(?:[^~/]|~0|~1)*)*$/,p=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,f=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;function m(e){return a.copy(m[e="full"==e?"full":"fast"])}function v(e){var r=e.match(o);if(!r)return!1;var t,a=+r[2],s=+r[3];return 1<=a&&a<=12&&1<=s&&s<=(2!=a||((t=+r[1])%4!=0||t%100==0&&t%400!=0)?i[a]:29)}function y(e,r){var t=e.match(n);if(!t)return!1;var a=t[1],s=t[2],o=t[3];return(a<=23&&s<=59&&o<=59||23==a&&59==s&&60==o)&&(!r||t[5])}(r.exports=m).fast={date:/^\d\d\d\d-[0-1]\d-[0-3]\d$/,time:/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,"date-time":/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,"uri-template":c,url:u,email:/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,hostname:s,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:w,uuid:h,"json-pointer":d,"json-pointer-uri-fragment":p,"relative-json-pointer":f},m.full={date:v,time:y,"date-time":function(e){var r=e.split(g);return 2==r.length&&v(r[0])&&y(r[1],!0)},uri:function(e){return P.test(e)&&l.test(e)},"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":c,url:u,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:s,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:w,uuid:h,"json-pointer":d,"json-pointer-uri-fragment":p,"relative-json-pointer":f};var g=/t|\s/i;var P=/\/|:/;var E=/[^\\]\\Z/;function w(e){if(E.test(e))return!1;try{return new RegExp(e),!0}catch(e){return!1}}},{"./util":10}],5:[function(e,r,t){"use strict";var R=e("./resolve"),$=e("./util"),j=e("./error_classes"),D=e("fast-json-stable-stringify"),O=e("../dotjs/validate"),I=$.ucs2length,A=e("fast-deep-equal"),k=j.Validation;function C(e,c,u,r){var d=this,p=this._opts,h=[void 0],f={},l=[],t={},m=[],a={},v=[],s=function(e,r,t){var a=L.call(this,e,r,t);return 0<=a?{index:a,compiling:!0}:{index:a=this._compilations.length,compiling:!(this._compilations[a]={schema:e,root:r,baseId:t})}}.call(this,e,c=c||{schema:e,refVal:h,refs:f},r),o=this._compilations[s.index];if(s.compiling)return o.callValidate=P;var y=this._formats,g=this.RULES;try{var i=E(e,c,u,r);o.validate=i;var n=o.callValidate;return n&&(n.schema=i.schema,n.errors=null,n.refs=i.refs,n.refVal=i.refVal,n.root=i.root,n.$async=i.$async,p.sourceCode&&(n.source=i.source)),i}finally{(function(e,r,t){var a=L.call(this,e,r,t);0<=a&&this._compilations.splice(a,1)}).call(this,e,c,r)}function P(){var e=o.validate,r=e.apply(this,arguments);return P.errors=e.errors,r}function E(e,r,t,a){var s=!r||r&&r.schema==e;if(r.schema!=c.schema)return C.call(d,e,r,t,a);var o=!0===e.$async,i=O({isTop:!0,schema:e,isRoot:s,baseId:a,root:r,schemaPath:"",errSchemaPath:"#",errorPath:'""',MissingRefError:j.MissingRef,RULES:g,validate:O,util:$,resolve:R,resolveRef:w,usePattern:_,useDefault:F,useCustomRule:x,opts:p,formats:y,logger:d.logger,self:d}),i=Q(h,z)+Q(l,N)+Q(m,q)+Q(v,T)+i;p.processCode&&(i=p.processCode(i,e));try{var n=new Function("self","RULES","formats","root","refVal","defaults","customRules","equal","ucs2length","ValidationError",i)(d,g,y,c,h,m,v,A,I,k);h[0]=n}catch(e){throw d.logger.error("Error compiling schema, function code:",i),e}return n.schema=e,n.errors=null,n.refs=f,n.refVal=h,n.root=s?n:r,o&&(n.$async=!0),!0===p.sourceCode&&(n.source={code:i,patterns:l,defaults:m}),n}function w(e,r,t){r=R.url(e,r);var a,s,o=f[r];if(void 0!==o)return S(a=h[o],s="refVal["+o+"]");if(!t&&c.refs){var i=c.refs[r];if(void 0!==i)return S(a=c.refVal[i],s=b(r,a))}s=b(r);var n,l=R.call(d,E,c,r);if(void 0!==l||(n=u&&u[r])&&(l=R.inlineRef(n,p.inlineRefs)?n:C.call(d,n,c,u,e)),void 0!==l)return S(h[f[r]]=l,s);delete f[r]}function b(e,r){var t=h.length;return h[t]=r,"refVal"+(f[e]=t)}function S(e,r){return"object"==typeof e||"boolean"==typeof e?{code:r,schema:e,inline:!0}:{code:r,$async:e&&!!e.$async}}function _(e){var r=t[e];return void 0===r&&(r=t[e]=l.length,l[r]=e),"pattern"+r}function F(e){switch(typeof e){case"boolean":case"number":return""+e;case"string":return $.toQuotedString(e);case"object":if(null===e)return"null";var r=D(e),t=a[r];return void 0===t&&(t=a[r]=m.length,m[t]=e),"default"+t}}function x(e,r,t,a){if(!1!==d._opts.validateSchema){var s=e.definition.dependencies;if(s&&!s.every(function(e){return Object.prototype.hasOwnProperty.call(t,e)}))throw new Error("parent schema must have all required keywords: "+s.join(","));var o=e.definition.validateSchema;if(o)if(!o(r)){var i="keyword schema is invalid: "+d.errorsText(o.errors);if("log"!=d._opts.validateSchema)throw new Error(i);d.logger.error(i)}}var n,l=e.definition.compile,c=e.definition.inline,u=e.definition.macro;if(l)n=l.call(d,r,t,a);else if(u)n=u.call(d,r,t,a),!1!==p.validateSchema&&d.validateSchema(n,!0);else if(c)n=c.call(d,a,e.keyword,r,t);else if(!(n=e.definition.validate))return;if(void 0===n)throw new Error('custom keyword "'+e.keyword+'"failed to compile');var h=v.length;return{code:"customRule"+h,validate:v[h]=n}}}function L(e,r,t){for(var a=0;a",_=P?">":"<",F=void 0;if(!y&&"number"!=typeof d&&void 0!==d)throw new Error(r+" must be number");if(!b&&void 0!==w&&"number"!=typeof w&&"boolean"!=typeof w)throw new Error(E+" must be number or boolean");b?(o="exclIsNumber"+u,i="' + "+(n="op"+u)+" + '",c+=" var schemaExcl"+u+" = "+(t=e.util.getData(w.$data,h,e.dataPathArr))+"; ",F=E,(l=l||[]).push(c+=" var "+(a="exclusive"+u)+"; var "+(s="exclType"+u)+" = typeof "+(t="schemaExcl"+u)+"; if ("+s+" != 'boolean' && "+s+" != 'undefined' && "+s+" != 'number') { "),c="",!1!==e.createErrors?(c+=" { keyword: '"+(F||"_exclusiveLimit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(f)+" , params: {} ",!1!==e.opts.messages&&(c+=" , message: '"+E+" should be boolean' "),e.opts.verbose&&(c+=" , schema: validate.schema"+p+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+v+" "),c+=" } "):c+=" {} ",x=c,c=l.pop(),c+=!e.compositeRule&&m?e.async?" throw new ValidationError(["+x+"]); ":" validate.errors = ["+x+"]; return false; ":" var err = "+x+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",c+=" } else if ( ",y&&(c+=" ("+g+" !== undefined && typeof "+g+" != 'number') || "),c+=" "+s+" == 'number' ? ( ("+a+" = "+g+" === undefined || "+t+" "+S+"= "+g+") ? "+v+" "+_+"= "+t+" : "+v+" "+_+" "+g+" ) : ( ("+a+" = "+t+" === true) ? "+v+" "+_+"= "+g+" : "+v+" "+_+" "+g+" ) || "+v+" !== "+v+") { var op"+u+" = "+a+" ? '"+S+"' : '"+S+"='; ",void 0===d&&(f=e.errSchemaPath+"/"+(F=E),g=t,y=b)):(i=S,(o="number"==typeof w)&&y?(n="'"+i+"'",c+=" if ( ",y&&(c+=" ("+g+" !== undefined && typeof "+g+" != 'number') || "),c+=" ( "+g+" === undefined || "+w+" "+S+"= "+g+" ? "+v+" "+_+"= "+w+" : "+v+" "+_+" "+g+" ) || "+v+" !== "+v+") { "):(o&&void 0===d?(a=!0,f=e.errSchemaPath+"/"+(F=E),g=w,_+="="):(o&&(g=Math[P?"min":"max"](w,d)),w===(!o||g)?(a=!0,f=e.errSchemaPath+"/"+(F=E),_+="="):(a=!1,i+="=")),n="'"+i+"'",c+=" if ( ",y&&(c+=" ("+g+" !== undefined && typeof "+g+" != 'number') || "),c+=" "+v+" "+_+" "+g+" || "+v+" !== "+v+") { ")),F=F||r,(l=l||[]).push(c),c="",!1!==e.createErrors?(c+=" { keyword: '"+(F||"_limit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(f)+" , params: { comparison: "+n+", limit: "+g+", exclusive: "+a+" } ",!1!==e.opts.messages&&(c+=" , message: 'should be "+i+" ",c+=y?"' + "+g:g+"'"),e.opts.verbose&&(c+=" , schema: ",c+=y?"validate.schema"+p:""+d,c+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+v+" "),c+=" } "):c+=" {} ";var x=c;return c=l.pop(),c+=!e.compositeRule&&m?e.async?" throw new ValidationError(["+x+"]); ":" validate.errors = ["+x+"]; return false; ":" var err = "+x+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",c+=" } ",m&&(c+=" else { "),c}},{}],14:[function(e,r,t){"use strict";r.exports=function(e,r){var t=" ",a=e.level,s=e.dataLevel,o=e.schema[r],i=e.schemaPath+e.util.getProperty(r),n=e.errSchemaPath+"/"+r,l=!e.opts.allErrors,c="data"+(s||""),u=e.opts.$data&&o&&o.$data,h=u?(t+=" var schema"+a+" = "+e.util.getData(o.$data,s,e.dataPathArr)+"; ","schema"+a):o;if(!u&&"number"!=typeof o)throw new Error(r+" must be number");t+="if ( ",u&&(t+=" ("+h+" !== undefined && typeof "+h+" != 'number') || ");var d=r,p=p||[];p.push(t+=" "+c+".length "+("maxItems"==r?">":"<")+" "+h+") { "),t="",!1!==e.createErrors?(t+=" { keyword: '"+(d||"_limitItems")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(n)+" , params: { limit: "+h+" } ",!1!==e.opts.messages&&(t+=" , message: 'should NOT have ",t+="maxItems"==r?"more":"fewer",t+=" than ",t+=u?"' + "+h+" + '":""+o,t+=" items' "),e.opts.verbose&&(t+=" , schema: ",t+=u?"validate.schema"+i:""+o,t+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "),t+=" } "):t+=" {} ";var f=t,t=p.pop();return t+=!e.compositeRule&&l?e.async?" throw new ValidationError(["+f+"]); ":" validate.errors = ["+f+"]; return false; ":" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",t+="} ",l&&(t+=" else { "),t}},{}],15:[function(e,r,t){"use strict";r.exports=function(e,r){var t=" ",a=e.level,s=e.dataLevel,o=e.schema[r],i=e.schemaPath+e.util.getProperty(r),n=e.errSchemaPath+"/"+r,l=!e.opts.allErrors,c="data"+(s||""),u=e.opts.$data&&o&&o.$data,h=u?(t+=" var schema"+a+" = "+e.util.getData(o.$data,s,e.dataPathArr)+"; ","schema"+a):o;if(!u&&"number"!=typeof o)throw new Error(r+" must be number");t+="if ( ",u&&(t+=" ("+h+" !== undefined && typeof "+h+" != 'number') || "),t+=!1===e.opts.unicode?" "+c+".length ":" ucs2length("+c+") ";var d=r,p=p||[];p.push(t+=" "+("maxLength"==r?">":"<")+" "+h+") { "),t="",!1!==e.createErrors?(t+=" { keyword: '"+(d||"_limitLength")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(n)+" , params: { limit: "+h+" } ",!1!==e.opts.messages&&(t+=" , message: 'should NOT be ",t+="maxLength"==r?"longer":"shorter",t+=" than ",t+=u?"' + "+h+" + '":""+o,t+=" characters' "),e.opts.verbose&&(t+=" , schema: ",t+=u?"validate.schema"+i:""+o,t+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "),t+=" } "):t+=" {} ";var f=t,t=p.pop();return t+=!e.compositeRule&&l?e.async?" throw new ValidationError(["+f+"]); ":" validate.errors = ["+f+"]; return false; ":" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",t+="} ",l&&(t+=" else { "),t}},{}],16:[function(e,r,t){"use strict";r.exports=function(e,r){var t=" ",a=e.level,s=e.dataLevel,o=e.schema[r],i=e.schemaPath+e.util.getProperty(r),n=e.errSchemaPath+"/"+r,l=!e.opts.allErrors,c="data"+(s||""),u=e.opts.$data&&o&&o.$data,h=u?(t+=" var schema"+a+" = "+e.util.getData(o.$data,s,e.dataPathArr)+"; ","schema"+a):o;if(!u&&"number"!=typeof o)throw new Error(r+" must be number");t+="if ( ",u&&(t+=" ("+h+" !== undefined && typeof "+h+" != 'number') || ");var d=r,p=p||[];p.push(t+=" Object.keys("+c+").length "+("maxProperties"==r?">":"<")+" "+h+") { "),t="",!1!==e.createErrors?(t+=" { keyword: '"+(d||"_limitProperties")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(n)+" , params: { limit: "+h+" } ",!1!==e.opts.messages&&(t+=" , message: 'should NOT have ",t+="maxProperties"==r?"more":"fewer",t+=" than ",t+=u?"' + "+h+" + '":""+o,t+=" properties' "),e.opts.verbose&&(t+=" , schema: ",t+=u?"validate.schema"+i:""+o,t+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "),t+=" } "):t+=" {} ";var f=t,t=p.pop();return t+=!e.compositeRule&&l?e.async?" throw new ValidationError(["+f+"]); ":" validate.errors = ["+f+"]; return false; ":" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",t+="} ",l&&(t+=" else { "),t}},{}],17:[function(e,r,t){"use strict";r.exports=function(e,r){var t=" ",a=e.schema[r],s=e.schemaPath+e.util.getProperty(r),o=e.errSchemaPath+"/"+r,i=!e.opts.allErrors,n=e.util.copy(e),l="";n.level++;var c="valid"+n.level,u=n.baseId,h=!0,d=a;if(d)for(var p,f=-1,m=d.length-1;f "+_+") { ",x=c+"["+_+"]",d.schema=$,d.schemaPath=i+"["+_+"]",d.errSchemaPath=n+"/"+_,d.errorPath=e.util.getPathExpr(e.errorPath,_,e.opts.jsonPointers,!0),d.dataPathArr[v]=_,R=e.validate(d),d.baseId=g,e.util.varOccurences(R,y)<2?t+=" "+e.util.varReplace(R,y,x)+" ":t+=" var "+y+" = "+x+"; "+R+" ",t+=" } ",l&&(t+=" if ("+f+") { ",p+="}"))}"object"==typeof b&&(e.opts.strictKeywords?"object"==typeof b&&0 "+o.length+") { for (var "+m+" = "+o.length+"; "+m+" < "+c+".length; "+m+"++) { ",d.errorPath=e.util.getPathExpr(e.errorPath,m,e.opts.jsonPointers,!0),x=c+"["+m+"]",d.dataPathArr[v]=m,R=e.validate(d),d.baseId=g,e.util.varOccurences(R,y)<2?t+=" "+e.util.varReplace(R,y,x)+" ":t+=" var "+y+" = "+x+"; "+R+" ",l&&(t+=" if (!"+f+") break; "),t+=" } } ",l&&(t+=" if ("+f+") { ",p+="}"))}else{(e.opts.strictKeywords?"object"==typeof o&&0 1e-"+e.opts.multipleOfPrecision+" ":" division"+a+" !== parseInt(division"+a+") ",t+=" ) ",u&&(t+=" ) ");var d=d||[];d.push(t+=" ) { "),t="",!1!==e.createErrors?(t+=" { keyword: 'multipleOf' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(n)+" , params: { multipleOf: "+h+" } ",!1!==e.opts.messages&&(t+=" , message: 'should be multiple of ",t+=u?"' + "+h:h+"'"),e.opts.verbose&&(t+=" , schema: ",t+=u?"validate.schema"+i:""+o,t+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "),t+=" } "):t+=" {} ";var p=t,t=d.pop();return t+=!e.compositeRule&&l?e.async?" throw new ValidationError(["+p+"]); ":" validate.errors = ["+p+"]; return false; ":" var err = "+p+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",t+="} ",l&&(t+=" else { "),t}},{}],30:[function(e,r,t){"use strict";r.exports=function(e,r){var t=" ",a=e.level,s=e.dataLevel,o=e.schema[r],i=e.schemaPath+e.util.getProperty(r),n=e.errSchemaPath+"/"+r,l=!e.opts.allErrors,c="data"+(s||""),u="errs__"+a,h=e.util.copy(e);h.level++;var d,p,f,m,v="valid"+h.level;return(e.opts.strictKeywords?"object"==typeof o&&0 1) { ",t=e.schema.items&&e.schema.items.type,a=Array.isArray(t),!t||"object"==t||"array"==t||a&&(0<=t.indexOf("object")||0<=t.indexOf("array"))?i+=" outer: for (;i--;) { for (j = i; j--;) { if (equal("+p+"[i], "+p+"[j])) { "+f+" = false; break outer; } } } ":(i+=" var itemIndices = {}, item; for (;i--;) { var item = "+p+"[i]; ",i+=" if ("+e.util["checkDataType"+(a?"s":"")](t,"item",e.opts.strictNumbers,!0)+") continue; ",a&&(i+=" if (typeof item == 'string') item = '\"' + item; "),i+=" if (typeof itemIndices[item] == 'number') { "+f+" = false; j = itemIndices[item]; break; } itemIndices[item] = i; } "),i+=" } ",m&&(i+=" } "),(s=s||[]).push(i+=" if (!"+f+") { "),i="",!1!==e.createErrors?(i+=" { keyword: 'uniqueItems' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(h)+" , params: { i: i, j: j } ",!1!==e.opts.messages&&(i+=" , message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)' "),e.opts.verbose&&(i+=" , schema: ",i+=m?"validate.schema"+u:""+c,i+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+p+" "),i+=" } "):i+=" {} ",o=i,i=s.pop(),i+=!e.compositeRule&&d?e.async?" throw new ValidationError(["+o+"]); ":" validate.errors = ["+o+"]; return false; ":" var err = "+o+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",i+=" } ",d&&(i+=" else { ")):d&&(i+=" if (true) { "),i}},{}],38:[function(e,r,t){"use strict";r.exports=function(a,e){var r="",t=!0===a.schema.$async,s=a.util.schemaHasRulesExcept(a.schema,a.RULES.all,"$ref"),o=a.self._getId(a.schema);if(a.opts.strictKeywords){var i=a.util.schemaUnknownRules(a.schema,a.RULES.keywords);if(i){var n="unknown keyword: "+i;if("log"!==a.opts.strictKeywords)throw new Error(n);a.logger.warn(n)}}if(a.isTop&&(r+=" var validate = ",t&&(a.async=!0,r+="async "),r+="function(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict'; ",o&&(a.opts.sourceCode||a.opts.processCode)&&(r+=" /*# sourceURL="+o+" */ ")),"boolean"==typeof a.schema||!s&&!a.schema.$ref){var l=a.level,c=a.dataLevel,u=a.schema[e="false schema"],h=a.schemaPath+a.util.getProperty(e),d=a.errSchemaPath+"/"+e,p=!a.opts.allErrors,f="data"+(c||""),m="valid"+l;return!1===a.schema?(a.isTop?p=!0:r+=" var "+m+" = false; ",(U=U||[]).push(r),r="",!1!==a.createErrors?(r+=" { keyword: 'false schema' , dataPath: (dataPath || '') + "+a.errorPath+" , schemaPath: "+a.util.toQuotedString(d)+" , params: {} ",!1!==a.opts.messages&&(r+=" , message: 'boolean schema is false' "),a.opts.verbose&&(r+=" , schema: false , parentSchema: validate.schema"+a.schemaPath+" , data: "+f+" "),r+=" } "):r+=" {} ",D=r,r=U.pop(),r+=!a.compositeRule&&p?a.async?" throw new ValidationError(["+D+"]); ":" validate.errors = ["+D+"]; return false; ":" var err = "+D+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "):r+=a.isTop?t?" return data; ":" validate.errors = null; return true; ":" var "+m+" = true; ",a.isTop&&(r+=" }; return validate; "),r}if(a.isTop){var v=a.isTop,l=a.level=0,c=a.dataLevel=0,f="data";if(a.rootId=a.resolve.fullPath(a.self._getId(a.root.schema)),a.baseId=a.baseId||a.rootId,delete a.isTop,a.dataPathArr=[""],void 0!==a.schema.default&&a.opts.useDefaults&&a.opts.strictDefaults){var y="default is ignored in the schema root";if("log"!==a.opts.strictDefaults)throw new Error(y);a.logger.warn(y)}r+=" var vErrors = null; ",r+=" var errors = 0; ",r+=" if (rootData === undefined) rootData = data; "}else{l=a.level,f="data"+((c=a.dataLevel)||"");if(o&&(a.baseId=a.resolve.url(a.baseId,o)),t&&!a.async)throw new Error("async schema in sync schema");r+=" var errs_"+l+" = errors;"}var g,m="valid"+l,p=!a.opts.allErrors,P="",E="",w=a.schema.type,b=Array.isArray(w);if(w&&a.opts.nullable&&!0===a.schema.nullable&&(b?-1==w.indexOf("null")&&(w=w.concat("null")):"null"!=w&&(w=[w,"null"],b=!0)),b&&1==w.length&&(w=w[0],b=!1),a.schema.$ref&&s){if("fail"==a.opts.extendRefs)throw new Error('$ref: validation keywords used in schema at path "'+a.errSchemaPath+'" (see option extendRefs)');!0!==a.opts.extendRefs&&(s=!1,a.logger.warn('$ref: keywords ignored in schema at path "'+a.errSchemaPath+'"'))}if(a.schema.$comment&&a.opts.$comment&&(r+=" "+a.RULES.all.$comment.code(a,"$comment")),w){a.opts.coerceTypes&&(g=a.util.coerceToTypes(a.opts.coerceTypes,w));var S=a.RULES.types[w];if(g||b||!0===S||S&&!Z(S)){h=a.schemaPath+".type",d=a.errSchemaPath+"/type",h=a.schemaPath+".type",d=a.errSchemaPath+"/type";if(r+=" if ("+a.util[b?"checkDataTypes":"checkDataType"](w,f,a.opts.strictNumbers,!0)+") { ",g){var _="dataType"+l,F="coerced"+l;r+=" var "+_+" = typeof "+f+"; var "+F+" = undefined; ","array"==a.opts.coerceTypes&&(r+=" if ("+_+" == 'object' && Array.isArray("+f+") && "+f+".length == 1) { "+f+" = "+f+"[0]; "+_+" = typeof "+f+"; if ("+a.util.checkDataType(a.schema.type,f,a.opts.strictNumbers)+") "+F+" = "+f+"; } "),r+=" if ("+F+" !== undefined) ; ";var x=g;if(x)for(var R,$=-1,j=x.length-1;$= 0x80 (not a basic code point)","invalid-input":"Invalid input"},k=Math.floor,C=String.fromCharCode;function L(e){throw new RangeError(i[e])}function n(e,r){var t=e.split("@"),a="";return 1>1,e+=k(e/r);455k((A-a)/h))&&L("overflow"),a+=p*h;var f=d<=o?1:o+26<=d?26:d-o;if(pk(A/m)&&L("overflow"),h*=m}var v=r.length+1,o=z(a-u,v,0==u);k(a/v)>A-s&&L("overflow"),s+=k(a/v),a%=v,r.splice(a++,0,s)}return String.fromCodePoint.apply(String,r)}function c(e){var r=[],t=(e=N(e)).length,a=128,s=0,o=72,i=!0,n=!1,l=void 0;try{for(var c,u=e[Symbol.iterator]();!(i=(c=u.next()).done);i=!0){var h=c.value;h<128&&r.push(C(h))}}catch(e){n=!0,l=e}finally{try{!i&&u.return&&u.return()}finally{if(n)throw l}}var d=r.length,p=d;for(d&&r.push("-");pk((A-s)/w)&&L("overflow"),s+=(f-a)*w,a=f;var b=!0,S=!1,_=void 0;try{for(var F,x=e[Symbol.iterator]();!(b=(F=x.next()).done);b=!0){var R=F.value;if(RA&&L("overflow"),R==a){for(var $=s,j=36;;j+=36){var D=j<=o?1:o+26<=j?26:j-o;if($>6|192).toString(16).toUpperCase()+"%"+(63&r|128).toString(16).toUpperCase():"%"+(r>>12|224).toString(16).toUpperCase()+"%"+(r>>6&63|128).toString(16).toUpperCase()+"%"+(63&r|128).toString(16).toUpperCase()}function p(e){for(var r="",t=0,a=e.length;tA-Z\\x5E-\\x7E]",'[\\"\\\\]')),Y=new RegExp(K,"g"),W=new RegExp("(?:(?:%[EFef][0-9A-Fa-f]%[0-9A-Fa-f][0-9A-Fa-f]%[0-9A-Fa-f][0-9A-Fa-f])|(?:%[89A-Fa-f][0-9A-Fa-f]%[0-9A-Fa-f][0-9A-Fa-f])|(?:%[0-9A-Fa-f][0-9A-Fa-f]))","g"),X=new RegExp(J("[^]","[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]","[\\.]",'[\\"]',G),"g"),ee=new RegExp(J("[^]",K,"[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]"),"g"),re=ee;function te(e){var r=p(e);return r.match(Y)?r:e}var ae={scheme:"mailto",parse:function(e,r){var t=e,a=t.to=t.path?t.path.split(","):[];if(t.path=void 0,t.query){for(var s=!1,o={},i=t.query.split("&"),n=0,l=i.length;n {
- console.log("Got new SSE connection");
- const transport = new sse_js_2.SSEServerTransport("/message", res);
- const server = new index_js_2.Server({
- name: "mcp-typescript test server",
- version: "0.1.0",
- }, {
- capabilities: {},
- });
- servers.push(server);
- server.onclose = () => {
- console.log("SSE connection closed");
- servers = servers.filter((s) => s !== server);
- };
- await server.connect(transport);
- });
- app.post("/message", async (req, res) => {
- console.log("Received message");
- const sessionId = req.query.sessionId;
- const transport = servers
- .map((s) => s.transport)
- .find((t) => t.sessionId === sessionId);
- if (!transport) {
- res.status(404).send("Session not found");
- return;
- }
- await transport.handlePostMessage(req, res);
- });
- app.listen(port, () => {
- console.log(`Server running on http://localhost:${port}/sse`);
- });
- }
- else {
- const server = new index_js_2.Server({
- name: "mcp-typescript test server",
- version: "0.1.0",
- }, {
- capabilities: {
- prompts: {},
- resources: {},
- tools: {},
- logging: {},
- },
- });
- const transport = new stdio_js_2.StdioServerTransport();
- await server.connect(transport);
- console.log("Server running on stdio");
- }
-}
-const args = process.argv.slice(2);
-const command = args[0];
-switch (command) {
- case "client":
- if (args.length < 2) {
- console.error("Usage: client [args...]");
- process.exit(1);
- }
- runClient(args[1], args.slice(2)).catch((error) => {
- console.error(error);
- process.exit(1);
- });
- break;
- case "server": {
- const port = args[1] ? parseInt(args[1]) : null;
- runServer(port).catch((error) => {
- console.error(error);
- process.exit(1);
- });
- break;
- }
- default:
- console.error("Unrecognized command:", command);
-}
-//# sourceMappingURL=cli.js.map
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/cjs/cli.js.map b/front_end/third_party/mcp-sdk/ajv/dist/cjs/cli.js.map
deleted file mode 100644
index b59c481f0cb..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/cjs/cli.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";;;;;AAAA,4CAA2B;AAE3B,8DAA8D;AAC7D,MAAc,CAAC,SAAS,GAAG,YAAS,CAAC;AAEtC,sDAA8B;AAC9B,gDAA2C;AAC3C,4CAAqD;AACrD,gDAAyD;AACzD,wDAAiE;AACjE,gDAA2C;AAC3C,4CAAqD;AACrD,gDAAyD;AACzD,yCAAuD;AAEvD,KAAK,UAAU,SAAS,CAAC,cAAsB,EAAE,IAAc;IAC7D,MAAM,MAAM,GAAG,IAAI,iBAAM,CACvB;QACE,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,OAAO;KACjB,EACD;QACE,YAAY,EAAE;YACZ,QAAQ,EAAE,EAAE;SACb;KACF,CACF,CAAC;IAEF,IAAI,eAAe,CAAC;IAEpB,IAAI,GAAG,GAAoB,SAAS,CAAC;IACrC,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC,CAAC;IAAC,WAAM,CAAC;QACP,SAAS;IACX,CAAC;IAED,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,MAAK,OAAO,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,MAAK,QAAQ,EAAE,CAAC;QAC5D,eAAe,GAAG,IAAI,2BAAkB,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;IACpE,CAAC;SAAM,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,MAAK,KAAK,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,MAAK,MAAM,EAAE,CAAC;QAC/D,eAAe,GAAG,IAAI,uCAAwB,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;IAC1E,CAAC;SAAM,CAAC;QACN,eAAe,GAAG,IAAI,+BAAoB,CAAC;YACzC,OAAO,EAAE,cAAc;YACvB,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAEpC,MAAM,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAE5B,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,oCAAyB,CAAC,CAAC;IAE9E,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACzB,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,IAAmB;IAC1C,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QAEtB,IAAI,OAAO,GAAa,EAAE,CAAC;QAE3B,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;YACjC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;YAEtC,MAAM,SAAS,GAAG,IAAI,2BAAkB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;YAC1D,MAAM,MAAM,GAAG,IAAI,iBAAM,CACvB;gBACE,IAAI,EAAE,4BAA4B;gBAClC,OAAO,EAAE,OAAO;aACjB,EACD;gBACE,YAAY,EAAE,EAAE;aACjB,CACF,CAAC;YAEF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAErB,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE;gBACpB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;gBACrC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;YAChD,CAAC,CAAC;YAEF,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;YACtC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YAEhC,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,SAAmB,CAAC;YAChD,MAAM,SAAS,GAAG,OAAO;iBACtB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAA+B,CAAC;iBAC7C,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;YAC1C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;gBAC1C,OAAO;YACT,CAAC;YAED,MAAM,SAAS,CAAC,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACpB,OAAO,CAAC,GAAG,CAAC,sCAAsC,IAAI,MAAM,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,MAAM,GAAG,IAAI,iBAAM,CACvB;YACE,IAAI,EAAE,4BAA4B;YAClC,OAAO,EAAE,OAAO;SACjB,EACD;YACE,YAAY,EAAE;gBACZ,OAAO,EAAE,EAAE;gBACX,SAAS,EAAE,EAAE;gBACb,KAAK,EAAE,EAAE;gBACT,OAAO,EAAE,EAAE;aACZ;SACF,CACF,CAAC;QAEF,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;QAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAEhC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACxB,QAAQ,OAAO,EAAE,CAAC;IAChB,KAAK,QAAQ;QACX,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,MAAM;IAER,KAAK,QAAQ,CAAC,CAAC,CAAC;QACd,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAChD,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAC9B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,MAAM;IACR,CAAC;IAED;QACE,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC"}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.d.ts b/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.d.ts
deleted file mode 100644
index ae1199056b5..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.d.ts
+++ /dev/null
@@ -1,139 +0,0 @@
-import type { OAuthClientMetadata, OAuthClientInformation, OAuthTokens, OAuthMetadata, OAuthClientInformationFull, OAuthProtectedResourceMetadata } from "../shared/auth.js";
-/**
- * Implements an end-to-end OAuth client to be used with one MCP server.
- *
- * This client relies upon a concept of an authorized "session," the exact
- * meaning of which is application-defined. Tokens, authorization codes, and
- * code verifiers should not cross different sessions.
- */
-export interface OAuthClientProvider {
- /**
- * The URL to redirect the user agent to after authorization.
- */
- get redirectUrl(): string | URL;
- /**
- * Metadata about this OAuth client.
- */
- get clientMetadata(): OAuthClientMetadata;
- /**
- * Returns a OAuth2 state parameter.
- */
- state?(): string | Promise;
- /**
- * Loads information about this OAuth client, as registered already with the
- * server, or returns `undefined` if the client is not registered with the
- * server.
- */
- clientInformation(): OAuthClientInformation | undefined | Promise;
- /**
- * If implemented, this permits the OAuth client to dynamically register with
- * the server. Client information saved this way should later be read via
- * `clientInformation()`.
- *
- * This method is not required to be implemented if client information is
- * statically known (e.g., pre-registered).
- */
- saveClientInformation?(clientInformation: OAuthClientInformationFull): void | Promise;
- /**
- * Loads any existing OAuth tokens for the current session, or returns
- * `undefined` if there are no saved tokens.
- */
- tokens(): OAuthTokens | undefined | Promise;
- /**
- * Stores new OAuth tokens for the current session, after a successful
- * authorization.
- */
- saveTokens(tokens: OAuthTokens): void | Promise;
- /**
- * Invoked to redirect the user agent to the given URL to begin the authorization flow.
- */
- redirectToAuthorization(authorizationUrl: URL): void | Promise;
- /**
- * Saves a PKCE code verifier for the current session, before redirecting to
- * the authorization flow.
- */
- saveCodeVerifier(codeVerifier: string): void | Promise;
- /**
- * Loads the PKCE code verifier for the current session, necessary to validate
- * the authorization result.
- */
- codeVerifier(): string | Promise;
-}
-export type AuthResult = "AUTHORIZED" | "REDIRECT";
-export declare class UnauthorizedError extends Error {
- constructor(message?: string);
-}
-/**
- * Orchestrates the full auth flow with a server.
- *
- * This can be used as a single entry point for all authorization functionality,
- * instead of linking together the other lower-level functions in this module.
- */
-export declare function auth(provider: OAuthClientProvider, { serverUrl, authorizationCode, scope, resourceMetadataUrl }: {
- serverUrl: string | URL;
- authorizationCode?: string;
- scope?: string;
- resourceMetadataUrl?: URL;
-}): Promise;
-/**
- * Extract resource_metadata from response header.
- */
-export declare function extractResourceMetadataUrl(res: Response): URL | undefined;
-/**
- * Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata.
- *
- * If the server returns a 404 for the well-known endpoint, this function will
- * return `undefined`. Any other errors will be thrown as exceptions.
- */
-export declare function discoverOAuthProtectedResourceMetadata(serverUrl: string | URL, opts?: {
- protocolVersion?: string;
- resourceMetadataUrl?: string | URL;
-}): Promise;
-/**
- * Looks up RFC 8414 OAuth 2.0 Authorization Server Metadata.
- *
- * If the server returns a 404 for the well-known endpoint, this function will
- * return `undefined`. Any other errors will be thrown as exceptions.
- */
-export declare function discoverOAuthMetadata(authorizationServerUrl: string | URL, opts?: {
- protocolVersion?: string;
-}): Promise;
-/**
- * Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL.
- */
-export declare function startAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, redirectUrl, scope, state, }: {
- metadata?: OAuthMetadata;
- clientInformation: OAuthClientInformation;
- redirectUrl: string | URL;
- scope?: string;
- state?: string;
-}): Promise<{
- authorizationUrl: URL;
- codeVerifier: string;
-}>;
-/**
- * Exchanges an authorization code for an access token with the given server.
- */
-export declare function exchangeAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, }: {
- metadata?: OAuthMetadata;
- clientInformation: OAuthClientInformation;
- authorizationCode: string;
- codeVerifier: string;
- redirectUri: string | URL;
-}): Promise;
-/**
- * Exchange a refresh token for an updated access token.
- */
-export declare function refreshAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, refreshToken, }: {
- metadata?: OAuthMetadata;
- clientInformation: OAuthClientInformation;
- refreshToken: string;
-}): Promise;
-/**
- * Performs OAuth 2.0 Dynamic Client Registration according to RFC 7591.
- */
-export declare function registerClient(authorizationServerUrl: string | URL, { metadata, clientMetadata, }: {
- metadata?: OAuthMetadata;
- clientMetadata: OAuthClientMetadata;
-}): Promise;
-//# sourceMappingURL=auth.d.ts.map
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.d.ts.map b/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.d.ts.map
deleted file mode 100644
index 96f9fd82899..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.d.ts.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/client/auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,WAAW,EAAE,aAAa,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AAG7K;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,GAAG,GAAG,CAAC;IAEhC;;OAEG;IACH,IAAI,cAAc,IAAI,mBAAmB,CAAC;IAE1C;;OAEG;IACH,KAAK,CAAC,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnC;;;;OAIG;IACH,iBAAiB,IAAI,sBAAsB,GAAG,SAAS,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAAC;IAEtG;;;;;;;OAOG;IACH,qBAAqB,CAAC,CAAC,iBAAiB,EAAE,0BAA0B,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5F;;;OAGG;IACH,MAAM,IAAI,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAErE;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;OAEG;IACH,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE;;;OAGG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1C;AAED,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,UAAU,CAAC;AAEnD,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED;;;;;GAKG;AACH,wBAAsB,IAAI,CACxB,QAAQ,EAAE,mBAAmB,EAC7B,EAAE,SAAS,EACT,iBAAiB,EACjB,KAAK,EACL,mBAAmB,EACpB,EAAE;IACD,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAoFpD;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,QAAQ,GAAG,GAAG,GAAG,SAAS,CAyBzE;AAED;;;;;GAKG;AACH,wBAAsB,sCAAsC,CAC1D,SAAS,EAAE,MAAM,GAAG,GAAG,EACvB,IAAI,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GACtE,OAAO,CAAC,8BAA8B,CAAC,CAmCzC;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,sBAAsB,EAAE,MAAM,GAAG,GAAG,EACpC,IAAI,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,GAClC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA6BpC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,sBAAsB,EAAE,MAAM,GAAG,GAAG,EACpC,EACE,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,KAAK,EACL,KAAK,GACN,EAAE;IACD,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,iBAAiB,EAAE,sBAAsB,CAAC;IAC1C,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GACA,OAAO,CAAC;IAAE,gBAAgB,EAAE,GAAG,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAiD1D;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,sBAAsB,EAAE,MAAM,GAAG,GAAG,EACpC,EACE,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,WAAW,GACZ,EAAE;IACD,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,iBAAiB,EAAE,sBAAsB,CAAC;IAC1C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC;CAC3B,GACA,OAAO,CAAC,WAAW,CAAC,CA6CtB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,sBAAsB,EAAE,MAAM,GAAG,GAAG,EACpC,EACE,QAAQ,EACR,iBAAiB,EACjB,YAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,iBAAiB,EAAE,sBAAsB,CAAC;IAC1C,YAAY,EAAE,MAAM,CAAC;CACtB,GACA,OAAO,CAAC,WAAW,CAAC,CA0CtB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,sBAAsB,EAAE,MAAM,GAAG,GAAG,EACpC,EACE,QAAQ,EACR,cAAc,GACf,EAAE;IACD,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,cAAc,EAAE,mBAAmB,CAAC;CACrC,GACA,OAAO,CAAC,0BAA0B,CAAC,CA0BrC"}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.js b/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.js
deleted file mode 100644
index f288546402a..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.js
+++ /dev/null
@@ -1,340 +0,0 @@
-"use strict";
-var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.UnauthorizedError = void 0;
-exports.auth = auth;
-exports.extractResourceMetadataUrl = extractResourceMetadataUrl;
-exports.discoverOAuthProtectedResourceMetadata = discoverOAuthProtectedResourceMetadata;
-exports.discoverOAuthMetadata = discoverOAuthMetadata;
-exports.startAuthorization = startAuthorization;
-exports.exchangeAuthorization = exchangeAuthorization;
-exports.refreshAuthorization = refreshAuthorization;
-exports.registerClient = registerClient;
-const pkce_challenge_1 = __importDefault(require("pkce-challenge"));
-const types_js_1 = require("../types.js");
-const auth_js_1 = require("../shared/auth.js");
-class UnauthorizedError extends Error {
- constructor(message) {
- super(message !== null && message !== void 0 ? message : "Unauthorized");
- }
-}
-exports.UnauthorizedError = UnauthorizedError;
-/**
- * Orchestrates the full auth flow with a server.
- *
- * This can be used as a single entry point for all authorization functionality,
- * instead of linking together the other lower-level functions in this module.
- */
-async function auth(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl }) {
- let authorizationServerUrl = serverUrl;
- try {
- const resourceMetadata = await discoverOAuthProtectedResourceMetadata(resourceMetadataUrl || serverUrl);
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
- }
- }
- catch (error) {
- console.warn("Could not load OAuth Protected Resource metadata, falling back to /.well-known/oauth-authorization-server", error);
- }
- const metadata = await discoverOAuthMetadata(authorizationServerUrl);
- // Handle client registration if needed
- let clientInformation = await Promise.resolve(provider.clientInformation());
- if (!clientInformation) {
- if (authorizationCode !== undefined) {
- throw new Error("Existing OAuth client information is required when exchanging an authorization code");
- }
- if (!provider.saveClientInformation) {
- throw new Error("OAuth client information must be saveable for dynamic registration");
- }
- const fullInformation = await registerClient(authorizationServerUrl, {
- metadata,
- clientMetadata: provider.clientMetadata,
- });
- await provider.saveClientInformation(fullInformation);
- clientInformation = fullInformation;
- }
- // Exchange authorization code for tokens
- if (authorizationCode !== undefined) {
- const codeVerifier = await provider.codeVerifier();
- const tokens = await exchangeAuthorization(authorizationServerUrl, {
- metadata,
- clientInformation,
- authorizationCode,
- codeVerifier,
- redirectUri: provider.redirectUrl,
- });
- await provider.saveTokens(tokens);
- return "AUTHORIZED";
- }
- const tokens = await provider.tokens();
- // Handle token refresh or new authorization
- if (tokens === null || tokens === void 0 ? void 0 : tokens.refresh_token) {
- try {
- // Attempt to refresh the token
- const newTokens = await refreshAuthorization(authorizationServerUrl, {
- metadata,
- clientInformation,
- refreshToken: tokens.refresh_token,
- });
- await provider.saveTokens(newTokens);
- return "AUTHORIZED";
- }
- catch (error) {
- console.error("Could not refresh OAuth tokens:", error);
- }
- }
- const state = provider.state ? await provider.state() : undefined;
- // Start new authorization flow
- const { authorizationUrl, codeVerifier } = await startAuthorization(authorizationServerUrl, {
- metadata,
- clientInformation,
- state,
- redirectUrl: provider.redirectUrl,
- scope: scope || provider.clientMetadata.scope,
- });
- await provider.saveCodeVerifier(codeVerifier);
- await provider.redirectToAuthorization(authorizationUrl);
- return "REDIRECT";
-}
-/**
- * Extract resource_metadata from response header.
- */
-function extractResourceMetadataUrl(res) {
- const authenticateHeader = res.headers.get("WWW-Authenticate");
- if (!authenticateHeader) {
- return undefined;
- }
- const [type, scheme] = authenticateHeader.split(' ');
- if (type.toLowerCase() !== 'bearer' || !scheme) {
- console.log("Invalid WWW-Authenticate header format, expected 'Bearer'");
- return undefined;
- }
- const regex = /resource_metadata="([^"]*)"/;
- const match = regex.exec(authenticateHeader);
- if (!match) {
- return undefined;
- }
- try {
- return new URL(match[1]);
- }
- catch (_a) {
- console.log("Invalid resource metadata url: ", match[1]);
- return undefined;
- }
-}
-/**
- * Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata.
- *
- * If the server returns a 404 for the well-known endpoint, this function will
- * return `undefined`. Any other errors will be thrown as exceptions.
- */
-async function discoverOAuthProtectedResourceMetadata(serverUrl, opts) {
- var _a;
- let url;
- if (opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl) {
- url = new URL(opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl);
- }
- else {
- url = new URL("/.well-known/oauth-protected-resource", serverUrl);
- }
- let response;
- try {
- response = await fetch(url, {
- headers: {
- "MCP-Protocol-Version": (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : types_js_1.LATEST_PROTOCOL_VERSION
- }
- });
- }
- catch (error) {
- // CORS errors come back as TypeError
- if (error instanceof TypeError) {
- response = await fetch(url);
- }
- else {
- throw error;
- }
- }
- if (response.status === 404) {
- throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
- }
- if (!response.ok) {
- throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
- }
- return auth_js_1.OAuthProtectedResourceMetadataSchema.parse(await response.json());
-}
-/**
- * Looks up RFC 8414 OAuth 2.0 Authorization Server Metadata.
- *
- * If the server returns a 404 for the well-known endpoint, this function will
- * return `undefined`. Any other errors will be thrown as exceptions.
- */
-async function discoverOAuthMetadata(authorizationServerUrl, opts) {
- var _a;
- const url = new URL("/.well-known/oauth-authorization-server", authorizationServerUrl);
- let response;
- try {
- response = await fetch(url, {
- headers: {
- "MCP-Protocol-Version": (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : types_js_1.LATEST_PROTOCOL_VERSION
- }
- });
- }
- catch (error) {
- // CORS errors come back as TypeError
- if (error instanceof TypeError) {
- response = await fetch(url);
- }
- else {
- throw error;
- }
- }
- if (response.status === 404) {
- return undefined;
- }
- if (!response.ok) {
- throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`);
- }
- return auth_js_1.OAuthMetadataSchema.parse(await response.json());
-}
-/**
- * Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL.
- */
-async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, }) {
- const responseType = "code";
- const codeChallengeMethod = "S256";
- let authorizationUrl;
- if (metadata) {
- authorizationUrl = new URL(metadata.authorization_endpoint);
- if (!metadata.response_types_supported.includes(responseType)) {
- throw new Error(`Incompatible auth server: does not support response type ${responseType}`);
- }
- if (!metadata.code_challenge_methods_supported ||
- !metadata.code_challenge_methods_supported.includes(codeChallengeMethod)) {
- throw new Error(`Incompatible auth server: does not support code challenge method ${codeChallengeMethod}`);
- }
- }
- else {
- authorizationUrl = new URL("/authorize", authorizationServerUrl);
- }
- // Generate PKCE challenge
- const challenge = await (0, pkce_challenge_1.default)();
- const codeVerifier = challenge.code_verifier;
- const codeChallenge = challenge.code_challenge;
- authorizationUrl.searchParams.set("response_type", responseType);
- authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
- authorizationUrl.searchParams.set("code_challenge", codeChallenge);
- authorizationUrl.searchParams.set("code_challenge_method", codeChallengeMethod);
- authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
- if (state) {
- authorizationUrl.searchParams.set("state", state);
- }
- if (scope) {
- authorizationUrl.searchParams.set("scope", scope);
- }
- return { authorizationUrl, codeVerifier };
-}
-/**
- * Exchanges an authorization code for an access token with the given server.
- */
-async function exchangeAuthorization(authorizationServerUrl, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, }) {
- const grantType = "authorization_code";
- let tokenUrl;
- if (metadata) {
- tokenUrl = new URL(metadata.token_endpoint);
- if (metadata.grant_types_supported &&
- !metadata.grant_types_supported.includes(grantType)) {
- throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
- }
- }
- else {
- tokenUrl = new URL("/token", authorizationServerUrl);
- }
- // Exchange code for tokens
- const params = new URLSearchParams({
- grant_type: grantType,
- client_id: clientInformation.client_id,
- code: authorizationCode,
- code_verifier: codeVerifier,
- redirect_uri: String(redirectUri),
- });
- if (clientInformation.client_secret) {
- params.set("client_secret", clientInformation.client_secret);
- }
- const response = await fetch(tokenUrl, {
- method: "POST",
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
- },
- body: params,
- });
- if (!response.ok) {
- throw new Error(`Token exchange failed: HTTP ${response.status}`);
- }
- return auth_js_1.OAuthTokensSchema.parse(await response.json());
-}
-/**
- * Exchange a refresh token for an updated access token.
- */
-async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, }) {
- const grantType = "refresh_token";
- let tokenUrl;
- if (metadata) {
- tokenUrl = new URL(metadata.token_endpoint);
- if (metadata.grant_types_supported &&
- !metadata.grant_types_supported.includes(grantType)) {
- throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
- }
- }
- else {
- tokenUrl = new URL("/token", authorizationServerUrl);
- }
- // Exchange refresh token
- const params = new URLSearchParams({
- grant_type: grantType,
- client_id: clientInformation.client_id,
- refresh_token: refreshToken,
- });
- if (clientInformation.client_secret) {
- params.set("client_secret", clientInformation.client_secret);
- }
- const response = await fetch(tokenUrl, {
- method: "POST",
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
- },
- body: params,
- });
- if (!response.ok) {
- throw new Error(`Token refresh failed: HTTP ${response.status}`);
- }
- return auth_js_1.OAuthTokensSchema.parse({ refresh_token: refreshToken, ...(await response.json()) });
-}
-/**
- * Performs OAuth 2.0 Dynamic Client Registration according to RFC 7591.
- */
-async function registerClient(authorizationServerUrl, { metadata, clientMetadata, }) {
- let registrationUrl;
- if (metadata) {
- if (!metadata.registration_endpoint) {
- throw new Error("Incompatible auth server: does not support dynamic client registration");
- }
- registrationUrl = new URL(metadata.registration_endpoint);
- }
- else {
- registrationUrl = new URL("/register", authorizationServerUrl);
- }
- const response = await fetch(registrationUrl, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(clientMetadata),
- });
- if (!response.ok) {
- throw new Error(`Dynamic client registration failed: HTTP ${response.status}`);
- }
- return auth_js_1.OAuthClientInformationFullSchema.parse(await response.json());
-}
-//# sourceMappingURL=auth.js.map
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.js.map b/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.js.map
deleted file mode 100644
index 0ef96038595..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/auth.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/client/auth.ts"],"names":[],"mappings":";;;;;;AAyFA,oBA8FC;AAKD,gEAyBC;AAQD,wFAsCC;AAQD,sDAgCC;AAKD,gDAgEC;AAKD,sDA4DC;AAKD,oDAqDC;AAKD,wCAmCC;AAnhBD,oEAA2C;AAC3C,0CAAsD;AAEtD,+CAAmJ;AA0EnJ,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,cAAc,CAAC,CAAC;IACnC,CAAC;CACF;AAJD,8CAIC;AAED;;;;;GAKG;AACI,KAAK,UAAU,IAAI,CACxB,QAA6B,EAC7B,EAAE,SAAS,EACT,iBAAiB,EACjB,KAAK,EACL,mBAAmB,EAKQ;IAE7B,IAAI,sBAAsB,GAAG,SAAS,CAAC;IACvC,IAAI,CAAC;QACH,MAAM,gBAAgB,GAAG,MAAM,sCAAsC,CACnE,mBAAmB,IAAI,SAAS,CAAC,CAAC;QAEpC,IAAI,gBAAgB,CAAC,qBAAqB,IAAI,gBAAgB,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChG,sBAAsB,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,2GAA2G,EAAE,KAAK,CAAC,CAAA;IAClI,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,sBAAsB,CAAC,CAAC;IAErE,uCAAuC;IACvC,IAAI,iBAAiB,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC5E,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,qFAAqF,CAAC,CAAC;QACzG,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;QACxF,CAAC;QAED,MAAM,eAAe,GAAG,MAAM,cAAc,CAAC,sBAAsB,EAAE;YACnE,QAAQ;YACR,cAAc,EAAE,QAAQ,CAAC,cAAc;SACxC,CAAC,CAAC;QAEH,MAAM,QAAQ,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC;QACtD,iBAAiB,GAAG,eAAe,CAAC;IACtC,CAAC;IAED,yCAAyC;IACzC,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,YAAY,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,sBAAsB,EAAE;YACjE,QAAQ;YACR,iBAAiB;YACjB,iBAAiB;YACjB,YAAY;YACZ,WAAW,EAAE,QAAQ,CAAC,WAAW;SAClC,CAAC,CAAC;QAEH,MAAM,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAClC,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC;IAEvC,4CAA4C;IAC5C,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,+BAA+B;YAC/B,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,sBAAsB,EAAE;gBACnE,QAAQ;gBACR,iBAAiB;gBACjB,YAAY,EAAE,MAAM,CAAC,aAAa;aACnC,CAAC,CAAC;YAEH,MAAM,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YACrC,OAAO,YAAY,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAElE,+BAA+B;IAC/B,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,sBAAsB,EAAE;QAC1F,QAAQ;QACR,iBAAiB;QACjB,KAAK;QACL,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,KAAK,EAAE,KAAK,IAAI,QAAQ,CAAC,cAAc,CAAC,KAAK;KAC9C,CAAC,CAAC;IAEH,MAAM,QAAQ,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,QAAQ,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;IACzD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,SAAgB,0BAA0B,CAAC,GAAa;IAEtD,MAAM,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC/D,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrD,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,2DAA2D,CAAC,CAAC;QACzE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,GAAG,6BAA6B,CAAC;IAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAE7C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACzD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,sCAAsC,CAC1D,SAAuB,EACvB,IAAuE;;IAGvE,IAAI,GAAQ,CAAA;IACZ,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,mBAAmB,EAAE,CAAC;QAC9B,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,mBAAmB,CAAC,CAAC;IAC3C,CAAC;SAAM,CAAC;QACN,GAAG,GAAG,IAAI,GAAG,CAAC,uCAAuC,EAAE,SAAS,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAC1B,OAAO,EAAE;gBACP,sBAAsB,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,eAAe,mCAAI,kCAAuB;aACzE;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qCAAqC;QACrC,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;YAC/B,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;IAC/F,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,QAAQ,QAAQ,CAAC,MAAM,+DAA+D,CACvF,CAAC;IACJ,CAAC;IACD,OAAO,8CAAoC,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,qBAAqB,CACzC,sBAAoC,EACpC,IAAmC;;IAEnC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,yCAAyC,EAAE,sBAAsB,CAAC,CAAC;IACvF,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAC1B,OAAO,EAAE;gBACP,sBAAsB,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,eAAe,mCAAI,kCAAuB;aACzE;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qCAAqC;QACrC,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;YAC/B,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,QAAQ,QAAQ,CAAC,MAAM,2CAA2C,CACnE,CAAC;IACJ,CAAC;IAED,OAAO,6BAAmB,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,kBAAkB,CACtC,sBAAoC,EACpC,EACE,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,KAAK,EACL,KAAK,GAON;IAED,MAAM,YAAY,GAAG,MAAM,CAAC;IAC5B,MAAM,mBAAmB,GAAG,MAAM,CAAC;IAEnC,IAAI,gBAAqB,CAAC;IAC1B,IAAI,QAAQ,EAAE,CAAC;QACb,gBAAgB,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;QAE5D,IAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CACb,4DAA4D,YAAY,EAAE,CAC3E,CAAC;QACJ,CAAC;QAED,IACE,CAAC,QAAQ,CAAC,gCAAgC;YAC1C,CAAC,QAAQ,CAAC,gCAAgC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EACxE,CAAC;YACD,MAAM,IAAI,KAAK,CACb,oEAAoE,mBAAmB,EAAE,CAC1F,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,gBAAgB,GAAG,IAAI,GAAG,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;IACnE,CAAC;IAED,0BAA0B;IAC1B,MAAM,SAAS,GAAG,MAAM,IAAA,wBAAa,GAAE,CAAC;IACxC,MAAM,YAAY,GAAG,SAAS,CAAC,aAAa,CAAC;IAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,cAAc,CAAC;IAE/C,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;IACjE,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC5E,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;IACnE,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAC/B,uBAAuB,EACvB,mBAAmB,CACpB,CAAC;IACF,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAEvE,IAAI,KAAK,EAAE,CAAC;QACV,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,KAAK,EAAE,CAAC;QACV,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,CAAC;AAC5C,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,qBAAqB,CACzC,sBAAoC,EACpC,EACE,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,WAAW,GAOZ;IAED,MAAM,SAAS,GAAG,oBAAoB,CAAC;IAEvC,IAAI,QAAa,CAAC;IAClB,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;QAE5C,IACE,QAAQ,CAAC,qBAAqB;YAC9B,CAAC,QAAQ,CAAC,qBAAqB,CAAC,QAAQ,CAAC,SAAS,CAAC,EACnD,CAAC;YACD,MAAM,IAAI,KAAK,CACb,yDAAyD,SAAS,EAAE,CACrE,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IACvD,CAAC;IAED,2BAA2B;IAC3B,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;QACjC,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,iBAAiB,CAAC,SAAS;QACtC,IAAI,EAAE,iBAAiB;QACvB,aAAa,EAAE,YAAY;QAC3B,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC;KAClC,CAAC,CAAC;IAEH,IAAI,iBAAiB,CAAC,aAAa,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;QACrC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,mCAAmC;SACpD;QACD,IAAI,EAAE,MAAM;KACb,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,+BAA+B,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,2BAAiB,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,oBAAoB,CACxC,sBAAoC,EACpC,EACE,QAAQ,EACR,iBAAiB,EACjB,YAAY,GAKb;IAED,MAAM,SAAS,GAAG,eAAe,CAAC;IAElC,IAAI,QAAa,CAAC;IAClB,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;QAE5C,IACE,QAAQ,CAAC,qBAAqB;YAC9B,CAAC,QAAQ,CAAC,qBAAqB,CAAC,QAAQ,CAAC,SAAS,CAAC,EACnD,CAAC;YACD,MAAM,IAAI,KAAK,CACb,yDAAyD,SAAS,EAAE,CACrE,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IACvD,CAAC;IAED,yBAAyB;IACzB,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;QACjC,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,iBAAiB,CAAC,SAAS;QACtC,aAAa,EAAE,YAAY;KAC5B,CAAC,CAAC;IAEH,IAAI,iBAAiB,CAAC,aAAa,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;QACrC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,mCAAmC;SACpD;QACD,IAAI,EAAE,MAAM;KACb,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,8BAA8B,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,2BAAiB,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;AAC9F,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,cAAc,CAClC,sBAAoC,EACpC,EACE,QAAQ,EACR,cAAc,GAIf;IAED,IAAI,eAAoB,CAAC;IAEzB,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;QAC5F,CAAC;QAED,eAAe,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAC5D,CAAC;SAAM,CAAC;QACN,eAAe,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,eAAe,EAAE;QAC5C,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;KACrC,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,0CAAgC,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AACvE,CAAC"}
\ No newline at end of file
diff --git a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/index.d.ts b/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/index.d.ts
deleted file mode 100644
index 3b42a6c0c9e..00000000000
--- a/front_end/third_party/mcp-sdk/ajv/dist/cjs/client/index.d.ts
+++ /dev/null
@@ -1,942 +0,0 @@
-import { Protocol, ProtocolOptions, RequestOptions } from "../shared/protocol.js";
-import { Transport } from "../shared/transport.js";
-import { CallToolRequest, CallToolResultSchema, ClientCapabilities, ClientNotification, ClientRequest, ClientResult, CompatibilityCallToolResultSchema, CompleteRequest, GetPromptRequest, Implementation, ListPromptsRequest, ListResourcesRequest, ListResourceTemplatesRequest, ListToolsRequest, LoggingLevel, Notification, ReadResourceRequest, Request, Result, ServerCapabilities, SubscribeRequest, UnsubscribeRequest } from "../types.js";
-export type ClientOptions = ProtocolOptions & {
- /**
- * Capabilities to advertise as being supported by this client.
- */
- capabilities?: ClientCapabilities;
-};
-/**
- * An MCP client on top of a pluggable transport.
- *
- * The client will automatically begin the initialization flow with the server when connect() is called.
- *
- * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:
- *
- * ```typescript
- * // Custom schemas
- * const CustomRequestSchema = RequestSchema.extend({...})
- * const CustomNotificationSchema = NotificationSchema.extend({...})
- * const CustomResultSchema = ResultSchema.extend({...})
- *
- * // Type aliases
- * type CustomRequest = z.infer
- * type CustomNotification = z.infer
- * type CustomResult = z.infer
- *
- * // Create typed client
- * const client = new Client({
- * name: "CustomClient",
- * version: "1.0.0"
- * })
- * ```
- */
-export declare class Client extends Protocol {
- private _clientInfo;
- private _serverCapabilities?;
- private _serverVersion?;
- private _capabilities;
- private _instructions?;
- private _cachedToolOutputValidators;
- private _ajv;
- /**
- * Initializes this client with the given name and version information.
- */
- constructor(_clientInfo: Implementation, options?: ClientOptions);
- /**
- * Registers new capabilities. This can only be called before connecting to a transport.
- *
- * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
- */
- registerCapabilities(capabilities: ClientCapabilities): void;
- protected assertCapability(capability: keyof ServerCapabilities, method: string): void;
- connect(transport: Transport, options?: RequestOptions): Promise;
- /**
- * After initialization has completed, this will be populated with the server's reported capabilities.
- */
- getServerCapabilities(): ServerCapabilities | undefined;
- /**
- * After initialization has completed, this will be populated with information about the server's name and version.
- */
- getServerVersion(): Implementation | undefined;
- /**
- * After initialization has completed, this may be populated with information about the server's instructions.
- */
- getInstructions(): string | undefined;
- protected assertCapabilityForMethod(method: RequestT["method"]): void;
- protected assertNotificationCapability(method: NotificationT["method"]): void;
- protected assertRequestHandlerCapability(method: string): void;
- ping(options?: RequestOptions): Promise<{
- _meta?: import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough"> | undefined;
- }>;
- complete(params: CompleteRequest["params"], options?: RequestOptions): Promise, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
- }, {
- completion: import("zod").ZodObject<{
- values: import("zod").ZodArray;
- total: import("zod").ZodOptional;
- hasMore: import("zod").ZodOptional;
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
- values: import("zod").ZodArray;
- total: import("zod").ZodOptional;
- hasMore: import("zod").ZodOptional;
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
- values: import("zod").ZodArray;
- total: import("zod").ZodOptional;
- hasMore: import("zod").ZodOptional;
- }, import("zod").ZodTypeAny, "passthrough">>;
- }>, import("zod").ZodTypeAny, "passthrough">>;
- setLoggingLevel(level: LoggingLevel, options?: RequestOptions): Promise<{
- _meta?: import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough"> | undefined;
- }>;
- getPrompt(params: GetPromptRequest["params"], options?: RequestOptions): Promise, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
- }, {
- description: import("zod").ZodOptional;
- messages: import("zod").ZodArray;
- content: import("zod").ZodUnion<[import("zod").ZodObject<{
- type: import("zod").ZodLiteral<"text">;
- text: import("zod").ZodString;
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
- type: import("zod").ZodLiteral<"text">;
- text: import("zod").ZodString;
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
- type: import("zod").ZodLiteral<"text">;
- text: import("zod").ZodString;
- }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
- type: import("zod").ZodLiteral<"image">;
- data: import("zod").ZodString;
- mimeType: import("zod").ZodString;
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
- type: import("zod").ZodLiteral<"image">;
- data: import("zod").ZodString;
- mimeType: import("zod").ZodString;
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
- type: import("zod").ZodLiteral<"image">;
- data: import("zod").ZodString;
- mimeType: import("zod").ZodString;
- }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
- type: import("zod").ZodLiteral<"audio">;
- data: import("zod").ZodString;
- mimeType: import("zod").ZodString;
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
- type: import("zod").ZodLiteral<"audio">;
- data: import("zod").ZodString;
- mimeType: import("zod").ZodString;
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
- type: import("zod").ZodLiteral<"audio">;
- data: import("zod").ZodString;
- mimeType: import("zod").ZodString;
- }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
- type: import("zod").ZodLiteral<"resource">;
- resource: import("zod").ZodUnion<[import("zod").ZodObject;
- }, {
- text: import("zod").ZodString;
- }>, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType;
- }, {
- text: import("zod").ZodString;
- }>, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType;
- }, {
- text: import("zod").ZodString;
- }>, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject;
- }, {
- blob: import("zod").ZodString;
- }>, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType;
- }, {
- blob: import("zod").ZodString;
- }>, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType;
- }, {
- blob: import("zod").ZodString;
- }>, import("zod").ZodTypeAny, "passthrough">>]>;
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
- type: import("zod").ZodLiteral<"resource">;
- resource: import("zod").ZodUnion<[import("zod").ZodObject