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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions ee/ui-component/contexts/morphik-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function getStoredConnectionUri(): string | null {
if (stored && stored.includes("://morphik://")) {
// Remove the leading protocol from malformed URIs like https://morphik://...
const cleaned = stored.replace(/^https?:\/\//, "");
console.log("Cleaning malformed stored URI:", stored, "→", cleaned);
console.log("Cleaning malformed stored connection URI", {
hadHttpProtocolPrefix: /^https?:\/\//.test(stored),
});
window.localStorage.setItem(CONNECTION_URI_STORAGE_KEY, cleaned);
return cleaned;
}
Expand All @@ -49,7 +51,10 @@ function getStoredConnectionUri(): string | null {
const match = stored.match(/^morphik:\/\/local@(.+)$/);
if (match && match[1]) {
const migratedUri = match[1];
console.log("Migrating old URI format:", stored, "→", migratedUri);
console.log("Migrating stored local connection URI format", {
from: "morphik-local",
to: "host",
});
// Update storage with migrated value
window.localStorage.setItem(CONNECTION_URI_STORAGE_KEY, migratedUri);
return migratedUri;
Expand Down Expand Up @@ -106,7 +111,7 @@ export function MorphikProvider({

// Clear stored URI if it's a local connection (on app restart)
if (storedUri && isLocalUri(storedUri)) {
console.log("Clearing stored local connection URI on app restart:", storedUri);
console.log("Clearing stored local connection URI on app restart");
setStoredConnectionUri(null);
// Use initial value or external prop for local connections
return externalConnectionUri || initialConnectionUri;
Expand All @@ -133,7 +138,11 @@ export function MorphikProvider({

// Safety check: ensure it's a proper HTTP(S) URL
if (!url.startsWith("http://") && !url.startsWith("https://")) {
console.error("[MorphikContext] Invalid apiBaseUrl:", url);
console.error("[MorphikContext] Invalid apiBaseUrl", {
hasValue: Boolean(connectionInfo.apiBaseUrl),
hasHttpProtocol: url.startsWith("http://"),
hasHttpsProtocol: url.startsWith("https://"),
});
return DEFAULT_API_BASE_URL;
}

Expand Down Expand Up @@ -161,7 +170,7 @@ export function MorphikProvider({
} else if (connectionUri && connectionInfo && connectionInfo.type === "local") {
// For local connections, we can optionally store temporarily
// but it will be cleared on next app restart
console.log("Local connection - will be cleared on restart:", connectionUri);
console.log("Local connection will be cleared on restart");
setStoredConnectionUri(connectionUri);
} else {
// Clear storage if no URI
Expand All @@ -171,21 +180,17 @@ export function MorphikProvider({

const updateConnectionUri = (uri: string) => {
if (!isReadOnlyUri) {
console.log("[MorphikContext] updateConnectionUri:", uri);
console.log("[MorphikContext] updateConnectionUri");
setConnectionUri(uri);
}
};

// Debug log when values change
React.useEffect(() => {
console.log("[MorphikContext] Current values:", {
connectionUri,
connectionInfo,
apiBaseUrl,
authToken,
isLocal,
console.log("[MorphikContext] Connection state changed:", {
hasConnection: Boolean(connectionUri),
});
}, [connectionUri, connectionInfo, apiBaseUrl, authToken, isLocal]);
}, [connectionUri]);

return (
<MorphikContext.Provider
Expand Down
6 changes: 4 additions & 2 deletions ee/ui-component/lib/connection-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export function parseConnectionUri(uri: string): ConnectionInfo {
if (uri.includes("://morphik://")) {
// Remove the leading protocol if someone entered https://morphik://...
cleanUri = uri.replace(/^https?:\/\//, "");
console.warn("Cleaning malformed URI:", uri, "→", cleanUri);
console.warn("Cleaning malformed connection URI", {
hadHttpProtocolPrefix: /^https?:\/\//.test(uri),
});
}

// Check if it's already a morphik:// URI
Expand Down Expand Up @@ -165,7 +167,7 @@ export function clearLocalConnectionFromStorage(): void {
try {
const stored = window.localStorage.getItem(CONNECTION_URI_STORAGE_KEY);
if (stored && isLocalUri(stored)) {
console.log("Clearing local connection from storage:", stored);
console.log("Clearing local connection from storage");
window.localStorage.removeItem(CONNECTION_URI_STORAGE_KEY);
}
} catch {
Expand Down
12 changes: 4 additions & 8 deletions ee/ui-component/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export function extractTokenFromUri(uri: string | undefined): string | null {
if (!uri) return null;

try {
console.log("Attempting to extract token from URI:", uri);
// The URI format is: morphik://appname:token@host
// We need to extract just the token part (after the colon and before the @)

Expand All @@ -35,15 +34,13 @@ export function extractTokenFromUri(uri: string | undefined): string | null {
if (authPart.includes(":")) {
// Format is appname:token
const fullToken = authPart.split(":")[1];
console.log("Extracted token:", fullToken ? `${fullToken.substring(0, 5)}...` : "null");
return fullToken;
} else {
// Old format with just token (no appname:)
console.log("Extracted token (old format):", authPart ? `${authPart.substring(0, 5)}...` : "null");
return authPart;
}
} catch (err) {
console.error("Error extracting token from URI:", err);
} catch {
console.error("Error extracting token from URI");
return null;
}
}
Expand Down Expand Up @@ -85,10 +82,9 @@ export function getApiBaseUrlFromUri(uri: string | undefined, defaultUrl: string
}
}

console.log("Extracted API base URL:", host);
return host;
} catch (err) {
console.error("Error extracting host from URI:", err);
} catch {
console.error("Error extracting host from URI");
return defaultUrl; // Default on error
}
}
Expand Down