@@ -11,7 +11,7 @@ import {
1111
1212import { useLocation , useNavigate } from "@solidjs/router" ;
1313
14- import type { Agent , Provider } from "@opencode-ai/sdk/v2/client" ;
14+ import type { Agent , Provider , Part } from "@opencode-ai/sdk/v2/client" ;
1515
1616import { getVersion } from "@tauri-apps/api/app" ;
1717import { parse } from "jsonc-parser" ;
@@ -64,6 +64,9 @@ import type {
6464 WorkspaceDisplay ,
6565 McpServerEntry ,
6666 McpStatusMap ,
67+ ComposerAttachment ,
68+ ComposerDraft ,
69+ ComposerPart ,
6770 WorkspaceCommand ,
6871 UpdateHandle ,
6972} from "./types" ;
@@ -305,9 +308,55 @@ export default function App() {
305308 const [ keybindOverrides , setKeybindOverrides ] = createSignal < Record < string , string > > ( { } ) ;
306309 const [ recentCommandIds , setRecentCommandIds ] = createSignal < string [ ] > ( [ ] ) ;
307310
308- async function sendPrompt ( ) {
309- const content = prompt ( ) . trim ( ) ;
310- if ( ! content ) return ;
311+ const buildPromptParts = ( draft : ComposerDraft ) : Part [ ] => {
312+ const parts : Part [ ] = [ ] ;
313+ const pushText = ( text : string ) => {
314+ if ( ! text ) return ;
315+ parts . push ( { type : "text" , text } as Part ) ;
316+ } ;
317+
318+ for ( const part of draft . parts ) {
319+ if ( part . type === "text" ) {
320+ pushText ( part . text ) ;
321+ continue ;
322+ }
323+ if ( part . type === "agent" ) {
324+ parts . push ( { type : "agent" , name : part . name } as Part ) ;
325+ continue ;
326+ }
327+ parts . push ( { type : "file" , path : part . path } as Part ) ;
328+ }
329+
330+ for ( const attachment of draft . attachments ) {
331+ if ( attachment . kind === "image" ) {
332+ parts . push ( { type : "image" , image : attachment . dataUrl , mediaType : attachment . mimeType } as Part ) ;
333+ continue ;
334+ }
335+ parts . push ( {
336+ type : "file" ,
337+ data : attachment . dataUrl ,
338+ filename : attachment . name ,
339+ mediaType : attachment . mimeType ,
340+ } as Part ) ;
341+ }
342+
343+ if ( ! parts . length && draft . text . trim ( ) ) {
344+ pushText ( draft . text . trim ( ) ) ;
345+ }
346+
347+ return parts ;
348+ } ;
349+
350+ async function sendPrompt ( draft ?: ComposerDraft ) {
351+ const fallbackText = prompt ( ) . trim ( ) ;
352+ const resolvedDraft : ComposerDraft = draft ?? {
353+ mode : "prompt" ,
354+ parts : fallbackText ? [ { type : "text" , text : fallbackText } as ComposerPart ] : [ ] ,
355+ attachments : [ ] as ComposerAttachment [ ] ,
356+ text : fallbackText ,
357+ } ;
358+ const content = resolvedDraft . text . trim ( ) ;
359+ if ( ! content && ! resolvedDraft . attachments . length ) return ;
311360
312361 if ( isDemoMode ( ) ) {
313362 setLastPromptSent ( content ) ;
@@ -330,30 +379,48 @@ export default function App() {
330379
331380 const model = selectedSessionModel ( ) ;
332381 const agent = selectedSessionAgent ( ) ;
382+ const parts = buildPromptParts ( resolvedDraft ) ;
383+
384+ if ( resolvedDraft . mode === "shell" ) {
385+ const sessionApi = c . session as any ;
386+ if ( sessionApi . shellAsync ) {
387+ await sessionApi . shellAsync ( { sessionID, command : content } ) ;
388+ } else if ( sessionApi . shell ) {
389+ await sessionApi . shell ( { sessionID, command : content } ) ;
390+ } else {
391+ await c . session . promptAsync ( {
392+ sessionID,
393+ model,
394+ agent : agent ?? undefined ,
395+ variant : modelVariant ( ) ?? undefined ,
396+ parts : [ { type : "text" , text : `!${ content } ` } ] ,
397+ } ) ;
398+ }
399+ } else {
400+ await c . session . promptAsync ( {
401+ sessionID,
402+ model,
403+ agent : agent ?? undefined ,
404+ variant : modelVariant ( ) ?? undefined ,
405+ parts,
406+ } ) ;
333407
334- await c . session . promptAsync ( {
335- sessionID,
336- model,
337- agent : agent ?? undefined ,
338- variant : modelVariant ( ) ?? undefined ,
339- parts : [ { type : "text" , text : content } ] ,
340- } ) ;
341-
342- setSessionModelById ( ( current ) => ( {
343- ...current ,
344- [ sessionID ] : model ,
345- } ) ) ;
408+ setSessionModelById ( ( current ) => ( {
409+ ...current ,
410+ [ sessionID ] : model ,
411+ } ) ) ;
346412
347- setSessionModelOverrideById ( ( current ) => {
348- if ( ! current [ sessionID ] ) return current ;
349- const copy = { ...current } ;
350- delete copy [ sessionID ] ;
351- return copy ;
352- } ) ;
413+ setSessionModelOverrideById ( ( current ) => {
414+ if ( ! current [ sessionID ] ) return current ;
415+ const copy = { ...current } ;
416+ delete copy [ sessionID ] ;
417+ return copy ;
418+ } ) ;
353419
354- await loadSessions ( workspaceStore . activeWorkspaceRoot ( ) . trim ( ) ) . catch (
355- ( ) => undefined
356- ) ;
420+ await loadSessions ( workspaceStore . activeWorkspaceRoot ( ) . trim ( ) ) . catch (
421+ ( ) => undefined
422+ ) ;
423+ }
357424 } catch ( e ) {
358425 const message = e instanceof Error ? e . message : safeStringify ( e ) ;
359426 setError ( addOpencodeCacheHint ( message ) ) ;
@@ -2633,7 +2700,6 @@ export default function App() {
26332700 busy : busy ( ) ,
26342701 prompt : prompt ( ) ,
26352702 setPrompt : setPrompt ,
2636- sendPrompt : sendPrompt ,
26372703 activePermission : activePermissionMemo ( ) ,
26382704 permissionReplyBusy : permissionReplyBusy ( ) ,
26392705 respondPermission : respondPermission ,
0 commit comments