File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -187,11 +187,16 @@ export const ChatInputBar = ({
187187
188188 if ( Array . isArray ( answer ) ) {
189189 // Multi-select: map array of indices to array of option labels
190- // Empty array means skipped
191- return {
192- questionIndex : idx ,
193- selectedOptions :
194- answer . length > 0 ? answer . map ( getOptionLabel ) : undefined ,
190+ // Empty array means skipped - omit selectedOptions entirely to avoid undefined in JSON
191+ if ( answer . length > 0 ) {
192+ return {
193+ questionIndex : idx ,
194+ selectedOptions : answer . map ( getOptionLabel ) ,
195+ }
196+ } else {
197+ return {
198+ questionIndex : idx ,
199+ }
195200 }
196201 } else if (
197202 typeof answer === 'number' &&
Original file line number Diff line number Diff line change @@ -11,6 +11,29 @@ import { getRgPath } from '../native/ripgrep'
1111
1212let clientInstance : CodebuffClient | null = null
1313
14+ /**
15+ * Recursively removes undefined values from an object to ensure clean JSON serialization.
16+ * This prevents issues with APIs that don't accept explicit undefined values.
17+ */
18+ function removeUndefinedValues < T > ( obj : T ) : T {
19+ if ( obj === null || obj === undefined ) {
20+ return obj
21+ }
22+ if ( Array . isArray ( obj ) ) {
23+ return obj . map ( removeUndefinedValues ) as T
24+ }
25+ if ( typeof obj === 'object' ) {
26+ const result : Record < string , unknown > = { }
27+ for ( const [ key , value ] of Object . entries ( obj ) ) {
28+ if ( value !== undefined ) {
29+ result [ key ] = removeUndefinedValues ( value )
30+ }
31+ }
32+ return result as T
33+ }
34+ return obj
35+ }
36+
1437/**
1538 * Reset the cached CodebuffClient instance.
1639 * This should be called after login to ensure the client is re-initialized with new credentials.
@@ -61,7 +84,7 @@ export async function getCodebuffClient(): Promise<CodebuffClient | null> {
6184 return [
6285 {
6386 type : 'json' ,
64- value : response ,
87+ value : removeUndefinedValues ( response ) ,
6588 } ,
6689 ]
6790 } ,
You can’t perform that action at this time.
0 commit comments