Skip to content

Commit 4d586d5

Browse files
committed
Update version to 0.4.7, integrate ChatContext into Sidebar, and enforce HTTPS for morphik.ai URLs
1 parent e320a62 commit 4d586d5

5 files changed

Lines changed: 86 additions & 6 deletions

File tree

ee/ui-component/components/MorphikUI.tsx

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SettingsSection } from "@/components/settings/SettingsSection";
1414
import { extractTokenFromUri, getApiBaseUrlFromUri } from "@/lib/utils";
1515
import { PDFAPIService } from "@/components/pdf/PDFAPIService";
1616
import { MorphikSidebarRemote } from "@/components/sidebar-stateful";
17+
import { useChatContext } from "@/components/chat/chat-context";
1718
import { DynamicSiteHeader } from "@/components/dynamic-site-header";
1819
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar-components";
1920
import { MorphikProvider } from "@/contexts/morphik-context";
@@ -203,6 +204,58 @@ const MorphikUI: React.FC<MorphikUIProps> = props => {
203204
}
204205
};
205206

207+
// Local wrapper to bridge ChatContext into the Sidebar props
208+
const SidebarWithChatContext: React.FC<{
209+
logoLight?: string;
210+
logoDark?: string;
211+
showChatView: boolean;
212+
onChatViewChange: (show: boolean) => void;
213+
showSettingsView: boolean;
214+
onSettingsViewChange: (show: boolean) => void;
215+
currentSection: string;
216+
onSectionChange: (section: string) => void;
217+
userProfile?: typeof userProfile;
218+
onLogout?: typeof onLogout;
219+
onProfileNavigate?: typeof onProfileNavigate;
220+
onUpgradeClick?: typeof onUpgradeClick;
221+
}> = ({
222+
logoLight,
223+
logoDark,
224+
showChatView,
225+
onChatViewChange,
226+
showSettingsView,
227+
onSettingsViewChange,
228+
currentSection,
229+
onSectionChange,
230+
userProfile,
231+
onLogout,
232+
onProfileNavigate,
233+
onUpgradeClick,
234+
}) => {
235+
const { activeChatId, setActiveChatId, activeSettingsTab, setActiveSettingsTab } = useChatContext();
236+
237+
return (
238+
<MorphikSidebarRemote
239+
currentSection={currentSection}
240+
onSectionChange={onSectionChange}
241+
userProfile={userProfile}
242+
onLogout={onLogout}
243+
onProfileNavigate={onProfileNavigate}
244+
onUpgradeClick={onUpgradeClick}
245+
logoLight={logoLight}
246+
logoDark={logoDark}
247+
showChatView={showChatView}
248+
onChatViewChange={onChatViewChange}
249+
activeChatId={activeChatId}
250+
onChatSelect={setActiveChatId}
251+
showSettingsView={showSettingsView}
252+
onSettingsViewChange={onSettingsViewChange}
253+
activeSettingsTab={activeSettingsTab}
254+
onSettingsTabChange={setActiveSettingsTab}
255+
/>
256+
);
257+
};
258+
206259
const contentInner = (
207260
<PDFAPIService sessionId={sessionId} userId={userId}>
208261
<div className="min-h-screen bg-sidebar">
@@ -224,7 +277,7 @@ const MorphikUI: React.FC<MorphikUIProps> = props => {
224277
} as React.CSSProperties
225278
}
226279
>
227-
<MorphikSidebarRemote
280+
<SidebarWithChatContext
228281
currentSection={currentSection}
229282
onSectionChange={handleSectionChange}
230283
userProfile={userProfile}

ee/ui-component/components/sidebar-base.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,14 @@ export function BaseSidebar({
395395
</SidebarGroup>
396396
{onUpgradeClick && (userProfile?.tier === "free" || !userProfile?.tier) && (
397397
<div className="mx-2 mb-2 mt-2">
398-
<Button className="w-full justify-between" variant="outline" size="default" onClick={onUpgradeClick}>
399-
<div className="flex items-center gap-2">
398+
<Button
399+
className="w-full justify-between group-data-[collapsible=icon]:justify-center"
400+
variant="outline"
401+
size="default"
402+
onClick={onUpgradeClick}
403+
title="Upgrade to PRO"
404+
>
405+
<div className="flex items-center gap-2 group-data-[collapsible=icon]:hidden">
400406
<span>Upgrade to</span>
401407
<Badge variant="secondary" className="text-xs">
402408
PRO

ee/ui-component/contexts/morphik-context.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,25 @@ export function MorphikProvider({
129129
return DEFAULT_API_BASE_URL;
130130
}
131131

132-
const url = connectionInfo.apiBaseUrl;
132+
let url = connectionInfo.apiBaseUrl.trim();
133133

134134
// Safety check: ensure it's a proper HTTP(S) URL
135135
if (!url.startsWith("http://") && !url.startsWith("https://")) {
136136
console.error("[MorphikContext] Invalid apiBaseUrl:", url);
137137
return DEFAULT_API_BASE_URL;
138138
}
139139

140+
// Force HTTPS for morphik.ai domains to avoid CORS preflight redirect failures
141+
try {
142+
const parsed = new URL(url);
143+
if (parsed.protocol === "http:" && parsed.hostname.endsWith("morphik.ai")) {
144+
parsed.protocol = "https:";
145+
url = parsed.toString().replace(/\/$/, "");
146+
}
147+
} catch {
148+
// ignore URL parse errors; fallback to original url
149+
}
150+
140151
return url;
141152
}, [connectionInfo]);
142153

ee/ui-component/hooks/useChatSessions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ export function useChatSessions({ apiBaseUrl, authToken, limit = 100 }: UseChatS
6666
}
6767

6868
try {
69-
const res = await fetch(`${apiBaseUrl}/chats?limit=${limit}`, {
69+
// Normalize to HTTPS for morphik.ai to avoid preflight redirects (CORS)
70+
let base = apiBaseUrl;
71+
try {
72+
const u = new URL(apiBaseUrl);
73+
if (u.protocol === "http:" && u.hostname.endsWith("morphik.ai")) {
74+
u.protocol = "https:";
75+
base = u.toString().replace(/\/$/, "");
76+
}
77+
} catch {}
78+
79+
const res = await fetch(`${base}/chats?limit=${limit}`, {
7080
headers: {
7181
...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
7282
},

ee/ui-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@morphik/ui",
3-
"version": "0.4.4",
3+
"version": "0.4.7",
44
"private": true,
55
"description": "Modern UI component for Morphik - A powerful document processing and querying system",
66
"author": "Morphik Team",

0 commit comments

Comments
 (0)