Skip to content

Wave AI UI Remake #2103

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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: 20 additions & 11 deletions frontend/app/element/markdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,31 @@
}

.codeblock-actions {
visibility: hidden;
display: flex;
position: absolute;
top: 0;
right: 0;
top: 5px;
right: 5px;
display: flex;
gap: 4px;
opacity: 0;
transition: opacity 0.1s ease-in-out;
background-color: rgba(0, 0, 0, 0.2);
backdrop-filter: blur(2px);
border-radius: 4px;
backdrop-filter: blur(8px);
margin: 0.143em;
padding: 0.286em;
align-items: center;
justify-content: flex-end;
gap: 0.286em;
padding: 2px 4px;

.iconbutton {
font-size: 14px;
padding: 3px;
border-radius: 3px;

&:hover {
background-color: rgba(255, 255, 255, 0.1);
}
}
}

&:hover .codeblock-actions {
visibility: visible;
opacity: 1;
}
}

Expand Down
73 changes: 71 additions & 2 deletions frontend/app/element/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
resolveSrcSet,
transformBlocks,
} from "@/app/element/markdown-util";
import { boundNumber, useAtomValueSafe } from "@/util/util";
import { ContextMenuModel as contextMenuModel } from "@/app/store/contextmenu";
import { RpcApi } from "@/app/store/wshclientapi";
import { TabRpcClient } from "@/app/store/wshrpcutil";
import { boundNumber, stringToBase64, useAtomValueSafe } from "@/util/util";
import { clsx } from "clsx";
import { Atom } from "jotai";
import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overlayscrollbars-react";
Expand All @@ -21,7 +24,7 @@ import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
import rehypeSlug from "rehype-slug";
import RemarkFlexibleToc, { TocItem } from "remark-flexible-toc";
import remarkGfm from "remark-gfm";
import { openLink } from "../store/global";
import { atoms, getAllBlockComponentModels, globalStore, openLink } from "../store/global";
import { IconButton } from "./iconbutton";
import "./markdown.scss";

Expand Down Expand Up @@ -91,6 +94,64 @@ const CodeBlock = ({ children, onClickExecute }: CodeBlockProps) => {
}
};

const handleSendToTerminal = async (e: React.MouseEvent) => {
let textToSend = getTextContent(children);
textToSend = textToSend.replace(/\n$/, "");

const allBCMs = getAllBlockComponentModels();
const terminalBlocks = [];

for (const bcm of allBCMs) {
if (bcm?.viewModel?.viewType === "term") {
terminalBlocks.push({
id: (bcm.viewModel as any).blockId || "",
title: `Terminal ${terminalBlocks.length + 1}`,
});
}
}

const menuItems: ContextMenuItem[] = terminalBlocks.map((terminal) => ({
label: terminal.title,
click: () => sendTextToTerminal(terminal.id, textToSend),
}));

menuItems.push({ type: "separator" });
menuItems.push({
label: "Create New Terminal",
click: async () => {
const termBlockDef = {
meta: {
controller: "shell",
view: "term",
},
};
try {
const tabId = globalStore.get(atoms.staticTabId);
const oref = await RpcApi.CreateBlockCommand(TabRpcClient, {
tabid: tabId,
blockdef: termBlockDef,
});

const blockId = oref.split(":")[1];
setTimeout(() => sendTextToTerminal(blockId, textToSend), 500);
} catch (error) {
console.error("Failed to create new terminal block:", error);
}
Comment on lines +129 to +139
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fixed potential issue with hardcoded timeout

The 500ms hardcoded timeout when creating a new terminal may not always be sufficient for terminal initialization, which could lead to missed text input.

Consider implementing a callback or event-based approach instead of a timeout to ensure the terminal is ready before sending text:

- setTimeout(() => sendTextToTerminal(blockId, textToSend), 500);
+ // Use an event listener or callback to detect when terminal is ready
+ const checkTerminalReady = () => {
+   const terminal = getAllBlockComponentModels().find(
+     bcm => bcm?.viewModel?.blockId === blockId && bcm?.viewModel?.viewType === "term"
+   );
+   if (terminal && terminal.isReady) {
+     sendTextToTerminal(blockId, textToSend);
+   } else {
+     setTimeout(checkTerminalReady, 100);
+   }
+ };
+ checkTerminalReady();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const tabId = globalStore.get(atoms.staticTabId);
const oref = await RpcApi.CreateBlockCommand(TabRpcClient, {
tabid: tabId,
blockdef: termBlockDef,
});
const blockId = oref.split(":")[1];
setTimeout(() => sendTextToTerminal(blockId, textToSend), 500);
} catch (error) {
console.error("Failed to create new terminal block:", error);
}
const tabId = globalStore.get(atoms.staticTabId);
const oref = await RpcApi.CreateBlockCommand(TabRpcClient, {
tabid: tabId,
blockdef: termBlockDef,
});
const blockId = oref.split(":")[1];
// Use an event listener or callback to detect when terminal is ready
const checkTerminalReady = () => {
const terminal = getAllBlockComponentModels().find(
bcm => bcm?.viewModel?.blockId === blockId && bcm?.viewModel?.viewType === "term"
);
if (terminal && terminal.isReady) {
sendTextToTerminal(blockId, textToSend);
} else {
setTimeout(checkTerminalReady, 100);
}
};
checkTerminalReady();
} catch (error) {
console.error("Failed to create new terminal block:", error);
}

},
});

