File tree Expand file tree Collapse file tree 4 files changed +74
-4
lines changed
Expand file tree Collapse file tree 4 files changed +74
-4
lines changed Original file line number Diff line number Diff line change @@ -248,8 +248,33 @@ export function Prompt(props: PromptProps) {
248248 } )
249249
250250 sdk . event . on ( TuiEvent . PromptAppend . type , ( evt ) => {
251+ const oldLength = input . plainText . length
251252 input . gotoBufferEnd ( )
252253 input . insertText ( evt . properties . text )
254+
255+ if ( evt . properties . parts . length > 0 ) {
256+ for ( const part of evt . properties . parts ) {
257+ const extmarkId =
258+ part . source &&
259+ input . extmarks . create ( {
260+ start : oldLength + ( part . type === "file" ? part . source . text . start : part . source . start ) ,
261+ end : oldLength + ( part . type === "file" ? part . source . text . end : part . source . end ) ,
262+ virtual : true ,
263+ styleId : part . type === "agent" ? agentStyleId : fileStyleId ,
264+ typeId : promptPartTypeId ,
265+ } )
266+
267+ setStore (
268+ produce ( ( draft ) => {
269+ const partIndex = draft . prompt . parts . length
270+ draft . prompt . parts . push ( part )
271+ if ( extmarkId !== undefined ) {
272+ draft . extmarkToPartIndex . set ( extmarkId , partIndex )
273+ }
274+ } ) ,
275+ )
276+ }
277+ }
253278 } )
254279
255280 createEffect ( ( ) => {
Original file line number Diff line number Diff line change 11import { Bus } from "@/bus"
2+ import { MessageV2 } from "@/session/message-v2"
23import z from "zod"
34
45export const TuiEvent = {
5- PromptAppend : Bus . event ( "tui.prompt.append" , z . object ( { text : z . string ( ) } ) ) ,
6+ PromptAppend : Bus . event (
7+ "tui.prompt.append" ,
8+ z . object ( {
9+ text : z . string ( ) ,
10+ parts : z . array (
11+ z . union ( [
12+ MessageV2 . AgentPart . omit ( { id : true , sessionID : true , messageID : true } ) ,
13+ MessageV2 . FilePart . omit ( { id : true , sessionID : true , messageID : true } ) ,
14+ ] ) ,
15+ ) ,
16+ } ) ,
17+ ) ,
618 CommandExecute : Bus . event (
719 "tui.command.execute" ,
820 z . object ( {
Original file line number Diff line number Diff line change @@ -1735,10 +1735,25 @@ export namespace Server {
17351735 ...errors ( 400 ) ,
17361736 } ,
17371737 } ) ,
1738- validator ( "json" , TuiEvent . PromptAppend . properties ) ,
1738+ validator ( "json" , z . object ( { text : z . string ( ) } ) ) ,
17391739 async ( c ) => {
1740- await Bus . publish ( TuiEvent . PromptAppend , c . req . valid ( "json" ) )
1741- return c . json ( true )
1740+ const { text } = c . req . valid ( "json" )
1741+
1742+ try {
1743+ await Bus . publish ( TuiEvent . PromptAppend , {
1744+ text,
1745+ parts : ( await SessionPrompt . resolvePromptParts ( text ) ) . filter (
1746+ ( part ) => part . type === "agent" || part . type === "file" ,
1747+ ) ,
1748+ } )
1749+ return c . json ( true )
1750+ } catch ( error ) {
1751+ log . error ( "Failed to process prompt append" , {
1752+ text,
1753+ error : error instanceof Error ? error . message : String ( error ) ,
1754+ } )
1755+ return c . json ( false )
1756+ }
17421757 } ,
17431758 )
17441759 . post (
Original file line number Diff line number Diff line change @@ -600,6 +600,24 @@ export type EventTuiPromptAppend = {
600600 type : "tui.prompt.append"
601601 properties : {
602602 text : string
603+ parts : Array <
604+ | {
605+ type : "agent"
606+ name : string
607+ source ?: {
608+ value : string
609+ start : number
610+ end : number
611+ }
612+ }
613+ | {
614+ type : "file"
615+ mime : string
616+ filename ?: string
617+ url : string
618+ source ?: FilePartSource
619+ }
620+ >
603621 }
604622}
605623
You can’t perform that action at this time.
0 commit comments