11import type { PineconeResponse , PineconeSearchVectorParams } from '@/tools/pinecone/types'
22import type { ToolConfig } from '@/tools/types'
33
4+ function parseBoolean ( value : unknown ) : boolean {
5+ if ( typeof value === 'boolean' ) return value
6+ if ( typeof value === 'number' ) return value !== 0
7+ return typeof value === 'string' && [ 'true' , '1' ] . includes ( value . trim ( ) . toLowerCase ( ) )
8+ }
9+
10+ function selectedOptions ( value : string [ ] | string | undefined ) : Set < string > {
11+ if ( Array . isArray ( value ) ) return new Set ( value )
12+ if ( typeof value !== 'string' || value . trim ( ) . length === 0 ) return new Set ( )
13+
14+ try {
15+ const parsed : unknown = JSON . parse ( value )
16+ return Array . isArray ( parsed )
17+ ? new Set ( parsed . filter ( ( item ) : item is string => typeof item === 'string' ) )
18+ : new Set ( )
19+ } catch {
20+ return new Set ( )
21+ }
22+ }
23+
424export const searchVectorTool : ToolConfig < PineconeSearchVectorParams , PineconeResponse > = {
525 id : 'pinecone_search_vector' ,
626 name : 'Pinecone Search Vector' ,
@@ -51,6 +71,12 @@ export const searchVectorTool: ToolConfig<PineconeSearchVectorParams, PineconeRe
5171 visibility : 'user-or-llm' ,
5272 description : 'Include metadata in response (true/false)' ,
5373 } ,
74+ options : {
75+ type : 'array' ,
76+ required : false ,
77+ visibility : 'user-only' ,
78+ description : 'Selected search result options' ,
79+ } ,
5480 apiKey : {
5581 type : 'string' ,
5682 required : true ,
@@ -76,8 +102,12 @@ export const searchVectorTool: ToolConfig<PineconeSearchVectorParams, PineconeRe
76102 ? JSON . parse ( params . filter )
77103 : params . filter
78104 : undefined ,
79- includeValues : Boolean ( params . includeValues ) ,
80- includeMetadata : Boolean ( params . includeMetadata )
105+ includeValues : params . options
106+ ? selectedOptions ( params . options ) . has ( 'includeValues' )
107+ : parseBoolean ( params . includeValues ) ,
108+ includeMetadata : params . options
109+ ? selectedOptions ( params . options ) . has ( 'includeMetadata' )
110+ : parseBoolean ( params . includeMetadata ) ,
81111 } ) ,
82112 } ,
83113
0 commit comments