Skip to content

Commit 6420ae9

Browse files
authored
various AI updates (#2574)
* roundtrip image filenames correctly * fix scrolling issue where the thumbs-up/thumbs-down buttons were cut off * update ai-sdk / ai-sdk react to current versions * fix a focus issue when moving to AI panel using ctrl:shift:arrowleft
1 parent cd6389d commit 6420ae9

File tree

6 files changed

+51
-26
lines changed

6 files changed

+51
-26
lines changed

frontend/app/aipanel/aipanelmessages.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const AIPanelMessages = memo(({ messages, status, onContextMenu }: AIPane
1818
const isPanelOpen = useAtomValue(model.getPanelVisibleAtom());
1919
const messagesEndRef = useRef<HTMLDivElement>(null);
2020
const messagesContainerRef = useRef<HTMLDivElement>(null);
21+
const prevStatusRef = useRef<string>(status);
2122

2223
const scrollToBottom = () => {
2324
const container = messagesContainerRef.current;
@@ -41,6 +42,19 @@ export const AIPanelMessages = memo(({ messages, status, onContextMenu }: AIPane
4142
}
4243
}, [isPanelOpen]);
4344

45+
useEffect(() => {
46+
const wasStreaming = prevStatusRef.current === "streaming";
47+
const isNowNotStreaming = status !== "streaming";
48+
49+
if (wasStreaming && isNowNotStreaming) {
50+
requestAnimationFrame(() => {
51+
scrollToBottom();
52+
});
53+
}
54+
55+
prevStatusRef.current = status;
56+
}, [status]);
57+
4458
return (
4559
<div
4660
ref={messagesContainerRef}

frontend/app/store/keymodel.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ function switchBlockInDirection(direction: NavigateDirection) {
236236
}
237237
if (numBlocks === 1) {
238238
FocusManager.getInstance().requestWaveAIFocus();
239+
setTimeout(() => {
240+
FocusManager.getInstance().refocusNode();
241+
}, 10);
239242
return;
240243
}
241244
}
@@ -249,6 +252,9 @@ function switchBlockInDirection(direction: NavigateDirection) {
249252
const navResult = layoutModel.switchNodeFocusInDirection(direction, inWaveAI);
250253
if (navResult.atLeft) {
251254
FocusManager.getInstance().requestWaveAIFocus();
255+
setTimeout(() => {
256+
FocusManager.getInstance().refocusNode();
257+
}, 10);
252258
return;
253259
}
254260
setTimeout(() => {

package-lock.json

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"vitest": "^3.0.9"
9090
},
9191
"dependencies": {
92-
"@ai-sdk/react": "^2.0.76",
92+
"@ai-sdk/react": "^2.0.92",
9393
"@floating-ui/react": "^0.27.16",
9494
"@monaco-editor/loader": "^1.5.0",
9595
"@monaco-editor/react": "^4.7.0",
@@ -104,7 +104,7 @@
104104
"@xterm/addon-web-links": "^0.11.0",
105105
"@xterm/addon-webgl": "^0.18.0",
106106
"@xterm/xterm": "^5.5.0",
107-
"ai": "^5.0.44",
107+
"ai": "^5.0.92",
108108
"base64-js": "^1.5.1",
109109
"class-variance-authority": "^0.7.1",
110110
"clsx": "^2.1.1",

pkg/aiusechat/openai/openai-backend.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ type OpenAIMessageContent struct {
9494
}
9595

9696
func (c *OpenAIMessageContent) clean() *OpenAIMessageContent {
97-
if c.PreviewUrl == "" {
97+
if c.PreviewUrl == "" && (c.Type != "input_image" || c.Filename == "") {
9898
return c
9999
}
100100
rtn := *c
101101
rtn.PreviewUrl = ""
102+
if c.Type == "input_image" {
103+
rtn.Filename = ""
104+
}
102105
return &rtn
103106
}
104107

pkg/aiusechat/openai/openai-convertmessage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func convertContentBlockToParts(block OpenAIMessageContent, role string) []uctyp
4545
parts = append(parts, uctypes.UIMessagePart{
4646
Type: "data-userfile",
4747
Data: uctypes.UIMessageDataUserFile{
48+
FileName: block.Filename,
4849
MimeType: "image/*",
4950
PreviewUrl: block.PreviewUrl,
5051
},
@@ -317,6 +318,7 @@ func convertFileAIMessagePart(part uctypes.AIMessagePart) (*OpenAIMessageContent
317318
return &OpenAIMessageContent{
318319
Type: "input_image",
319320
ImageUrl: imageUrl,
321+
Filename: part.FileName,
320322
PreviewUrl: part.PreviewUrl,
321323
}, nil
322324

0 commit comments

Comments
 (0)