diff --git a/packages/jupyter-ai/src/components/chat-messages.tsx b/packages/jupyter-ai/src/components/chat-messages.tsx index 0bb2ca0cb..bf7caf02e 100644 --- a/packages/jupyter-ai/src/components/chat-messages.tsx +++ b/packages/jupyter-ai/src/components/chat-messages.tsx @@ -11,7 +11,7 @@ import { MarkdownComponent } from './markdown-component'; import { useCollaboratorsContext } from '../contexts/collaborators-context'; type ChatMessagesProps = { - rendermime: IRenderMimeRegistry; + rmRegistry: IRenderMimeRegistry; messages: AiService.ChatMessage[]; }; @@ -144,7 +144,7 @@ export function ChatMessages(props: ChatMessagesProps): JSX.Element { sx={{ marginBottom: 3 }} /> diff --git a/packages/jupyter-ai/src/components/chat.tsx b/packages/jupyter-ai/src/components/chat.tsx index 8960e9615..31e0b5a15 100644 --- a/packages/jupyter-ai/src/components/chat.tsx +++ b/packages/jupyter-ai/src/components/chat.tsx @@ -23,13 +23,13 @@ import { ScrollContainer } from './scroll-container'; type ChatBodyProps = { chatHandler: ChatHandler; setChatView: (view: ChatView) => void; - renderMimeRegistry: IRenderMimeRegistry; + rmRegistry: IRenderMimeRegistry; }; function ChatBody({ chatHandler, setChatView: chatViewHandler, - renderMimeRegistry + rmRegistry: renderMimeRegistry }: ChatBodyProps): JSX.Element { const [messages, setMessages] = useState([]); const [showWelcomeMessage, setShowWelcomeMessage] = useState(false); @@ -149,7 +149,7 @@ function ChatBody({ return ( <> - + )} {view === ChatView.Settings && } diff --git a/packages/jupyter-ai/src/components/markdown-component.tsx b/packages/jupyter-ai/src/components/markdown-component.tsx index 56d0b4766..917a72c11 100644 --- a/packages/jupyter-ai/src/components/markdown-component.tsx +++ b/packages/jupyter-ai/src/components/markdown-component.tsx @@ -4,32 +4,32 @@ import { Widget } from '@lumino/widgets'; import { LuminoComponent } from './lumino-component'; type MarkdownWidgetProps = { - rendermime: IRenderMimeRegistry; markdownString: string; + rmRegistry: IRenderMimeRegistry; }; type MarkdownComponentProps = { markdownString: string; - rendermime: IRenderMimeRegistry; + rmRegistry: IRenderMimeRegistry; }; class MarkdownWidget extends Widget { - private rendermime: IRenderMimeRegistry; + private rmRegistry: IRenderMimeRegistry; private markdownString: string; constructor(props: MarkdownWidgetProps) { super(); - this.rendermime = props.rendermime; + this.rmRegistry = props.rmRegistry; this.markdownString = props.markdownString; this.initializeMarkdownRendering(); } async initializeMarkdownRendering(): Promise { const mimeType = 'text/markdown'; - const model = this.rendermime.createModel({ + const model = this.rmRegistry.createModel({ data: { [mimeType]: this.markdownString } }); - const renderer = this.rendermime.createRenderer(mimeType); + const renderer = this.rmRegistry.createRenderer(mimeType); await renderer.renderModel(model); this.node.appendChild(renderer.node); } @@ -38,18 +38,20 @@ class MarkdownWidget extends Widget { export function MarkdownComponent( props: MarkdownComponentProps ): React.ReactElement | null { - const { markdownString, rendermime } = props; const widgetRef = useRef(null); useEffect(() => { if (!widgetRef.current) { - widgetRef.current = new MarkdownWidget({ rendermime, markdownString }); + widgetRef.current = new MarkdownWidget({ + markdownString: props.markdownString, + rmRegistry: props.rmRegistry + }); } return () => { widgetRef.current?.dispose(); }; - }, []); // Empty dependency array if props are not expected to change + }, []); return widgetRef.current ? ( diff --git a/packages/jupyter-ai/src/index.ts b/packages/jupyter-ai/src/index.ts index 5c55c5e25..5a1958974 100644 --- a/packages/jupyter-ai/src/index.ts +++ b/packages/jupyter-ai/src/index.ts @@ -22,12 +22,13 @@ export type DocumentTracker = IWidgetTracker; const plugin: JupyterFrontEndPlugin = { id: 'jupyter_ai:plugin', autoStart: true, + requires: [IRenderMimeRegistry], optional: [IGlobalAwareness, ILayoutRestorer], activate: async ( app: JupyterFrontEnd, + rmRegistry: IRenderMimeRegistry, globalAwareness: Awareness | null, - restorer: ILayoutRestorer | null, - renderMimeRegistry: IRenderMimeRegistry + restorer: ILayoutRestorer | null ) => { /** * Initialize selection watcher singleton @@ -46,7 +47,7 @@ const plugin: JupyterFrontEndPlugin = { selectionWatcher, chatHandler, globalAwareness, - renderMimeRegistry + rmRegistry ); } catch (e) { chatWidget = buildErrorWidget(); diff --git a/packages/jupyter-ai/src/widgets/chat-sidebar.tsx b/packages/jupyter-ai/src/widgets/chat-sidebar.tsx index 6a2452cfa..e696a048b 100644 --- a/packages/jupyter-ai/src/widgets/chat-sidebar.tsx +++ b/packages/jupyter-ai/src/widgets/chat-sidebar.tsx @@ -12,14 +12,14 @@ export function buildChatSidebar( selectionWatcher: SelectionWatcher, chatHandler: ChatHandler, globalAwareness: Awareness | null, - renderMimeRegistry: IRenderMimeRegistry + rmRegistry: IRenderMimeRegistry ): ReactWidget { const ChatWidget = ReactWidget.create( ); ChatWidget.id = 'jupyter-ai::chat';