@@ -48,10 +48,15 @@ import {
4848} from '@/providers/utils'
4949import { useProvidersStore } from '@/stores/providers/store'
5050import { gaugeGetQueryMetadataTool } from '@/tools/gauge/get_query_metadata'
51+ import { gaugeListAnswersTool } from '@/tools/gauge/list_answers'
52+ import { gaugeListCitationsTool } from '@/tools/gauge/list_citations'
5153import { gaugeListPromptsTool } from '@/tools/gauge/list_prompts'
54+ import { gaugeQueryTool } from '@/tools/gauge/query'
5255import type {
5356 GaugeGetQueryMetadataParams ,
57+ GaugeListAnswersParams ,
5458 GaugeListPromptsParams ,
59+ GaugeQueryParams ,
5560 GaugeUpdatePromptParams ,
5661} from '@/tools/gauge/types'
5762import { gaugeUpdatePromptTool } from '@/tools/gauge/update_prompt'
@@ -88,6 +93,84 @@ const mockGetRotatingApiKey = vi.fn().mockReturnValue('rotating-server-key')
8893const originalRequire = module . require
8994
9095describe ( 'integration filters through agent execution' , ( ) => {
96+ it . each ( [
97+ { tool : gaugeListAnswersTool , field : 'topicFilterSelector' } ,
98+ { tool : gaugeListAnswersTool , field : 'manualTopicFilter' } ,
99+ { tool : gaugeListCitationsTool , field : 'topicFilterSelector' } ,
100+ { tool : gaugeListCitationsTool , field : 'manualTopicFilter' } ,
101+ ] ) ( 'ignores stale $field aliases for $tool.id' , async ( { tool, field } ) => {
102+ const providerTool = await transformBlockTool (
103+ {
104+ type : 'gauge' ,
105+ params : {
106+ org : 'example' ,
107+ category : 'example' ,
108+ [ field ] : 'top_stale' ,
109+ topic : '["top_active"]' ,
110+ promptTrackingType : 'branded_own' ,
111+ trackingType : 'all' ,
112+ } ,
113+ } ,
114+ { selectedOperation : tool . id , getAllBlocks : ( ) => [ GaugeBlock ] , getTool : ( ) => tool }
115+ )
116+ if ( ! providerTool ) throw new Error ( 'Gauge agent tool was not created' )
117+ const { executionParams } = prepareToolExecution ( providerTool , { } , { } , undefined )
118+ const params = { ...executionParams , accessToken : 'fixture-token' } as GaugeListAnswersParams
119+ const url = typeof tool . request . url === 'function' ? tool . request . url ( params ) : tool . request . url
120+ expect ( new URL ( url ) . searchParams . getAll ( 'topic' ) ) . toEqual ( [ 'top_active' ] )
121+ expect ( new URL ( url ) . searchParams . get ( 'trackingType' ) ) . toBe ( 'all' )
122+ } )
123+
124+ it . each ( [ 'answers' , 'all' ] ) (
125+ 'ignores a stale %s metadata selection when querying a different dataset' ,
126+ async ( metadataDataset ) => {
127+ const tool = gaugeQueryTool
128+ const providerTool = await transformBlockTool (
129+ {
130+ type : 'gauge' ,
131+ params : {
132+ org : 'example' ,
133+ dataset : 'citations' ,
134+ metrics : '["citations"]' ,
135+ metadataDataset,
136+ } ,
137+ } ,
138+ { selectedOperation : tool . id , getAllBlocks : ( ) => [ GaugeBlock ] , getTool : ( ) => tool }
139+ )
140+ if ( ! providerTool ) throw new Error ( 'Gauge agent tool was not created' )
141+ const { executionParams } = prepareToolExecution ( providerTool , { } , { } , undefined )
142+ const params = { ...executionParams , accessToken : 'fixture-token' } as GaugeQueryParams
143+ expect ( tool . request . body ?.( params ) ) . toMatchObject ( { dataset : 'citations' } )
144+ }
145+ )
146+
147+ it ( 'clears an incompatible Gauge topic array when switching an agent to List Prompts' , async ( ) => {
148+ const tool = gaugeListPromptsTool
149+ vi . spyOn ( blockRegistry , 'getBlock' ) . mockReturnValue ( GaugeBlock )
150+ const params = getParamsForToolOperation (
151+ { type : 'gauge' , params : { org : 'example' , category : 'example' , topic : '["top_stale"]' } } ,
152+ tool
153+ )
154+ const providerTool = await transformBlockTool (
155+ { type : 'gauge' , params } ,
156+ { selectedOperation : tool . id , getAllBlocks : ( ) => [ GaugeBlock ] , getTool : ( ) => tool }
157+ )
158+ if ( ! providerTool ) throw new Error ( 'Gauge agent tool was not created' )
159+ const { executionParams } = prepareToolExecution (
160+ providerTool ,
161+ { topic : 'top_model' } ,
162+ { } ,
163+ undefined
164+ )
165+ const requestParams = {
166+ ...executionParams ,
167+ accessToken : 'fixture-token' ,
168+ } as GaugeListPromptsParams
169+ const url =
170+ typeof tool . request . url === 'function' ? tool . request . url ( requestParams ) : tool . request . url
171+ expect ( new URL ( url ) . searchParams . get ( 'topic' ) ) . toBe ( 'top_model' )
172+ } )
173+
91174 it . each ( [ 'configured' , 'model' ] as const ) (
92175 'retains the %s Gauge topic filter without a stored operation' ,
93176 async ( source ) => {
0 commit comments