Repository: microsoft/TypeChat
File: examples/music/src/main.ts (TypeScript)

Code before:
    case "listPlaylists": {
      const playlists = await getPlaylists(clientContext.service);
      if (playlists) {
        for (const playlist of playlists.items) {
          console.log(chalk.magentaBright(`${playlist.name}`));
        }
      }
      break;
    }
    case "getPlaylistTracks": {
      const playlistName = args[0] as string;
      const playlists = await getPlaylists(clientContext.service);
      if (playlists) {
        for (const playlist of playlists.items) {
          if (playlist.name === playlistName) {
            const playlistResponse = await getPlaylistTracks(
              clientContext.service,
              playlist.id
            );
            if (playlistResponse) {
              result = playlistResponse.items.map((item) => item.track!);
            }
            break;
          }
        }
      }
      break;
    }
    case "deletePlaylist": {
      const playlistName = args[0] as string;
      const playlists = await getPlaylists(clientContext.service);
      if (playlists) {
        for (const playlist of playlists.items) {
          if (playlist.name === playlistName) {
            await deletePlaylist(clientContext.service, playlist.id);
            console.log(
              chalk.magentaBright(`playlist ${playlistName} deleted`)
            );
            break;
          }
        }
      }
      break;
    }
    case "createPlaylist": {
      const input = args[0] as SpotifyApi.TrackObjectFull[];
      const name = args[1] as string;
      if (input && input.length > 0) {
        const uris = input.map((track) => (track ? track.uri : ""));
        await createPlaylist(
          clientContext.service,

Review comment (suggestion):
```suggestion
      const playlist = playlists?.items.find(playlist => playlist.name === playlistName);
      const playlistResponse = playlist && await getPlaylistTracks(
        clientContext.service,
        playlist.id
      );
      result = playlistResponse?.items.map(item => item.track);
```

Code after:
          console.log(chalk.magentaBright(`${playlist.name}`));
        }
      }
      break;
    }
    case "getPlaylistTracks": {
      const playlistName = args[0] as string;
      const playlists = await getPlaylists(clientContext.service);
      const playlist = playlists?.items.find(playlist => playlist.name === playlistName);
      const playlistResponse = playlist && await getPlaylistTracks(
        clientContext.service,
        playlist.id
      );
      result = playlistResponse?.items.map(item => item.track);
      break;
    }
    case "deletePlaylist": {
      const playlistName = args[0] as string;
      const playlists = await getPlaylists(clientContext.service);
      if (playlists) {
        for (const playlist of playlists.items) {
          if (playlist.name === playlistName) {
            await deletePlaylist(clientContext.service, playlist.id);
            console.log(
              chalk.magentaBright(`playlist ${playlistName} deleted`)
            );
            break;
          }
        }
      }
      break;
    }
    case "createPlaylist": {
      const input = args[0] as SpotifyApi.TrackObjectFull[];
      const name = args[1] as string;
      if (input && input.length > 0) {
        const uris = input.map((track) => (track ? track.uri : ""));
        await createPlaylist(
          clientContext.service,
          name,
          clientContext.service.retrieveUser().id!,
          uris,
          name
        );
        console.log(`playlist ${name} created with tracks:`);
        printTrackNames(input, clientContext);
      } else {
        console.log(chalk.red("filter did not find any tracks"));
      }
      break;
    }