From 39233287bb678058b7139ea6132ef01516bdf4f6 Mon Sep 17 00:00:00 2001 From: kowshikdev Date: Thu, 3 Dec 2026 19:40:22 +0530 Subject: [PATCH] fix(spotify): send the transfer device and shuffle state the block collects Transfer Playback stored the device in target_device_id and Set Shuffle stored the switch in shuffle_state, but the tools read device_id and state, so both operations failed with a missing required parameter. Co-Authored-By: Claude Opus 5.5 --- apps/sim/blocks/blocks/spotify.test.ts | 37 ++++++++++++++++++++++++++ apps/sim/blocks/blocks/spotify.ts | 11 ++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 apps/sim/blocks/blocks/spotify.test.ts diff --git a/apps/sim/blocks/blocks/spotify.test.ts b/apps/sim/blocks/blocks/spotify.test.ts new file mode 100644 index 00000000000..2b2ec468c0a --- /dev/null +++ b/apps/sim/blocks/blocks/spotify.test.ts @@ -0,0 +1,37 @@ +/** + * @vitest-environment node + */ +import { describe, expect, it } from 'vitest' +import { SpotifyBlock } from '@/blocks/blocks/spotify' +import type { BlockToolParamsContext } from '@/blocks/types' + +/** Merges the mapper's result over the inputs the way the generic handler and tool calls do. */ +function toolParams(inputs: Record, context?: BlockToolParamsContext) { + return { ...inputs, ...SpotifyBlock.tools.config?.params?.(inputs, context) } +} + +describe('Spotify player params', () => { + it('transfers playback to the Target Device ID', () => { + expect( + toolParams({ operation: 'spotify_transfer_playback', target_device_id: 'kitchen' }) + ).toMatchObject({ device_id: 'kitchen' }) + }) + + it.each([true, false])('sets shuffle to the switch value %s', (shuffle) => { + expect( + toolParams({ operation: 'spotify_set_shuffle', shuffle_state: shuffle, device_id: 'kitchen' }) + ).toMatchObject({ state: shuffle, device_id: 'kitchen' }) + }) + + it("keeps the model's own args on a tool call that leaves the block fields blank", () => { + expect( + toolParams( + { target_device_id: '', device_id: 'kitchen' }, + { operation: 'spotify_transfer_playback' } + ) + ).toMatchObject({ device_id: 'kitchen' }) + expect(toolParams({ state: false }, { operation: 'spotify_set_shuffle' })).toMatchObject({ + state: false, + }) + }) +}) diff --git a/apps/sim/blocks/blocks/spotify.ts b/apps/sim/blocks/blocks/spotify.ts index 05d51ecfbe4..0ce2b543f6f 100644 --- a/apps/sim/blocks/blocks/spotify.ts +++ b/apps/sim/blocks/blocks/spotify.ts @@ -1,7 +1,7 @@ import { SpotifyIcon } from '@/components/icons' import type { BlockConfig, BlockMeta } from '@/blocks/types' import { AuthMode, IntegrationType } from '@/blocks/types' -import { normalizeFileInput } from '@/blocks/utils' +import { blockFieldOrToolArg, mapperOperation, normalizeFileInput } from '@/blocks/utils' /** * Canonical basic/advanced pair for the playlist cover art, shared by the card @@ -1009,8 +1009,15 @@ export const SpotifyBlock: BlockConfig = { if (params.playUris) params.uris = params.playUris return params.operation || 'spotify_search' }, - params: (params) => { + params: (params, context) => { const result: Record = {} + const operation = mapperOperation(params, context) + if (operation === 'spotify_transfer_playback') { + result.device_id = blockFieldOrToolArg(context, params.target_device_id, params.device_id) + } + if (operation === 'spotify_set_shuffle') { + result.state = blockFieldOrToolArg(context, params.shuffle_state, params.state) + } if (params.limit) result.limit = Number(params.limit) if (params.volume_percent) result.volume_percent = Number(params.volume_percent) if (params.range_start) result.range_start = Number(params.range_start)