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 @@ -250,8 +250,33 @@ export function Prompt(props: PromptProps) {
250250 } )
251251
252252 sdk . event . on ( TuiEvent . PromptAppend . type , ( evt ) => {
253+ const oldLength = input . plainText . length
253254 input . gotoBufferEnd ( )
254255 input . insertText ( evt . properties . text )
256+
257+ if ( evt . properties . parts . length > 0 ) {
258+ for ( const part of evt . properties . parts ) {
259+ const extmarkId =
260+ part . source &&
261+ input . extmarks . create ( {
262+ start : oldLength + ( part . type === "file" ? part . source . text . start : part . source . start ) ,
263+ end : oldLength + ( part . type === "file" ? part . source . text . end : part . source . end ) ,
264+ virtual : true ,
265+ styleId : part . type === "agent" ? agentStyleId : fileStyleId ,
266+ typeId : promptPartTypeId ,
267+ } )
268+
269+ setStore (
270+ produce ( ( draft ) => {
271+ const partIndex = draft . prompt . parts . length
272+ draft . prompt . parts . push ( part )
273+ if ( extmarkId !== undefined ) {
274+ draft . extmarkToPartIndex . set ( extmarkId , partIndex )
275+ }
276+ } ) ,
277+ )
278+ }
279+ }
255280 } )
256281
257282 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 @@ -1519,10 +1519,25 @@ export namespace Server {
15191519 ...errors ( 400 ) ,
15201520 } ,
15211521 } ) ,
1522- validator ( "json" , TuiEvent . PromptAppend . properties ) ,
1522+ validator ( "json" , z . object ( { text : z . string ( ) } ) ) ,
15231523 async ( c ) => {
1524- await Bus . publish ( TuiEvent . PromptAppend , c . req . valid ( "json" ) )
1525- return c . json ( true )
1524+ const { text } = c . req . valid ( "json" )
1525+
1526+ try {
1527+ await Bus . publish ( TuiEvent . PromptAppend , {
1528+ text,
1529+ parts : ( await SessionPrompt . resolvePromptParts ( text ) ) . filter (
1530+ ( part ) => part . type === "agent" || part . type === "file" ,
1531+ ) ,
1532+ } )
1533+ return c . json ( true )
1534+ } catch ( error ) {
1535+ log . error ( "Failed to process prompt append" , {
1536+ text,
1537+ error : error instanceof Error ? error . message : String ( error ) ,
1538+ } )
1539+ return c . json ( false )
1540+ }
15261541 } ,
15271542 )
15281543 . post (
Original file line number Diff line number Diff line change @@ -584,6 +584,24 @@ export type EventTuiPromptAppend = {
584584 type : "tui.prompt.append"
585585 properties : {
586586 text : string
587+ parts : Array <
588+ | {
589+ type : "agent"
590+ name : string
591+ source ?: {
592+ value : string
593+ start : number
594+ end : number
595+ }
596+ }
597+ | {
598+ type : "file"
599+ mime : string
600+ filename ?: string
601+ url : string
602+ source ?: FilePartSource
603+ }
604+ >
587605 }
588606}
589607
You can’t perform that action at this time.
0 commit comments