Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export components from @jupyter/chat #132

Merged
merged 5 commits into from
Dec 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions packages/jupyter-chat/src/components/chat-messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import clsx from 'clsx';
import React, { useEffect, useState, useRef, forwardRef } from 'react';

import { ChatInput } from './chat-input';
import { RendermimeMarkdown } from './rendermime-markdown';
import { MarkdownRenderer } from './markdown-renderer';
import { ScrollContainer } from './scroll-container';
import { IChatModel } from '../model';
import { IChatMessage, IUser } from '../types';
Expand Down Expand Up @@ -391,7 +391,7 @@ export const ChatMessage = forwardRef<HTMLDivElement, ChatMessageProps>(
hideIncludeSelection={true}
/>
) : (
<RendermimeMarkdown
<MarkdownRenderer
rmRegistry={rmRegistry}
markdownStr={message.body}
model={model}
Expand Down
7 changes: 7 additions & 0 deletions packages/jupyter-chat/src/components/code-blocks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

export * from './code-toolbar';
export * from './copy-button';
15 changes: 15 additions & 0 deletions packages/jupyter-chat/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

export * from './chat';
export * from './chat-input';
export * from './chat-messages';
export * from './code-blocks';
export * from './input';
export * from './jl-theme-provider';
export * from './markdown-renderer';
export * from './mui-extras';
export * from './scroll-container';
export * from './toolbar';
7 changes: 7 additions & 0 deletions packages/jupyter-chat/src/components/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

export * from './cancel-button';
export * from './send-button';
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { MessageToolbar } from './toolbar';
import { IChatModel } from '../model';

const MD_MIME_TYPE = 'text/markdown';
const RENDERMIME_MD_CLASS = 'jp-chat-rendermime-markdown';
const MD_RENDERED_CLASS = 'jp-chat-rendered-markdown';

type RendermimeMarkdownProps = {
type MarkdownRendererProps = {
/**
* The string to render.
*/
Expand Down Expand Up @@ -62,7 +62,7 @@ function escapeLatexDelimiters(text: string) {
.replace(/\\\]/g, '\\\\]');
}

function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {
function MarkdownRendererBase(props: MarkdownRendererProps): JSX.Element {
const appendContent = props.appendContent || false;
const [renderedContent, setRenderedContent] = useState<HTMLElement | null>(
null
Expand Down Expand Up @@ -122,7 +122,7 @@ function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {
}, [props.markdownStr, props.rmRegistry]);

return (
<div className={RENDERMIME_MD_CLASS}>
<div className={MD_RENDERED_CLASS}>
{renderedContent &&
(appendContent ? (
<div ref={node => node && node.appendChild(renderedContent)} />
Expand All @@ -146,4 +146,4 @@ function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {
);
}

export const RendermimeMarkdown = React.memo(RendermimeMarkdownBase);
export const MarkdownRenderer = React.memo(MarkdownRendererBase);
8 changes: 8 additions & 0 deletions packages/jupyter-chat/src/components/mui-extras/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

export * from './contrasting-tooltip';
export * from './tooltipped-button';
export * from './tooltipped-icon-button';
105 changes: 0 additions & 105 deletions packages/jupyter-chat/src/components/mui-extras/stacking-alert.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/jupyter-chat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

export * from './active-cell-manager';
export * from './components';
export * from './icons';
export * from './model';
export * from './registry';
Expand Down
12 changes: 6 additions & 6 deletions packages/jupyter-chat/style/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
padding: 0 1em;
}

.jp-chat-rendermime-markdown {
.jp-chat-rendered-markdown {
position: relative;
}

Expand All @@ -26,11 +26,11 @@
* See: https://jupyterlab.readthedocs.io/en/latest/extension/extension_migration.html#css-styling
* See also: https://github.com/jupyterlab/jupyter-ai/issues/1090
*/
.jp-ThemedContainer .jp-chat-rendermime-markdown .jp-RenderedHTMLCommon {
.jp-ThemedContainer .jp-chat-rendered-markdown .jp-RenderedHTMLCommon {
padding-right: 0;
}

.jp-ThemedContainer .jp-chat-rendermime-markdown pre {
.jp-ThemedContainer .jp-chat-rendered-markdown pre {
background-color: var(--jp-cell-editor-background);
overflow-x: auto;
white-space: pre;
Expand All @@ -39,13 +39,13 @@
border: var(--jp-border-width) solid var(--jp-cell-editor-border-color);
}

.jp-ThemedContainer .jp-chat-rendermime-markdown pre > code {
.jp-ThemedContainer .jp-chat-rendered-markdown pre > code {
background-color: inherit;
overflow-x: inherit;
white-space: inherit;
}

.jp-ThemedContainer .jp-chat-rendermime-markdown mjx-container {
.jp-ThemedContainer .jp-chat-rendered-markdown mjx-container {
font-size: 119%;
}

Expand All @@ -58,7 +58,7 @@
color: var(--jp-ui-font-color3);
}

.jp-chat-rendermime-markdown:hover .jp-chat-toolbar {
.jp-chat-rendered-markdown:hover .jp-chat-toolbar {
display: inherit;
}

Expand Down
6 changes: 3 additions & 3 deletions ui-tests/tests/chat-file.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in ui-tests/tests/chat-file.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/chat-file.spec.ts:166:7 › #ychat › should add an id to the chat metadata

1) tests/chat-file.spec.ts:166:7 › #ychat › should add an id to the chat metadata ──────────────── Test timeout of 60000ms exceeded.
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/
Expand Down Expand Up @@ -29,7 +29,7 @@
page: IJupyterLabPageFixture,
filename: string
): Promise<Contents.IModel> => {
return await page.evaluate(async filepath => {

Check failure on line 32 in ui-tests/tests/chat-file.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/chat-file.spec.ts:166:7 › #ychat › should add an id to the chat metadata

1) tests/chat-file.spec.ts:166:7 › #ychat › should add an id to the chat metadata ──────────────── Error: proxy.evaluate: Target page, context or browser has been closed 30 | filename: string 31 | ): Promise<Contents.IModel> => { > 32 | return await page.evaluate(async filepath => { | ^ 33 | return await window.jupyterapp.serviceManager.contents.get(filepath); 34 | }, filename); 35 | }; at readFileContent (/home/runner/work/jupyter-chat/jupyter-chat/ui-tests/tests/chat-file.spec.ts:32:21) at hasId (/home/runner/work/jupyter-chat/jupyter-chat/ui-tests/tests/chat-file.spec.ts:173:27) at Timeout.check (/home/runner/work/jupyter-chat/jupyter-chat/ui-tests/node_modules/@jupyterlab/galata/src/utils.ts:183:33)
return await window.jupyterapp.serviceManager.contents.get(filepath);
}, filename);
};
Expand Down Expand Up @@ -215,7 +215,7 @@
const updatedContent = 'Content updated';
const chatPanel = await openChat(page, FILENAME);
const messageContent = chatPanel
.locator('.jp-chat-messages-container .jp-chat-rendermime-markdown')
.locator('.jp-chat-messages-container .jp-chat-rendered-markdown')
.first();
const newMsg = { ...msg, body: updatedContent };
const newContent = {
Expand Down Expand Up @@ -261,14 +261,14 @@

await expect(messages).toHaveCount(2);
await expect(
messages.last().locator('.jp-chat-rendermime-markdown')
messages.last().locator('.jp-chat-rendered-markdown')
).toHaveText(newMsgContent);
});

test('should delete a message from file', async ({ page }) => {
const chatPanel = await openChat(page, FILENAME);
const messageContent = chatPanel
.locator('.jp-chat-messages-container .jp-chat-rendermime-markdown')
.locator('.jp-chat-messages-container .jp-chat-rendered-markdown')
.first();
const newContent = {
messages: [],
Expand Down
8 changes: 4 additions & 4 deletions ui-tests/tests/message-toolbar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in ui-tests/tests/message-toolbar.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/message-toolbar.spec.ts:96:7 › #messageToolbar › should cancel message edition

2) tests/message-toolbar.spec.ts:96:7 › #messageToolbar › should cancel message edition ────────── Test timeout of 60000ms exceeded.
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/
Expand Down Expand Up @@ -51,7 +51,7 @@
test('message should have a toolbar', async ({ page }) => {
const chatPanel = await openChat(page, FILENAME);
const message = chatPanel
.locator('.jp-chat-messages-container .jp-chat-rendermime-markdown')
.locator('.jp-chat-messages-container .jp-chat-rendered-markdown')
.first();

await expect(message.locator('.jp-chat-toolbar')).not.toBeVisible();
Expand All @@ -66,7 +66,7 @@
const message = chatPanel
.locator('.jp-chat-messages-container .jp-chat-message')
.first();
const messageContent = message.locator('.jp-chat-rendermime-markdown');
const messageContent = message.locator('.jp-chat-rendered-markdown');

// Should display the message toolbar
await messageContent.hover({ position: { x: 5, y: 5 } });
Expand Down Expand Up @@ -98,10 +98,10 @@
const message = chatPanel
.locator('.jp-chat-messages-container .jp-chat-message')
.first();
const messageContent = message.locator('.jp-chat-rendermime-markdown');
const messageContent = message.locator('.jp-chat-rendered-markdown');

// Should display the message toolbar
await messageContent.hover({ position: { x: 5, y: 5 } });

Check failure on line 104 in ui-tests/tests/message-toolbar.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/message-toolbar.spec.ts:96:7 › #messageToolbar › should cancel message edition

2) tests/message-toolbar.spec.ts:96:7 › #messageToolbar › should cancel message edition ────────── Error: locator.hover: Test timeout of 60000ms exceeded. Call log: - waiting for getByRole('main').getByRole('tabpanel', { name: 'my-chat.chat' }).locator('.jp-chat-messages-container .jp-chat-message').first().locator('.jp-chat-rendered-markdown') 102 | 103 | // Should display the message toolbar > 104 | await messageContent.hover({ position: { x: 5, y: 5 } }); | ^ 105 | await messageContent.locator('.jp-chat-toolbar jp-button').first().click(); 106 | 107 | await expect(messageContent).not.toBeVisible(); at /home/runner/work/jupyter-chat/jupyter-chat/ui-tests/tests/message-toolbar.spec.ts:104:26
await messageContent.locator('.jp-chat-toolbar jp-button').first().click();

await expect(messageContent).not.toBeVisible();
Expand Down Expand Up @@ -134,7 +134,7 @@
const message = chatPanel
.locator('.jp-chat-messages-container .jp-chat-message')
.first();
const messageContent = message.locator('.jp-chat-rendermime-markdown');
const messageContent = message.locator('.jp-chat-rendered-markdown');

// Should display the message toolbar
await messageContent.hover({ position: { x: 5, y: 5 } });
Expand Down
12 changes: 6 additions & 6 deletions ui-tests/tests/send-message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test.describe('#sendMessages', () => {
await expect(messages.locator('.jp-chat-message')).toHaveCount(1);
// It seems that the markdown renderer adds a new line.
await expect(
messages.locator('.jp-chat-message .jp-chat-rendermime-markdown')
messages.locator('.jp-chat-message .jp-chat-rendered-markdown')
).toHaveText(MSG_CONTENT + '\n');
});

Expand All @@ -53,7 +53,7 @@ test.describe('#sendMessages', () => {
await expect(messages.locator('.jp-chat-message')).toHaveCount(1);
// It seems that the markdown renderer adds a new line.
await expect(
messages.locator('.jp-chat-message .jp-chat-rendermime-markdown')
messages.locator('.jp-chat-message .jp-chat-rendered-markdown')
).toHaveText(MSG_CONTENT + '\n');
});

Expand Down Expand Up @@ -93,7 +93,7 @@ test.describe('#sendMessages', () => {
// It seems that the markdown renderer adds a new line, but the '\n' inserter when
// pressing Enter above is trimmed.
await expect(
messages.locator('.jp-chat-message .jp-chat-rendermime-markdown')
messages.locator('.jp-chat-message .jp-chat-rendered-markdown')
).toHaveText(MSG_CONTENT + '\n');
});

Expand Down Expand Up @@ -139,7 +139,7 @@ test.describe('#sendMessages', () => {
// It seems that the markdown renderer adds a new line, but the '\n' inserted when
// pressing Enter above is trimmed.
await expect(
messages.locator('.jp-chat-message .jp-chat-rendermime-markdown')
messages.locator('.jp-chat-message .jp-chat-rendered-markdown')
).toHaveText(MSG_CONTENT + '\n');
});

Expand Down Expand Up @@ -195,7 +195,7 @@ test.describe('#sendMessages', () => {
// It seems that the markdown renderer adds a new line, but the '\n' inserter when
// pressing Enter above is trimmed.
await expect(
messages.locator('.jp-chat-message .jp-chat-rendermime-markdown')
messages.locator('.jp-chat-message .jp-chat-rendered-markdown')
).toHaveText(`${MSG_CONTENT}\n${cellContent}\n`);
});

Expand Down Expand Up @@ -244,7 +244,7 @@ test.describe('#sendMessages', () => {
// It seems that the markdown renderer adds a new line, but the '\n' inserter when
// pressing Enter above is trimmed.
await expect(
messages.locator('.jp-chat-message .jp-chat-rendermime-markdown')
messages.locator('.jp-chat-message .jp-chat-rendered-markdown')
).toHaveText(`${MSG_CONTENT}\nprint\n`);
});
});
8 changes: 4 additions & 4 deletions ui-tests/tests/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
const splitPath = filename.split('/');
const tabName = splitPath[splitPath.length - 1];
await page.waitForCondition(
async () => await page.activity.isTabActive(tabName)

Check failure on line 51 in ui-tests/tests/test-utils.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/ui-config.spec.ts:198:7 › #typingNotification › should display typing user

3) tests/ui-config.spec.ts:198:7 › #typingNotification › should display typing user ────────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: locator.isChecked: Target page, context or browser has been closed at tests/test-utils.ts:51 49 | const tabName = splitPath[splitPath.length - 1]; 50 | await page.waitForCondition( > 51 | async () => await page.activity.isTabActive(tabName) | ^ 52 | ); 53 | panel = await page.activity.getPanelLocator(tabName); 54 | at Object.isInSimpleMode (/home/runner/work/jupyter-chat/jupyter-chat/ui-tests/node_modules/@jupyterlab/galata/src/utils.ts:311:17) at ActivityHelper.isTabActive (/home/runner/work/jupyter-chat/jupyter-chat/ui-tests/node_modules/@jupyterlab/galata/src/helpers/activity.ts:46:21) at /home/runner/work/jupyter-chat/jupyter-chat/ui-tests/tests/test-utils.ts:51:37 at Timeout.check (/home/runner/work/jupyter-chat/jupyter-chat/ui-tests/node_modules/@jupyterlab/galata/src/utils.ts:183:33)
);
panel = await page.activity.getPanelLocator(tabName);

Expand All @@ -56,8 +56,8 @@
if (content) {
await page.waitForCondition(async () => {
const expectedCount = content.messages.length;
const currentCount = await panel?.locator('.jp-chat-rendermime-markdown').count();
const currentBodies = await panel?.locator('.jp-chat-rendermime-markdown').allTextContents();
const currentCount = await panel?.locator('.jp-chat-rendered-markdown').count();
const currentBodies = await panel?.locator('.jp-chat-rendered-markdown').allTextContents();
return expectedCount === currentCount && currentBodies!.every(value => value !== '');
});
}
Expand All @@ -83,8 +83,8 @@
if (content) {
await page.waitForCondition(async () => {
const expectedCount = content.messages.length;
const currentCount = await panel?.locator('.jp-chat-rendermime-markdown').count();
const currentBodies = await panel?.locator('.jp-chat-rendermime-markdown').allTextContents();
const currentCount = await panel?.locator('.jp-chat-rendered-markdown').count();
const currentBodies = await panel?.locator('.jp-chat-rendered-markdown').allTextContents();
return expectedCount === currentCount && currentBodies!.every(value => value !== '');
});
}
Expand Down
Loading