@@ -185,23 +185,37 @@ export async function generateChangelog(previous: string, current: string): Prom
185185
186186 const commits = commitsWithMeta . join ( "\n" )
187187
188+ if ( ! commits . trim ( ) ) {
189+ console . error ( "No commits found to generate changelog" )
190+ }
191+
188192 // Generate changelog via LLM
189193 // different port to not conflict with dev running opencode
190- const opencode = await createOpencode ( { port : 8192 } )
191194 let raw : string | undefined
192195 try {
193- const session = await opencode . client . session . create ( )
194- raw = await opencode . client . session
195- . prompt ( {
196- path : { id : session . data ! . id } ,
196+ const opencode = await createOpencode ( { port : 8192 } )
197+ try {
198+ const session = await opencode . client . session . create ( )
199+ if ( ! session . data ?. id ) {
200+ console . error ( "Failed to create session:" , session )
201+ throw new Error ( "Failed to create session" )
202+ }
203+ const response = await opencode . client . session . prompt ( {
204+ path : { id : session . data . id } ,
197205 body : {
198206 model : { providerID : "opencode" , modelID : MODEL } ,
199207 parts : [ { type : "text" , text : buildPrompt ( previous , commits ) } ] ,
200208 } ,
201209 } )
202- . then ( ( x ) => x . data ?. parts ?. find ( ( y ) => y . type === "text" ) ?. text )
203- } finally {
204- opencode . server . close ( )
210+ if ( ! response . data ?. parts ) {
211+ console . error ( "Empty response from LLM:" , response )
212+ }
213+ raw = response . data ?. parts ?. find ( ( y ) => y . type === "text" ) ?. text
214+ } finally {
215+ opencode . server . close ( )
216+ }
217+ } catch ( err ) {
218+ console . error ( "Failed to generate changelog via LLM:" , err )
205219 }
206220
207221 const notes = parseChangelog ( raw ?? "" )
0 commit comments