contextMenuModel.showContextMenu(menuItems, e);
};

const sendTextToTerminal = (blockId: string, text: string) => {
const textWithReturn = text + "\n";
const b64data = stringToBase64(textWithReturn);
RpcApi.ControllerInputCommand(TabRpcClient, {
blockid: blockId,
inputdata64: b64data,
});
};

return (
<pre className="codeblock">
{children}
Expand All @@ -105,6 +166,14 @@ const CodeBlock = ({ children, onClickExecute }: CodeBlockProps) => {
}}
/>
)}
<IconButton
decl={{
elemtype: "iconbutton",
icon: "regular@terminal",
click: handleSendToTerminal,
title: "Send to Terminal",
}}
/>
</div>
</pre>
);
Expand Down
58 changes: 33 additions & 25 deletions frontend/app/element/typingindicator.scss
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

$dot-width: 11px;
$dot-color: var(--success-color);
$speed: 1.5s;
.typing-indicator {
display: inline-flex;
align-items: center;
gap: 8px;
margin: 0;
padding: 0;

.typing {
position: relative;
height: $dot-width;
&-bubble {
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(from var(--accent-color) r g b / 0.1);
border-radius: 20px;
padding: 6px 12px;
gap: 4px;
}

span {
content: "";
animation: blink $speed infinite;
animation-fill-mode: both;
height: $dot-width;
width: $dot-width;
background: $dot-color;
position: absolute;
left: 0;
top: 0;
&-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background-color: var(--accent-color);
opacity: 0.7;

&:nth-child(1) {
animation: typing-animation 1.4s infinite ease-in-out;
animation-delay: 0s;
}

&:nth-child(2) {
animation: typing-animation 1.4s infinite ease-in-out;
animation-delay: 0.2s;
margin-left: $dot-width * 1.5;
}

&:nth-child(3) {
animation: typing-animation 1.4s infinite ease-in-out;
animation-delay: 0.4s;
margin-left: $dot-width * 3;
}
}
}

@keyframes blink {
0% {
opacity: 0.1;
@keyframes typing-animation {
0%,
100% {
transform: translateY(0);
}
20% {
50% {
transform: translateY(-2.5px);
opacity: 1;
}
100% {
opacity: 0.1;
}
}
23 changes: 12 additions & 11 deletions frontend/app/element/typingindicator.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

import { clsx } from "clsx";

import React from "react";
import "./typingindicator.scss";

type TypingIndicatorProps = {
export interface TypingIndicatorProps {
style?: React.CSSProperties;
className?: string;
};
const TypingIndicator = ({ className }: TypingIndicatorProps) => {
}

export const TypingIndicator: React.FC<TypingIndicatorProps> = ({ style, className }) => {
return (
<div className={clsx("typing", className)}>
<span></span>
<span></span>
<span></span>
<div className={`typing-indicator ${className || ""}`} style={style}>
<div className="typing-indicator-bubble">
<div className="typing-indicator-dot"></div>
<div className="typing-indicator-dot"></div>
<div className="typing-indicator-dot"></div>
</div>
</div>
);
};

export { TypingIndicator };
Loading