@@ -3,10 +3,11 @@ import {
3
3
ThreadListItemPrimitive ,
4
4
ThreadListPrimitive ,
5
5
} from "@assistant-ui/react" ;
6
- import { PlusIcon , Trash2Icon } from "lucide-react" ;
6
+ import { PencilIcon , PlusIcon , Trash2Icon } from "lucide-react" ;
7
7
8
8
import { Button } from "../ui/button" ;
9
9
import { TooltipIconButton } from "./tooltip-icon-button" ;
10
+ import { useThreadListItemRuntime } from "@assistant-ui/react" ;
10
11
11
12
export const ThreadList : FC = ( ) => {
12
13
return (
@@ -38,6 +39,7 @@ const ThreadListItem: FC = () => {
38
39
< ThreadListItemPrimitive . Trigger className = "aui-thread-list-item-trigger" >
39
40
< ThreadListItemTitle />
40
41
</ ThreadListItemPrimitive . Trigger >
42
+ < ThreadListItemRename />
41
43
< ThreadListItemDelete />
42
44
</ ThreadListItemPrimitive . Root >
43
45
) ;
@@ -63,4 +65,40 @@ const ThreadListItemDelete: FC = () => {
63
65
</ TooltipIconButton >
64
66
</ ThreadListItemPrimitive . Delete >
65
67
) ;
68
+ } ;
69
+
70
+
71
+ const ThreadListItemRename : FC = ( ) => {
72
+ const runtime = useThreadListItemRuntime ( ) ;
73
+
74
+ const handleClick = async ( ) => {
75
+ // runtime doesn't expose a direct `title` prop; read it from its state
76
+ let current = "" ;
77
+ try {
78
+ // getState is part of the public runtime surface
79
+ current = ( runtime . getState ?.( ) as any ) ?. title ?? "" ;
80
+ } catch {
81
+ // fallback – generate a title if the runtime provides a helper
82
+ if ( typeof ( runtime as any ) . generateTitle === "function" ) {
83
+ // generateTitle(threadId) in older builds, generateTitle() in newer ones
84
+ current = ( runtime as any ) . generateTitle ( ( runtime as any ) . threadId ?? undefined ) ;
85
+ }
86
+ }
87
+
88
+ const next = prompt ( "Rename thread" , current ) ?. trim ( ) ;
89
+ if ( next && next !== current ) {
90
+ await runtime . rename ( next ) ;
91
+ }
92
+ } ;
93
+
94
+ return (
95
+ < TooltipIconButton
96
+ tooltip = "Rename thread"
97
+ variant = "ghost"
98
+ onClick = { handleClick }
99
+ className = "aui-thread-list-item-rename"
100
+ >
101
+ < PencilIcon />
102
+ </ TooltipIconButton >
103
+ ) ;
66
104
} ;
0 commit comments