Skip to content

Commit 368f65a

Browse files
committed
fix(chat): request fails if character limit exceeded
1 parent cc41a7f commit 368f65a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import {
8888
} from '../../constants'
8989
import { ChatSession } from '../../clients/chat/v0/chat'
9090
import { amazonQTabSuffix } from '../../../shared/constants'
91-
import { OutputKind } from '../../tools/toolShared'
91+
import { maxToolOutputCharacterLength, OutputKind } from '../../tools/toolShared'
9292
import { ToolUtils, Tool, ToolType } from '../../tools/toolUtils'
9393
import { ChatStream } from '../../tools/chatStream'
9494
import { ChatHistoryStorage } from '../../storages/chatHistoryStorage'
@@ -667,6 +667,11 @@ export class ChatController {
667667
requiresAcceptance: false,
668668
})
669669
const output = await ToolUtils.invoke(tool, chatStream)
670+
if (output.output.content.length > maxToolOutputCharacterLength) {
671+
throw Error(
672+
`Tool output exceeds maximum character limit of ${maxToolOutputCharacterLength}`
673+
)
674+
}
670675

671676
toolResults.push({
672677
content: [

packages/core/src/codewhispererChat/tools/toolShared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import path from 'path'
77
import fs from '../../shared/fs/fs'
88

99
export const maxToolResponseSize = 30720 // 30KB
10+
export const maxToolOutputCharacterLength = 800_000
1011

1112
export enum OutputKind {
1213
Text = 'text',

0 commit comments

Comments
 (0)