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 @@ -309,8 +309,33 @@ export function Prompt(props: PromptProps) {
309309 } )
310310
311311 sdk . event . on ( TuiEvent . PromptAppend . type , ( evt ) => {
312+ const oldLength = input . plainText . length
312313 input . gotoBufferEnd ( )
313314 input . insertText ( evt . properties . text )
315+
316+ if ( evt . properties . parts . length > 0 ) {
317+ for ( const part of evt . properties . parts ) {
318+ const extmarkId =
319+ part . source &&
320+ input . extmarks . create ( {
321+ start : oldLength + ( part . type === "file" ? part . source . text . start : part . source . start ) ,
322+ end : oldLength + ( part . type === "file" ? part . source . text . end : part . source . end ) ,
323+ virtual : true ,
324+ styleId : part . type === "agent" ? agentStyleId : fileStyleId ,
325+ typeId : promptPartTypeId ,
326+ } )
327+
328+ setStore (
329+ produce ( ( draft ) => {
330+ const partIndex = draft . prompt . parts . length
331+ draft . prompt . parts . push ( part )
332+ if ( extmarkId !== undefined ) {
333+ draft . extmarkToPartIndex . set ( extmarkId , partIndex )
334+ }
335+ } ) ,
336+ )
337+ }
338+ }
314339 } )
315340
316341 createEffect ( ( ) => {
Original file line number Diff line number Diff line change 11import { BusEvent } from "@/bus/bus-event"
22import { Bus } from "@/bus"
3+ import { MessageV2 } from "@/session/message-v2"
34import z from "zod"
45
56export const TuiEvent = {
6- PromptAppend : BusEvent . define ( "tui.prompt.append" , z . object ( { text : z . string ( ) } ) ) ,
7+ PromptAppend : BusEvent . define (
8+ "tui.prompt.append" ,
9+ z . object ( {
10+ text : z . string ( ) ,
11+ parts : z . array (
12+ z . union ( [
13+ MessageV2 . AgentPart . omit ( { id : true , sessionID : true , messageID : true } ) ,
14+ MessageV2 . FilePart . omit ( { id : true , sessionID : true , messageID : true } ) ,
15+ ] ) ,
16+ ) ,
17+ } ) ,
18+ ) ,
719 CommandExecute : BusEvent . define (
820 "tui.command.execute" ,
921 z . object ( {
Original file line number Diff line number Diff line change @@ -2164,10 +2164,25 @@ export namespace Server {
21642164 ...errors ( 400 ) ,
21652165 } ,
21662166 } ) ,
2167- validator ( "json" , TuiEvent . PromptAppend . properties ) ,
2167+ validator ( "json" , z . object ( { text : z . string ( ) } ) ) ,
21682168 async ( c ) => {
2169- await Bus . publish ( TuiEvent . PromptAppend , c . req . valid ( "json" ) )
2170- return c . json ( true )
2169+ const { text } = c . req . valid ( "json" )
2170+
2171+ try {
2172+ await Bus . publish ( TuiEvent . PromptAppend , {
2173+ text,
2174+ parts : ( await SessionPrompt . resolvePromptParts ( text ) ) . filter (
2175+ ( part ) => part . type === "agent" || part . type === "file" ,
2176+ ) ,
2177+ } )
2178+ return c . json ( true )
2179+ } catch ( error ) {
2180+ log . error ( "Failed to process prompt append" , {
2181+ text,
2182+ error : error instanceof Error ? error . message : String ( error ) ,
2183+ } )
2184+ return c . json ( false )
2185+ }
21712186 } ,
21722187 )
21732188 . post (
Original file line number Diff line number Diff line change @@ -615,6 +615,24 @@ export type EventTuiPromptAppend = {
615615 type : "tui.prompt.append"
616616 properties : {
617617 text : string
618+ parts : Array <
619+ | {
620+ type : "agent"
621+ name : string
622+ source ?: {
623+ value : string
624+ start : number
625+ end : number
626+ }
627+ }
628+ | {
629+ type : "file"
630+ mime : string
631+ filename ?: string
632+ url : string
633+ source ?: FilePartSource
634+ }
635+ >
618636 }
619637}
620638
You can’t perform that action at this time.
0 commit comments