11import { AlgoliaIcon } from '@/components/icons'
2- import type { BlockConfig , BlockMeta } from '@/blocks/types'
2+ import type { BlockConfig , BlockMeta , BlockToolParamsContext } from '@/blocks/types'
33import { AuthMode , IntegrationType } from '@/blocks/types'
4- import { withSavedCredential } from '@/blocks/utils'
4+ import { isToolCall , mapperOperation , toolCallArg , withSavedCredential } from '@/blocks/utils'
55
66export const AlgoliaBlock : BlockConfig = {
77 type : 'algolia' ,
@@ -593,11 +593,11 @@ Return ONLY the JSON array.`,
593593 ] ,
594594 config : {
595595 tool : ( params : Record < string , unknown > ) => `algolia_${ params . operation } ` ,
596- params : ( params : Record < string , unknown > ) => {
597- const { operation, ... rest } = params
596+ params : ( params : Record < string , unknown > , context ?: BlockToolParamsContext ) => {
597+ const operation = mapperOperation ( params , context )
598598 const result : Record < string , unknown > = { }
599599
600- for ( const [ key , value ] of Object . entries ( rest ) ) {
600+ for ( const [ key , value ] of Object . entries ( params ) ) {
601601 if ( value === undefined || value === null || value === '' ) continue
602602 result [ key ] = value
603603 }
@@ -618,15 +618,18 @@ Return ONLY the JSON array.`,
618618 result . getRankingInfo = toBool ( result . getRankingInfo , false )
619619 }
620620 if ( operation === 'copy_move_index' ) {
621- result . operation = result . copyMoveOperation
621+ // A tool call carries the tool's own copy-or-move `operation` as a model arg.
622+ if ( ! isToolCall ( context ) || result . copyMoveOperation !== undefined ) {
623+ result . operation = result . copyMoveOperation
624+ }
622625 result . copyMoveOperation = undefined
623626 }
624627 if ( operation === 'delete_by_filter' ) {
625- result . filters = result . deleteFilters
628+ result . filters = result . deleteFilters ?? toolCallArg ( context , result . filters )
626629 result . deleteFilters = undefined
627630 }
628631 if ( operation === 'get_records' ) {
629- result . requests = result . getRecordsRequests
632+ result . requests = result . getRecordsRequests ?? toolCallArg ( context , result . requests )
630633 result . getRecordsRequests = undefined
631634 }
632635
0 commit comments