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 @@ -1489,10 +1489,25 @@ export namespace Server {
14891489 ...errors ( 400 ) ,
14901490 } ,
14911491 } ) ,
1492- validator ( "json" , TuiEvent . PromptAppend . properties ) ,
1492+ validator ( "json" , z . object ( { text : z . string ( ) } ) ) ,
14931493 async ( c ) => {
1494- await Bus . publish ( TuiEvent . PromptAppend , c . req . valid ( "json" ) )
1495- return c . json ( true )
1494+ const { text } = c . req . valid ( "json" )
1495+
1496+ try {
1497+ await Bus . publish ( TuiEvent . PromptAppend , {
1498+ text,
1499+ parts : ( await SessionPrompt . resolvePromptParts ( text ) ) . filter (
1500+ ( part ) => part . type === "agent" || part . type === "file" ,
1501+ ) ,
1502+ } )
1503+ return c . json ( true )
1504+ } catch ( error ) {
1505+ log . error ( "Failed to process prompt append" , {
1506+ text,
1507+ error : error instanceof Error ? error . message : String ( error ) ,
1508+ } )
1509+ return c . json ( false )
1510+ }
14961511 } ,
14971512 )
14981513 . post (
Original file line number Diff line number Diff line change @@ -535,6 +535,24 @@ export type EventTuiPromptAppend = {
535535 type : "tui.prompt.append"
536536 properties : {
537537 text : string
538+ parts : Array <
539+ | {
540+ type : "agent"
541+ name : string
542+ source ?: {
543+ value : string
544+ start : number
545+ end : number
546+ }
547+ }
548+ | {
549+ type : "file"
550+ mime : string
551+ filename ?: string
552+ url : string
553+ source ?: FilePartSource
554+ }
555+ >
538556 }
539557}
540558
You can’t perform that action at this time.
0 commit comments