Skip to content

Commit 9aea67c

Browse files
committed
fix(GmailTools): implement retry logic for Gmail compose streaming
1 parent ba95871 commit 9aea67c

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

entrypoints/content/components/GmailTools/GmailComposeCard.vue

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,25 @@ const start = async () => {
459459
460460
logger.debug('Gmail compose prompt:', { systemPrompt, userPrompt })
461461
462-
const iter = streamObjectInBackground({
463-
prompt: userPrompt,
464-
system: systemPrompt,
465-
schema: 'emailCompose',
466-
})
467-
468-
for await (const part of iter) {
469-
// Extract the structured result
470-
if (part.type === 'object') {
471-
runningStatus.value = 'streaming'
472-
optimizedSubject.value = part.object.subject || ''
473-
optimizedBody.value = part.object.body || ''
462+
const retry = 0
463+
do {
464+
logger.debug(`Gmail compose attempt #${retry + 1}`)
465+
const iter = streamObjectInBackground({
466+
prompt: userPrompt,
467+
system: systemPrompt,
468+
schema: 'emailCompose',
469+
abortSignal: abortController.signal,
470+
})
471+
472+
for await (const part of iter) {
473+
// Extract the structured result
474+
if (part.type === 'object') {
475+
runningStatus.value = 'streaming'
476+
optimizedSubject.value = part.object.subject || ''
477+
optimizedBody.value = part.object.body || ''
478+
}
474479
}
475-
}
480+
} while ((!optimizedSubject.value || !optimizedBody.value) && retry < 3)
476481
477482
logger.debug('Gmail compose structured response:', {
478483
subject: optimizedSubject.value,

0 commit comments

Comments
 (0)