33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import {
7- ConversationState ,
8- CursorState ,
9- DocumentSymbol ,
10- RelevantTextDocument ,
11- SymbolType ,
12- TextDocument ,
13- } from '@amzn/codewhisperer-streaming'
6+ import { ConversationState , CursorState , DocumentSymbol , SymbolType , TextDocument } from '@amzn/codewhisperer-streaming'
147import { AdditionalContentEntryAddition , ChatTriggerType , RelevantTextDocumentAddition , TriggerPayload } from '../model'
158import { undefinedIfEmpty } from '../../../../shared/utilities/textUtilities'
169import { getLogger } from '../../../../shared/logger/logger'
@@ -36,7 +29,6 @@ export const supportedLanguagesList = [
3629]
3730
3831const filePathSizeLimit = 4_000
39- const customerMessageSizeLimit = 4_000
4032
4133export function triggerPayloadToChatRequest ( triggerPayload : TriggerPayload ) : { conversationState : ConversationState } {
4234 // Flexible truncation logic
@@ -81,7 +73,7 @@ export function triggerPayloadToChatRequest(triggerPayload: TriggerPayload): { c
8173 )
8274
8375 getLogger ( ) . debug (
84- `current request total payload size: ${ userInputTruncationInfo . sizeAfter + userSpecificFilesTruncationInfo . sizeAfter + currentFileTruncationInfo . sizeAfter + userSpecificFilesTruncationInfo . sizeAfter + workspaceTruncationInfo . sizeAfter } `
76+ `current request total payload size: ${ userInputTruncationInfo . sizeAfter + currentFileTruncationInfo . sizeAfter + userSpecificRulesTruncationInfo . sizeAfter + userSpecificFilesTruncationInfo . sizeAfter + workspaceTruncationInfo . sizeAfter } `
8577 )
8678
8779 // Filter out empty innerContext from additionalContents
@@ -92,11 +84,9 @@ export function triggerPayloadToChatRequest(triggerPayload: TriggerPayload): { c
9284 }
9385
9486 // Filter out empty text from relevantTextDocuments
95- if ( triggerPayload . relevantTextDocuments !== undefined ) {
96- triggerPayload . relevantTextDocuments = triggerPayload . relevantTextDocuments . filter (
97- ( doc ) => doc . text !== undefined && doc . text !== ''
98- )
99- }
87+ triggerPayload . relevantTextDocuments = triggerPayload . relevantTextDocuments . filter (
88+ ( doc ) => doc . text !== undefined && doc . text !== ''
89+ )
10090
10191 let document : TextDocument | undefined = undefined
10292 let cursorState : CursorState | undefined = undefined
@@ -154,10 +144,6 @@ export function triggerPayloadToChatRequest(triggerPayload: TriggerPayload): { c
154144 }
155145 }
156146
157- const relevantDocuments : RelevantTextDocument [ ] = triggerPayload . relevantTextDocuments
158- ? triggerPayload . relevantTextDocuments
159- : [ ]
160- const useRelevantDocuments = triggerPayload . useRelevantDocuments
161147 // service will throw validation exception if string is empty
162148 const customizationArn : string | undefined = undefinedIfEmpty ( triggerPayload . customization . arn )
163149 const chatTriggerType = triggerPayload . trigger === ChatTriggerType . InlineChatMessage ? 'INLINE_CHAT' : 'MANUAL'
@@ -166,15 +152,13 @@ export function triggerPayloadToChatRequest(triggerPayload: TriggerPayload): { c
166152 conversationState : {
167153 currentMessage : {
168154 userInputMessage : {
169- content : triggerPayload . message
170- ? triggerPayload . message . substring ( 0 , customerMessageSizeLimit )
171- : '' ,
155+ content : triggerPayload . message ,
172156 userInputMessageContext : {
173157 editorState : {
174158 document,
175159 cursorState,
176- relevantDocuments,
177- useRelevantDocuments,
160+ relevantDocuments : triggerPayload . relevantTextDocuments ,
161+ useRelevantDocuments : triggerPayload . useRelevantDocuments ,
178162 } ,
179163 additionalContext : triggerPayload . additionalContents ,
180164 } ,
@@ -194,7 +178,7 @@ function preserveContexts(
194178) : FlexibleTruncationInfo {
195179 const typeToContextMap = new Map <
196180 ChatContextType ,
197- string | AdditionalContentEntryAddition [ ] | RelevantTextDocumentAddition [ ] | undefined
181+ string | AdditionalContentEntryAddition [ ] | RelevantTextDocumentAddition [ ]
198182 > ( [
199183 [ ChatContextType . UserInput , triggerPayload . message ] ,
200184 [ ChatContextType . CurrentFile , triggerPayload . fileText ] ,
@@ -212,45 +196,45 @@ function preserveContexts(
212196 }
213197
214198 const contexts = typeToContextMap . get ( contextType )
215- if ( ! contexts ) {
216- getLogger ( ) . debug (
217- `Current request context size: type: ${ contextType } , before: ${ truncationInfo . sizeBefore } , after: ${ truncationInfo . sizeAfter } `
218- )
219- return truncationInfo
220- }
221-
222199 switch ( contextType ) {
223200 case ChatContextType . UserInput :
224201 truncationInfo = truncate ( contexts as string , truncationInfo )
225202 triggerPayload . message = truncationInfo . textAfter
203+ triggerPayload . contextLengths . truncatedUserInputContextLength = truncationInfo . sizeAfter
226204 break
227205 case ChatContextType . CurrentFile :
228206 truncationInfo = truncate ( contexts as string , truncationInfo )
229207 triggerPayload . fileText = truncationInfo . textAfter
208+ triggerPayload . contextLengths . truncatedCurrentFileContextLength = truncationInfo . sizeAfter
230209 break
231210 case ChatContextType . UserSpecificPrompts :
232211 truncationInfo = truncateUserSpecificContexts (
233212 contexts as AdditionalContentEntryAddition [ ] ,
234213 truncationInfo ,
235214 'prompt'
236215 )
216+ triggerPayload . contextLengths . truncatedAdditionalContextLengths . promptContextLength =
217+ truncationInfo . sizeAfter
237218 break
238219 case ChatContextType . UserSpecificRules :
239220 truncationInfo = truncateUserSpecificContexts (
240221 contexts as AdditionalContentEntryAddition [ ] ,
241222 truncationInfo ,
242223 'rule'
243224 )
225+ triggerPayload . contextLengths . truncatedAdditionalContextLengths . ruleContextLength = truncationInfo . sizeAfter
244226 break
245227 case ChatContextType . UserSpecificFiles :
246228 truncationInfo = truncateUserSpecificContexts (
247229 contexts as AdditionalContentEntryAddition [ ] ,
248230 truncationInfo ,
249231 'file'
250232 )
233+ triggerPayload . contextLengths . truncatedAdditionalContextLengths . fileContextLength = truncationInfo . sizeAfter
251234 break
252235 case ChatContextType . Workspace :
253236 truncationInfo = truncateWorkspaceContexts ( contexts as RelevantTextDocumentAddition [ ] , truncationInfo )
237+ triggerPayload . contextLengths . truncatedWorkspaceContextLength = truncationInfo . sizeAfter
254238 break
255239 default :
256240 getLogger ( ) . warn ( `Unexpected context type: ${ contextType } ` )
0 commit comments