-
Notifications
You must be signed in to change notification settings - Fork 1
feat: in-app AI Chat panel (issue #209, Phase 8) #252
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
17b0dd0
feat: add in-app AI Chat panel (issue #209, Phase 8)
fernandotonon ba7f0b4
fix(ai-chat): tool calls execute correctly; show model name in header
fernandotonon 0227717
fix(ai-chat): stop material bleeding; selectable text; context trunca…
fernandotonon 54c3216
fix(ai-chat): fix blank chat area after TextEdit migration
fernandotonon a455421
fix(ai-chat): fix blank bubbles with explicit TextEdit layout
fernandotonon 01b8453
fix(ai-chat): overlay pattern for selectable text — no more blank bub…
fernandotonon f5e7f5b
fix(ai-chat): revert bubble layout to original anchoring; add TextEdi…
fernandotonon 6b6f201
fix(ai-chat): remove invalid background:null from QtQuick TextEdit
fernandotonon 44e75d9
fix(ai-chat): stop post-tool loop and context overflow
fernandotonon 31c978b
fix(ai-chat): stop button works between tool calls; fix tool tag parsing
fernandotonon ead6af5
fix(ai-chat): strip chat-template tokens and hallucinated user turns
fernandotonon dbf6f67
fix(ai-chat): replace fragile tag regex with JSON object scanner
fernandotonon 781cd8c
fix(ai-chat): handle [Tool: X]\nArguments:{} format; fix result format
fernandotonon 882a7d0
feat(ai-chat): agentic error recovery — retry after tool failures
fernandotonon 8facd38
Improve AI chat agentic behavior and multi-step tool execution
fernandotonon 382a9e2
Fix multi-step AI tool chain: correct material params, KV-cache ordering
fernandotonon 765e28f
Trim verbose tool results in history to conserve context window
fernandotonon e315679
Pin original user message in sliding history window
fernandotonon 9548858
Cap AI chat output to 400 tokens; fix box=cube rule in system prompt
fernandotonon 558e7e2
Fix AI chat focus and copy/paste issues
fernandotonon fd8bb45
Improve AI chat agentic behavior and fix model artifacts
fernandotonon 3412ebd
Switch AI chat to structured JSON response format with retry
fernandotonon 12c9b79
Fix phantom box creation and improve axis/remaining enforcement
fernandotonon ba0d639
Add list_files and read_file MCP tools; fix Z-axis direction
fernandotonon f2b0ffd
Add search_files tool, filter AI tool list, fix coordinates and recen…
fernandotonon eea89fb
Add camera MCP tools, search_files, task separation rule
fernandotonon 0aaca04
Fix chat focus on app reactivation; clean up LLM model list
fernandotonon 37d9aef
v2.21.0: Add delete_entity tool, clean up debug prints, update docs a…
fernandotonon 9185a7e
Address PR review: QPointer, input height cap, remove dead code
fernandotonon eab8d06
Merge branch 'master' into feat/ai-chat-panel
fernandotonon 4ace39a
Fix CI: add AIChatManager to tests/CMakeLists.txt sources
fernandotonon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,311 @@ | ||
| import QtQuick 2.15 | ||
| import QtQuick.Controls 2.15 | ||
| import QtQuick.Layouts 1.15 | ||
| import AIChatPanel 1.0 | ||
| import PropertiesPanel 1.0 | ||
|
|
||
| Rectangle { | ||
| id: root | ||
| color: PropertiesPanelController.panelColor | ||
|
|
||
| // Forward focus to the input field whenever the panel gains active focus | ||
| // (e.g. when the user clicks anywhere in the dock after returning from | ||
| // another app window). | ||
| onActiveFocusChanged: { | ||
| if (activeFocus) | ||
| Qt.callLater(() => inputField.forceActiveFocus()) | ||
| } | ||
|
|
||
| // ---- Header bar ---- | ||
| Rectangle { | ||
| id: header | ||
| anchors { top: parent.top; left: parent.left; right: parent.right } | ||
| height: 36 | ||
| color: PropertiesPanelController.headerColor | ||
|
|
||
| RowLayout { | ||
| anchors { fill: parent; leftMargin: 8; rightMargin: 8 } | ||
| spacing: 6 | ||
|
|
||
| Text { | ||
| text: "AI Chat" | ||
| color: PropertiesPanelController.textColor | ||
| font.pixelSize: 13; font.bold: true | ||
| Layout.fillWidth: true | ||
| } | ||
|
|
||
| // Model status dot | ||
| Rectangle { | ||
| width: 8; height: 8; radius: 4 | ||
| color: AIChatManager.modelAvailable ? "#44dd44" : "#dd4444" | ||
| } | ||
|
|
||
| Text { | ||
| text: AIChatManager.modelAvailable | ||
| ? AIChatManager.currentModelName | ||
| : "No model" | ||
| color: PropertiesPanelController.textColor | ||
| font.pixelSize: 10 | ||
| elide: Text.ElideMiddle | ||
| Layout.maximumWidth: 160 | ||
| } | ||
|
|
||
| // Clear button | ||
| Rectangle { | ||
| width: 22; height: 22; radius: 3 | ||
| color: clearArea.containsMouse | ||
| ? Qt.lighter(PropertiesPanelController.panelColor, 1.5) | ||
| : "transparent" | ||
|
|
||
| Text { anchors.centerIn: parent; text: "✕"; color: PropertiesPanelController.textColor; font.pixelSize: 11 } | ||
| MouseArea { | ||
| id: clearArea | ||
| anchors.fill: parent | ||
| hoverEnabled: true | ||
| cursorShape: Qt.PointingHandCursor | ||
| onClicked: AIChatManager.clearHistory() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ---- Single selectable conversation area ---- | ||
| Flickable { | ||
| id: msgFlick | ||
| anchors { | ||
| top: header.bottom; left: parent.left; right: parent.right | ||
| bottom: thinkingRow.top; bottomMargin: 0 | ||
| } | ||
| clip: true | ||
| contentWidth: width | ||
| contentHeight: msgEdit.implicitHeight + 16 | ||
|
|
||
| function scrollToBottom() { | ||
| contentY = Math.max(0, contentHeight - height) | ||
| } | ||
|
|
||
| TextEdit { | ||
| id: msgEdit | ||
| anchors { left: parent.left; right: parent.right; top: parent.top; margins: 8 } | ||
| readOnly: true | ||
| selectByMouse: true | ||
| textFormat: Text.RichText | ||
| wrapMode: Text.WrapAtWordBoundaryOrAnywhere | ||
| color: PropertiesPanelController.textColor | ||
| font.pixelSize: 12 | ||
| selectionColor: Qt.rgba(0.3, 0.5, 0.8, 0.5) | ||
| selectedTextColor: PropertiesPanelController.textColor | ||
| text: root.buildHtml() | ||
|
|
||
| // Intercept Ctrl/Cmd+C to copy plain text instead of RichText HTML. | ||
| Keys.onPressed: (event) => { | ||
| if ((event.key === Qt.Key_C) && | ||
| (event.modifiers & Qt.ControlModifier)) { | ||
| if (selectedText.length > 0) { | ||
| Qt.application.clipboard.text = selectedText | ||
| event.accepted = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // When the user finishes selecting (mouse released with no selection), | ||
| // return focus to the input field. Use onActiveFocusChanged instead of | ||
| // onSelectedTextChanged to avoid stealing focus mid-drag. | ||
| onActiveFocusChanged: { | ||
| if (!activeFocus && selectedText.length === 0) | ||
| Qt.callLater(() => inputField.forceActiveFocus()) | ||
| } | ||
| } | ||
|
|
||
| onContentHeightChanged: Qt.callLater(scrollToBottom) | ||
|
|
||
| Connections { | ||
| target: AIChatManager | ||
| function onMessagesChanged() { Qt.callLater(msgFlick.scrollToBottom) } | ||
| function onStreamingTextChanged(){ Qt.callLater(msgFlick.scrollToBottom) } | ||
| } | ||
| } | ||
|
|
||
| // ---- Thinking dots (no tokens yet) ---- | ||
| Row { | ||
| id: thinkingRow | ||
| anchors { bottom: inputRow.top; left: parent.left; leftMargin: 12; bottomMargin: 6 } | ||
| height: visible ? 14 : 0 | ||
| spacing: 4 | ||
| visible: AIChatManager.isGenerating | ||
|
|
||
| Repeater { | ||
| model: 3 | ||
| Rectangle { | ||
| width: 6; height: 6; radius: 3 | ||
| color: PropertiesPanelController.accentColor | ||
| opacity: 0.3 | ||
| SequentialAnimation on opacity { | ||
| loops: Animation.Infinite | ||
| NumberAnimation { to: 1.0; duration: 400 } | ||
| NumberAnimation { to: 0.3; duration: 400 } | ||
| PauseAnimation { duration: index * 150 } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ---- Input row ---- | ||
| Rectangle { | ||
| id: inputRow | ||
| anchors { bottom: parent.bottom; left: parent.left; right: parent.right } | ||
| height: Math.max(40, Math.min(inputField.implicitHeight, 80) + 16) | ||
| color: PropertiesPanelController.headerColor | ||
| border.color: PropertiesPanelController.borderColor | ||
| border.width: 1 | ||
|
|
||
| TextArea { | ||
| id: inputField | ||
| anchors { left: parent.left; right: sendBtn.left; | ||
| verticalCenter: parent.verticalCenter; | ||
| leftMargin: 8; rightMargin: 6 } | ||
| height: Math.min(implicitHeight, 80) | ||
| placeholderText: AIChatManager.modelAvailable | ||
| ? "Ask AI to do something…" | ||
| : "Load an AI model first (AI → AI Model Settings)" | ||
| color: PropertiesPanelController.textColor | ||
| background: null | ||
| font.pixelSize: 12 | ||
| wrapMode: Text.WrapAtWordBoundaryOrAnywhere | ||
| enabled: AIChatManager.modelAvailable && !AIChatManager.isGenerating | ||
| focus: true | ||
|
|
||
| Keys.onReturnPressed: (event) => { | ||
| if (event.modifiers & Qt.ShiftModifier) { | ||
| event.accepted = false // shift+enter → newline | ||
| } else { | ||
| event.accepted = true | ||
| doSend() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Rectangle { | ||
| id: sendBtn | ||
| anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 8 } | ||
| width: 32; height: 32; radius: 4 | ||
| color: sendBtnArea.containsMouse | ||
| ? PropertiesPanelController.accentColor | ||
| : PropertiesPanelController.buttonColor | ||
| enabled: AIChatManager.modelAvailable | ||
|
|
||
| Text { | ||
| anchors.centerIn: parent | ||
| text: AIChatManager.isGenerating ? "■" : "▶" | ||
| color: PropertiesPanelController.textColor | ||
| font.pixelSize: 13 | ||
| } | ||
|
|
||
| MouseArea { | ||
| id: sendBtnArea | ||
| anchors.fill: parent | ||
| hoverEnabled: true | ||
| cursorShape: Qt.PointingHandCursor | ||
| onClicked: { | ||
| if (AIChatManager.isGenerating) | ||
| AIChatManager.stopGeneration() | ||
| else | ||
| doSend() | ||
| } | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // ---- Empty state hint ---- | ||
| Column { | ||
| anchors.centerIn: parent | ||
| anchors.verticalCenterOffset: -30 | ||
| spacing: 8 | ||
| visible: AIChatManager.messages.length === 0 && !AIChatManager.isGenerating | ||
|
|
||
| Text { | ||
| anchors.horizontalCenter: parent.horizontalCenter | ||
| text: "✦" | ||
| color: PropertiesPanelController.accentColor | ||
| font.pixelSize: 28 | ||
| } | ||
| Text { | ||
| anchors.horizontalCenter: parent.horizontalCenter | ||
| text: "Ask me to control the editor" | ||
| color: PropertiesPanelController.textColor | ||
| font.pixelSize: 13; opacity: 0.7 | ||
| } | ||
| Text { | ||
| anchors.horizontalCenter: parent.horizontalCenter | ||
| text: "\"make the selected mesh twice as large\"" | ||
| color: PropertiesPanelController.textColor | ||
| font.pixelSize: 11; opacity: 0.45; font.italic: true | ||
| } | ||
| } | ||
|
|
||
| // ---- Helpers ---- | ||
|
|
||
| function doSend() { | ||
| var txt = inputField.text.trim() | ||
| if (txt.length > 0) { | ||
| AIChatManager.sendMessage(txt) | ||
| inputField.text = "" | ||
| } | ||
| } | ||
|
|
||
| function escHtml(t) { | ||
| return t.replace(/&/g, "&") | ||
| .replace(/</g, "<") | ||
| .replace(/>/g, ">") | ||
| .replace(/\n/g, "<br>") | ||
| } | ||
|
|
||
| function buildHtml() { | ||
| var html = "" | ||
| var msgs = AIChatManager.messages | ||
| for (var i = 0; i < msgs.length; ++i) { | ||
| var msg = msgs[i] | ||
| var isTool = msg.isTool | ||
| var role = msg.role | ||
| var roleColor, roleLabel | ||
| if (isTool) { roleColor = "#88cc88"; roleLabel = "⚙ tool" } | ||
| else if (role === "user"){ roleColor = "#88aacc"; roleLabel = "you" } | ||
| else { roleColor = "#aaaaaa"; roleLabel = "assistant" } | ||
|
|
||
| // Assistant messages may be structured JSON — render appropriately. | ||
| var displayText = msg.text | ||
| if (role === "assistant" && !isTool) { | ||
| var trimmed = msg.text.trim() | ||
| if (trimmed.startsWith("{")) { | ||
| try { | ||
| var obj = JSON.parse(trimmed) | ||
| if (obj && obj.command) | ||
| displayText = "[calling " + obj.command + "]" | ||
| else if (obj && obj.response) | ||
| displayText = obj.response // final done message | ||
| else if (obj && obj.name) | ||
| displayText = "[calling " + obj.name + "]" // legacy fallback | ||
| } catch(e) {} | ||
| } | ||
| } | ||
|
|
||
| if (i > 0) html += "<br>" | ||
| if (role === "user") { | ||
| html += '<p align="right"><font color="#88aacc"><small><b>you</b></small></font><br>' | ||
| html += escHtml(displayText) + '</p>' | ||
| } else { | ||
| html += '<font color="' + roleColor + '"><small><b>' + roleLabel + '</b></small></font><br>' | ||
| html += escHtml(displayText) + "<br>" | ||
| } | ||
| } | ||
|
|
||
| // In-progress streaming text | ||
| if (AIChatManager.streamingText.length > 0) { | ||
| if (msgs.length > 0) html += "<br>" | ||
| html += '<font color="#aaaaaa"><small><b>assistant</b></small></font><br>' | ||
| html += escHtml(AIChatManager.streamingText) | ||
| } | ||
|
|
||
| return html | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hide the thinking dots once streaming starts.
This row is labeled "no tokens yet", but
visibleonly checksisGenerating, so the dots stay on-screen during the whole streamed reply.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents