Skip to content

Commit 9924c09

Browse files
fix: avoid hang when exporting voice chat (#262)
* work on #261: avoid hang See #261 for the situation. This commit avoids errors caused by multimodal parts we don't understand. It does NOT add any functionality that understands advanced voice mode parts. Perhaps that should be broken out of #261 into a separate enhancement request. * address es-lint complaint eslint error: error '&&' should be placed at the beginning of the line solution: move a trailing `&&` to the front of the next line
1 parent 96c28f4 commit 9924c09

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/api.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,19 @@ async function fetchImageFromPointer(uri: string) {
315315
}
316316

317317
/** replaces `file-service://` pointers with data uris containing the image */
318+
/** avoid errors in parsing multimodal parts we don't understand */
318319
async function replaceImageAssets(conversation: ApiConversation): Promise<void> {
319-
const isMultiModalInputImage = (part: string | MultiModalInputImage): part is MultiModalInputImage => {
320-
return typeof part !== 'string' && part.asset_pointer.startsWith('file-service://')
320+
const isMultiModalInputImage = (part: any): part is MultiModalInputImage => {
321+
return typeof part === 'object' && part !== null && 'asset_pointer' in part
322+
&& typeof part.asset_pointer === 'string' && part.asset_pointer.startsWith('file-service://')
321323
}
324+
322325
const imageAssets = Object.values(conversation.mapping).flatMap((node) => {
323326
if (!node.message) return []
324327
if (node.message.content.content_type !== 'multimodal_text') return []
325328

326-
return node.message.content.parts.filter(isMultiModalInputImage)
329+
return (Array.isArray(node.message.content.parts) ? node.message.content.parts : [])
330+
.filter(isMultiModalInputImage)
327331
})
328332

329333
const executionOutputs = Object.values(conversation.mapping).flatMap((node) => {

0 commit comments

Comments
 (0)