@notebook-intelligence/notebook-intelligence 2.2.4 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chat-sidebar.js +6 -3
- package/package.json +1 -1
- package/src/chat-sidebar.tsx +8 -4
package/lib/chat-sidebar.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Mehmet Bektas <mbektasgh@outlook.com>
|
|
2
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState, memo } from 'react';
|
|
3
3
|
import { ReactWidget } from '@jupyterlab/apputils';
|
|
4
4
|
import { UUID } from '@lumino/coreutils';
|
|
5
5
|
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
|
|
6
6
|
import { NBIAPI, GitHubCopilotLoginStatus } from './api';
|
|
7
7
|
import { BackendMessageType, BuiltinToolsetType, ContextType, GITHUB_COPILOT_PROVIDER_ID, RequestDataType, ResponseStreamDataType, TelemetryEventType } from './tokens';
|
|
8
|
-
import { MarkdownRenderer } from './markdown-renderer';
|
|
8
|
+
import { MarkdownRenderer as OriginalMarkdownRenderer } from './markdown-renderer';
|
|
9
|
+
const MarkdownRenderer = memo(OriginalMarkdownRenderer);
|
|
9
10
|
import copySvgstr from '../style/icons/copy.svg';
|
|
10
11
|
import copilotSvgstr from '../style/icons/copilot.svg';
|
|
11
12
|
import copilotWarningSvgstr from '../style/icons/copilot-warning.svg';
|
|
@@ -141,6 +142,7 @@ function ChatResponseHTMLFrame(props) {
|
|
|
141
142
|
return (React.createElement("div", { className: "chat-response-html-frame", key: `key-${props.index}` },
|
|
142
143
|
React.createElement("iframe", { className: "chat-response-html-frame-iframe", height: props.height, sandbox: "allow-scripts", src: iframSrc })));
|
|
143
144
|
}
|
|
145
|
+
// Memoize ChatResponse for performance
|
|
144
146
|
function ChatResponse(props) {
|
|
145
147
|
var _a, _b, _c;
|
|
146
148
|
const [renderCount, setRenderCount] = useState(0);
|
|
@@ -302,6 +304,7 @@ function ChatResponse(props) {
|
|
|
302
304
|
}),
|
|
303
305
|
msg.notebookLink && (React.createElement("a", { className: "copilot-generated-notebook-link", "data-ref": msg.notebookLink, onClick: openNotebook }, "open notebook")))));
|
|
304
306
|
}
|
|
307
|
+
const MemoizedChatResponse = memo(ChatResponse);
|
|
305
308
|
async function submitCompletionRequest(request, responseEmitter) {
|
|
306
309
|
switch (request.type) {
|
|
307
310
|
case RunChatCompletionType.Chat:
|
|
@@ -1142,7 +1145,7 @@ function SidebarComponent(props) {
|
|
|
1142
1145
|
chatEnabled &&
|
|
1143
1146
|
(chatMessages.length === 0 ? (React.createElement("div", { className: "sidebar-messages" },
|
|
1144
1147
|
React.createElement("div", { className: "sidebar-greeting" }, "Welcome! How can I assist you today?"))) : (React.createElement("div", { className: "sidebar-messages" },
|
|
1145
|
-
chatMessages.map((msg, index) => (React.createElement(
|
|
1148
|
+
chatMessages.map((msg, index) => (React.createElement(MemoizedChatResponse, { key: msg.id, message: msg, openFile: props.openFile, getApp: props.getApp, getActiveDocumentInfo: props.getActiveDocumentInfo, showGenerating: index === chatMessages.length - 1 &&
|
|
1146
1149
|
msg.from === 'copilot' &&
|
|
1147
1150
|
copilotRequestInProgress }))),
|
|
1148
1151
|
React.createElement("div", { ref: messagesEndRef })))),
|
package/package.json
CHANGED
package/src/chat-sidebar.tsx
CHANGED
|
@@ -7,7 +7,8 @@ import React, {
|
|
|
7
7
|
useEffect,
|
|
8
8
|
useMemo,
|
|
9
9
|
useRef,
|
|
10
|
-
useState
|
|
10
|
+
useState,
|
|
11
|
+
memo
|
|
11
12
|
} from 'react';
|
|
12
13
|
import { ReactWidget } from '@jupyterlab/apputils';
|
|
13
14
|
import { UUID } from '@lumino/coreutils';
|
|
@@ -32,7 +33,8 @@ import {
|
|
|
32
33
|
TelemetryEventType
|
|
33
34
|
} from './tokens';
|
|
34
35
|
import { JupyterFrontEnd } from '@jupyterlab/application';
|
|
35
|
-
import { MarkdownRenderer } from './markdown-renderer';
|
|
36
|
+
import { MarkdownRenderer as OriginalMarkdownRenderer } from './markdown-renderer';
|
|
37
|
+
const MarkdownRenderer = memo(OriginalMarkdownRenderer);
|
|
36
38
|
|
|
37
39
|
import copySvgstr from '../style/icons/copy.svg';
|
|
38
40
|
import copilotSvgstr from '../style/icons/copilot.svg';
|
|
@@ -314,6 +316,7 @@ function ChatResponseHTMLFrame(props: any) {
|
|
|
314
316
|
);
|
|
315
317
|
}
|
|
316
318
|
|
|
319
|
+
// Memoize ChatResponse for performance
|
|
317
320
|
function ChatResponse(props: any) {
|
|
318
321
|
const [renderCount, setRenderCount] = useState(0);
|
|
319
322
|
const msg: IChatMessage = props.message;
|
|
@@ -599,6 +602,7 @@ function ChatResponse(props: any) {
|
|
|
599
602
|
</div>
|
|
600
603
|
);
|
|
601
604
|
}
|
|
605
|
+
const MemoizedChatResponse = memo(ChatResponse);
|
|
602
606
|
|
|
603
607
|
async function submitCompletionRequest(
|
|
604
608
|
request: IRunChatCompletionRequest,
|
|
@@ -1740,8 +1744,8 @@ function SidebarComponent(props: any) {
|
|
|
1740
1744
|
) : (
|
|
1741
1745
|
<div className="sidebar-messages">
|
|
1742
1746
|
{chatMessages.map((msg, index) => (
|
|
1743
|
-
<
|
|
1744
|
-
key={
|
|
1747
|
+
<MemoizedChatResponse
|
|
1748
|
+
key={msg.id}
|
|
1745
1749
|
message={msg}
|
|
1746
1750
|
openFile={props.openFile}
|
|
1747
1751
|
getApp={props.getApp}
|