Skip to content
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
2 changes: 2 additions & 0 deletions packages/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const VsCodeMessageTypes = {
copyCodeToEditor: 'extension.copyCodeToEditor',
stopDatasourceTask: 'extension.stopDatasourceTask',
stopApplicationTask: 'extension.stopApplicationTask',
copyMessageToClipboard: 'extension.copyMessageToClipboard',
}

export const UiMessageTypes = {
Expand All @@ -36,4 +37,5 @@ export const UiMessageTypes = {
stopApplicationTask: 'ui.stopApplicationTask',
getPromptVersionDetail: 'ui.getPromptVersionDetail',
getApplicationVersionDetail: 'ui.getApplicationVersionDetail',
copyMessageToClipboard: 'ui.copyMessageToClipboard',
}
24 changes: 12 additions & 12 deletions packages/ui/src/components/ChatBox/ChatBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ const ChatBox = forwardRef(({
chatHistory = [],
setChatHistory = () => { },
loadCoreData,
deployments
deployments,
sendMessage
} = useContext(DataContext);
const chatInput = useRef(null);
const listRefs = useRef([]);
Expand Down Expand Up @@ -559,20 +560,19 @@ const ChatBox = forwardRef(({
(id) => async () => {
const message = chatHistory.find(item => item.id === id);
if (message) {
if (message.exception) {
try {
await navigator.clipboard.writeText(JSON.stringify(message.exception));
toastInfo('The exception has been copied to the clipboard');
} catch (e) {
toastError('Failed to copy the exception!');
}
} else {
await navigator.clipboard.writeText(message.content);
toastInfo('The message has been copied to the clipboard');
const clipboardText = message.exception ? JSON.stringify(message.exception) : message.content;

try {
navigator.clipboard
? await navigator.clipboard.writeText(clipboardText)
: await sendMessage({ type: VsCodeMessageTypes.copyMessageToClipboard, data: clipboardText });
toastInfo(`The ${message.exception ? 'exception' : 'message'} has been copied to the clipboard`);
} catch (e) {
toastError('Failed to copy to the clipboard!');
}
}
},
[chatHistory, toastInfo, toastError],
[chatHistory, toastInfo, toastError, sendMessage],
);

return (
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/context/DataContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const DataProvider = ({ children }) => {
switch (message.type) {
case UiMessageTypes.stopApplicationTask:
case UiMessageTypes.stopDatasourceTask:
case UiMessageTypes.copyMessageToClipboard:
case UiMessageTypes.getSelectedText:
if (messagePromises[message.id]) {
messagePromises[message.id].resolve(message.data);
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/test/plugin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ app.get('/', async (req, res) => {
data = (await getData(`datasources/datasources/prompt_lib/${projectId}`)).rows;
break;
case 'extension.getApplications':
data = (await getData(`applications/applications/prompt_lib/${projectId}`)).rows;
data = (await getData(`applications/applications/prompt_lib/${projectId}?offset=0&limit=1000`)).rows;
break;
case 'extension.getPromptDetail':
data = (await getData(`prompt_lib/prompt/prompt_lib/${projectId}/${chatData}`));
Expand All @@ -89,6 +89,9 @@ app.get('/', async (req, res) => {
case 'extension.copyCodeToEditor':
data = '';
break;
case 'extension.copyMessageToClipboard':
data = '';
break;
default:
data = `unexpected type of message: ${type}`;
break;
Expand Down