@@ -185,23 +185,35 @@ export async function generateChangelog(previous: string, current: string): Prom
185185
186186 const commits = commitsWithMeta . join ( "\n" )
187187
188+ }
189+
188190 // Generate changelog via LLM
189191 // different port to not conflict with dev running opencode
190- const opencode = await createOpencode ( { port : 8192 } )
191192 let raw : string | undefined
192193 try {
193- const session = await opencode . client . session . create ( )
194- raw = await opencode . client . session
195- . prompt ( {
196- path : { id : session . data ! . id } ,
194+ const opencode = await createOpencode ( { port : 8192 } )
195+ try {
196+ const session = await opencode . client . session . create ( )
197+ if ( ! session . data ?. id ) {
198+ console . error ( "Failed to create session:" , session )
199+ throw new Error ( "Failed to create session" )
200+ }
201+ const response = await opencode . client . session . prompt ( {
202+ path : { id : session . data . id } ,
197203 body : {
198204 model : { providerID : "opencode" , modelID : MODEL } ,
199205 parts : [ { type : "text" , text : buildPrompt ( previous , commits ) } ] ,
200206 } ,
201207 } )
202- . then ( ( x ) => x . data ?. parts ?. find ( ( y ) => y . type === "text" ) ?. text )
203- } finally {
204- opencode . server . close ( )
208+ if ( ! response . data ?. parts ) {
209+ console . error ( "Empty response from LLM:" , response )
210+ }
211+ raw = response . data ?. parts ?. find ( ( y ) => y . type === "text" ) ?. text
212+ } finally {
213+ opencode . server . close ( )
214+ }
215+ } catch ( err ) {
216+ console . error ( "Failed to generate changelog via LLM:" , err )
205217 }
206218
207219 const notes = parseChangelog ( raw ?? "" )
0 commit comments