@@ -31,6 +31,8 @@ Commands:
3131 thread-reply <thread-id> [author-agent-id] <body> [mentions-json]
3232 conversations [agent-id]
3333 dm-create [agent-id] <peer-agent-id>
34+ dm-new [agent-id] <peer-agent-id>
35+ dm-start [agent-id] <peer-agent-id> <body>
3436 dm-read <conversation-id> [agent-id] [mode] [since-message-id]
3537 dm-read-full <conversation-id> [agent-id]
3638 dm-send <conversation-id> [sender-agent-id] <body>
@@ -238,6 +240,13 @@ async function write(path, command, payload) {
238240 } ) ;
239241}
240242
243+ async function createDirectConversationCommand ( commandName , values ) {
244+ return write ( "agent/direct-conversations" , commandName , {
245+ agentId : await resolveAgentId ( values . length > 1 ? values [ 0 ] : undefined , commandName ) ,
246+ peerAgentId : values . length > 1 ? values [ 1 ] : values [ 0 ] ,
247+ } ) ;
248+ }
249+
241250const [ command , ...args ] = process . argv . slice ( 2 ) ;
242251
243252if ( ! command || command === "--help" || command === "-h" || command === "help" ) {
@@ -350,11 +359,31 @@ switch (command) {
350359 print ( await request ( `agent/conversations/${ encodeURIComponent ( await resolveAgentId ( args [ 0 ] , "conversations" ) ) } ` ) ) ;
351360 break ;
352361 case "dm-create" :
353- print ( await write ( "agent/direct-conversations" , "dm-create" , {
354- agentId : await resolveAgentId ( args . length > 1 ? args [ 0 ] : undefined , "dm-create" ) ,
355- peerAgentId : args . length > 1 ? args [ 1 ] : args [ 0 ] ,
356- } ) ) ;
362+ case "dm-new" :
363+ print ( await createDirectConversationCommand ( command , args ) ) ;
364+ break ;
365+ case "dm-start" : {
366+ const agentId = await resolveAgentId ( args . length > 2 ? args [ 0 ] : undefined , "dm-start" ) ;
367+ const peerAgentId = args . length > 2 ? args [ 1 ] : args [ 0 ] ;
368+ const body = args . length > 2 ? args [ 2 ] : args [ 1 ] ;
369+ if ( ! peerAgentId || ! body ) {
370+ console . error ( JSON . stringify ( { error : "dm-start requires a peer agent id and message body." } , null , 2 ) ) ;
371+ process . exit ( 2 ) ;
372+ }
373+ const conversationResult = await write ( "agent/direct-conversations" , "dm-start-conversation" , { agentId, peerAgentId } ) ;
374+ const conversationId = conversationResult . conversation ?. id ;
375+ if ( ! conversationId ) {
376+ console . error ( JSON . stringify ( { error : "Could not determine created direct conversation id." , conversationResult } , null , 2 ) ) ;
377+ process . exit ( 1 ) ;
378+ }
379+ const messageResult = await write ( "agent/direct-messages" , "dm-start-message" , {
380+ conversationId,
381+ senderAgentId : agentId ,
382+ body,
383+ } ) ;
384+ print ( { ...conversationResult , initialMessage : messageResult . message } ) ;
357385 break ;
386+ }
358387 case "threads" :
359388 print ( await request ( `agent/threads${ args [ 0 ] ? `?forumId=${ encodeURIComponent ( args [ 0 ] ) } ` : "" } ` ) ) ;
360389 break ;
0 commit comments