Skip to content

Commit eb1fa58

Browse files
committed
Merge remote-tracking branch 'upstream/ai-agent' into ai-agent
2 parents 9ae5012 + 7715ae6 commit eb1fa58

File tree

3 files changed

+101
-10
lines changed

3 files changed

+101
-10
lines changed

src/pages/aiAssistant/assistant.js

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ export default function openAIAssistantPage() {
222222
child: tag("i", {
223223
className: "icon edit",
224224
}),
225-
// TODO: Implement edit functionality
226-
//onclick: () => editMessage(message.id),
225+
onclick: () => editMessage(message.id),
227226
});
228227
messageActions.appendChild(editBtn);
229228
}
@@ -238,7 +237,11 @@ export default function openAIAssistantPage() {
238237
if (message.role === "user") {
239238
messageContent.textContent = message.content;
240239
} else {
241-
const md = markdownIt();
240+
const md = markdownIt({
241+
html: true,
242+
linkify: true,
243+
typographer: true,
244+
});
242245
messageContent.innerHTML = md.render(message.content);
243246
}
244247

@@ -248,6 +251,74 @@ export default function openAIAssistantPage() {
248251
scrollToBottom();
249252
};
250253

254+
const editMessage = (messageId) => {
255+
const message = chatHistory.find((msg) => msg.id === messageId);
256+
if (!message) return;
257+
258+
const messageEl = messageContainerRef.el.querySelector(
259+
`#message-${message.id}`,
260+
);
261+
const messageContent = messageEl.querySelector(".message-content");
262+
263+
const editContainer = <div className="edit-container"></div>;
264+
265+
const textarea = (
266+
<textarea
267+
className="edit-textarea"
268+
defaultValue={message.content}
269+
placeholder="Edit your message..."
270+
onkeydown={(e) => {
271+
if (e.key === "Enter" && e.ctrlKey) {
272+
e.preventDefault();
273+
// TODO: save edit
274+
} else if (e.key === "Escape") {
275+
e.preventDefault();
276+
// TODO: cancel edit
277+
}
278+
}}
279+
/>
280+
);
281+
282+
const editActions = <div className="edit-actions"></div>;
283+
284+
const editInfo = (
285+
<div className="edit-info">
286+
Press Ctrl+Enter to save, Escape to cancel
287+
</div>
288+
);
289+
290+
const editButtons = (
291+
<div className="edit-buttons">
292+
<button
293+
className="btn btn-sm btn-outline"
294+
onclick={() => {
295+
const md = markdownIt({
296+
html: true,
297+
linkify: true,
298+
typographer: true,
299+
});
300+
messageContent.innerHTML = md.render(message.content);
301+
}}
302+
>
303+
<i className="icon clearclose"></i>{" "}
304+
<span className="btn-text">Cancel</span>
305+
</button>
306+
<button className="btn btn-sm btn-primary">
307+
<i className="icon check"></i> <span className="btn-text">Save</span>
308+
</button>
309+
</div>
310+
);
311+
312+
editActions.append(editInfo, editButtons);
313+
editContainer.append(textarea, editActions);
314+
315+
messageContent.innerHTML = "";
316+
messageContent.appendChild(editContainer);
317+
318+
textarea.focus();
319+
textarea.select();
320+
};
321+
251322
/**
252323
* Updates the profile button appearance and state
253324
* @param {string} profile - Profile type ("ask" or "write")
@@ -416,6 +487,7 @@ export default function openAIAssistantPage() {
416487
);
417488
}
418489
chatHistory.push({
490+
id: msg.id,
419491
role: msg.role,
420492
content: msg.content,
421493
});
@@ -485,7 +557,10 @@ export default function openAIAssistantPage() {
485557
role: "user",
486558
content: userInput,
487559
};
488-
chatHistory.push(userMessageForAgent);
560+
chatHistory.push({
561+
...userMessageForAgent,
562+
id: userMsgId.id,
563+
});
489564

490565
chatInputRef.el.value = "";
491566
handleChatInput();
@@ -609,6 +684,15 @@ export default function openAIAssistantPage() {
609684
);
610685
if (targetMessageElContent) {
611686
targetMessageElContent.innerHTML += errorContent;
687+
} else {
688+
const assistantErrorMsg = {
689+
id: assistantMsgId,
690+
conversationId: currentConversationId,
691+
role: "assistant",
692+
content: errorContent,
693+
timestamp: Date.now(),
694+
};
695+
addMessage(assistantErrorMsg);
612696
}
613697
} finally {
614698
currentController = null;
@@ -631,6 +715,7 @@ export default function openAIAssistantPage() {
631715

632716
if (!wasError) {
633717
chatHistory.push({
718+
id: assistantFinalData.id,
634719
role: "assistant",
635720
content: streamedContent,
636721
});

src/pages/aiAssistant/assistant.module.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,15 @@
182182
border-radius: 0.375rem;
183183
color: var(--primary-text-color);
184184
font-size: 0.875rem;
185-
resize: vertical;
185+
resize: none;
186186
transition: all 0.2s ease;
187-
}
187+
box-sizing: border-box;
188188

189-
.edit-textarea:focus {
190-
outline: none;
191-
border-color: var(--active-color);
192-
box-shadow: 0 0 0 2px rgba(35, 116, 225, 0.1);
189+
&:focus {
190+
outline: none;
191+
border-color: var(--active-color);
192+
box-shadow: 0 0 0 2px rgba(35, 116, 225, 0.1);
193+
}
193194
}
194195

195196
.edit-actions {

src/pages/aiAssistant/system_prompt.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { addedFolder } from "lib/openFolder";
2+
13
export const SYSTEM_PROMPT = `You are a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.
24
35
## Communication
@@ -26,4 +28,7 @@ Otherwise, follow debugging best practices:
2628
1. Unless explicitly requested by the user, use the best suited external APIs and packages to solve the task. There is no need to ask the user for permission.
2729
2. When selecting which version of an API or package to use, choose one that is compatible with the user's dependency management file(s). If no such file exists or if the package is not present, use the latest version that is in your training data.
2830
3. If an external API requires an API Key, be sure to point this out to the user. Adhere to best security practices (e.g. DO NOT hardcode an API key in a place where it can be exposed)
31+
32+
SideBar workspace projects(name, absolutePath or url):
33+
${addedFolder.map((node) => `name: ${node.title}\nurl: ${node.url}`).join("\n")}
2934
`;

0 commit comments

Comments
 (0)